mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgr standby switchover: add "%p" event notification parameter
This will contain the node ID of the former primary.
This commit is contained in:
5
HISTORY
5
HISTORY
@@ -2,7 +2,10 @@
|
||||
repmgr: enable documentation to be build as single HTML file; GitHub #353 (fanf2)
|
||||
repmgr: add missing -W option to getopt_long() invocation; GitHub #350 (Ian)
|
||||
repmgr: recognize "--terse" option for "repmgr cluster event"; GitHub #360 (Ian)
|
||||
docs: various fixes (Ian, Daymel, Martín, ams)
|
||||
repmgr: add "--wait-start" option for "repmgr standby register"; GitHub #356 (Ian)
|
||||
repmgr: add "%p" event notification parameter for "repmgr standby switchover"
|
||||
containing the node ID of the demoted primary (Ian)
|
||||
docs: various fixes and updates (Ian, Daymel, Martín, ams)
|
||||
|
||||
4.0.1 2017-12-13
|
||||
repmgr: ensure "repmgr node check --action=" returns appropriate return
|
||||
|
||||
17
dbutils.c
17
dbutils.c
@@ -2962,7 +2962,6 @@ create_event_record(PGconn *conn, t_configuration_options *options, int node_id,
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* create_event_notification()
|
||||
*
|
||||
@@ -3063,7 +3062,7 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
|
||||
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
/* we don't treat this as an error */
|
||||
/* we don't treat this as a fatal error */
|
||||
log_warning(_("unable to create event record:\n %s"),
|
||||
PQerrorMessage(conn));
|
||||
|
||||
@@ -3216,6 +3215,20 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char
|
||||
dst_ptr += strlen(dst_ptr);
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
/* %p: former primary id ("repmgr standby switchover") */
|
||||
src_ptr++;
|
||||
if (event_info->former_primary_id != UNKNOWN_NODE_ID)
|
||||
{
|
||||
PQExpBufferData node_id;
|
||||
initPQExpBuffer(&node_id);
|
||||
appendPQExpBuffer(&node_id,
|
||||
"%i", event_info->former_primary_id);
|
||||
strlcpy(dst_ptr, node_id.data, end_ptr - dst_ptr);
|
||||
dst_ptr += strlen(dst_ptr);
|
||||
termPQExpBuffer(&node_id);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* otherwise treat the % as not special */
|
||||
if (dst_ptr < end_ptr)
|
||||
|
||||
@@ -174,11 +174,13 @@ typedef struct s_event_info
|
||||
{
|
||||
char *node_name;
|
||||
char *conninfo_str;
|
||||
int former_primary_id;
|
||||
} t_event_info;
|
||||
|
||||
#define T_EVENT_INFO_INITIALIZER { \
|
||||
NULL, \
|
||||
NULL \
|
||||
NULL, \
|
||||
UNKNOWN_NODE_ID \
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<term><option>%s</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
success (1 or 0)
|
||||
success (1) or failure (0)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@@ -84,6 +84,17 @@
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
|
||||
<varlistentry>
|
||||
<term><option>%p</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
node ID of the demoted standby (<xref linkend="repmgr-standby-switchover"> only)
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
<para>
|
||||
The values provided for <literal>%t</literal> and <literal>%d</literal>
|
||||
|
||||
@@ -109,9 +109,14 @@
|
||||
<title>Event notifications</title>
|
||||
<para>
|
||||
<literal>standby_switchover</literal> and <literal>standby_promote</literal>
|
||||
<link linkend="event-notifications">event notification</link> will be generated for the new primary,
|
||||
<link linkend="event-notifications">event notifications</link> will be generated for the new primary,
|
||||
and a <literal>node_rejoin</literal> event notification for the former primary (new standby).
|
||||
</para>
|
||||
<para>
|
||||
If using an event notification script, <literal>standby_switchover</literal>
|
||||
will populate the placeholder parameter <literal>%p</literal> with the node ID of
|
||||
the former standby.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
|
||||
|
||||
@@ -2016,6 +2016,8 @@ do_standby_switchover(void)
|
||||
NodeInfoList sibling_nodes = T_NODE_INFO_LIST_INITIALIZER;
|
||||
int unreachable_sibling_node_count = 0;
|
||||
|
||||
t_event_info event_info = T_EVENT_INFO_INITIALIZER;
|
||||
|
||||
/*
|
||||
* SANITY CHECKS
|
||||
*
|
||||
@@ -2114,6 +2116,8 @@ do_standby_switchover(void)
|
||||
|
||||
log_verbose(LOG_DEBUG, "remote node name is \"%s\"", remote_node_record.node_name);
|
||||
|
||||
/* this will fill the %p event notification parameter */
|
||||
event_info.former_primary_id = remote_node_record.node_id;
|
||||
|
||||
/*
|
||||
* If --force-rewind specified, check pg_rewind can be used, and
|
||||
@@ -2790,8 +2794,7 @@ do_standby_switchover(void)
|
||||
log_debug("executing:\n %s", remote_command_str.data);
|
||||
initPQExpBuffer(&command_output);
|
||||
|
||||
command_success = remote_command(
|
||||
remote_host,
|
||||
command_success = remote_command(remote_host,
|
||||
runtime_options.remote_user,
|
||||
remote_command_str.data,
|
||||
&command_output);
|
||||
@@ -2807,12 +2810,13 @@ do_standby_switchover(void)
|
||||
if (strlen(command_output.data) > 2)
|
||||
log_detail("%s", command_output.data);
|
||||
|
||||
create_event_record(local_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
"standby_switchover",
|
||||
false,
|
||||
command_output.data);
|
||||
create_event_notification_extended(local_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
"standby_switchover",
|
||||
false,
|
||||
command_output.data,
|
||||
&event_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2825,12 +2829,13 @@ do_standby_switchover(void)
|
||||
config_file_options.node_id,
|
||||
remote_node_record.node_id);
|
||||
|
||||
create_event_record(local_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
"standby_switchover",
|
||||
true,
|
||||
event_details.data);
|
||||
create_event_notification_extended(local_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
"standby_switchover",
|
||||
true,
|
||||
event_details.data,
|
||||
&event_info);
|
||||
termPQExpBuffer(&event_details);
|
||||
}
|
||||
|
||||
@@ -3730,8 +3735,7 @@ initialise_direct_clone(t_node_info *node_record)
|
||||
{
|
||||
log_error("%s", event_details.data);
|
||||
|
||||
create_event_notification(
|
||||
primary_conn,
|
||||
create_event_notification(primary_conn,
|
||||
&config_file_options,
|
||||
config_file_options.node_id,
|
||||
"standby_clone",
|
||||
|
||||
Reference in New Issue
Block a user