From 7862941300b5840d2bcbd290ce7e03729feceb05 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 28 Sep 2021 10:24:13 +0900 Subject: [PATCH] repmgrd: add %p event notification parameter for "repmgrd_failover_promote" This enables an event notification script to identify the former primary node. --- dbutils.c | 2 +- doc/appendix-release-notes.xml | 9 +++++++++ doc/event-notifications.xml | 8 ++++++-- repmgrd-physical.c | 33 +++++++++++++++++++++------------ 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/dbutils.c b/dbutils.c index d8d7f404..22ab1b85 100644 --- a/dbutils.c +++ b/dbutils.c @@ -4242,7 +4242,7 @@ _create_event(PGconn *conn, t_configuration_options *options, int node_id, char } break; case 'p': - /* %p: primary id ("standby_switchover": former primary id) */ + /* %p: primary id ("standby_switchover"/"repmgrd_failover_promote": former primary id) */ src_ptr++; if (event_info->node_id != UNKNOWN_NODE_ID) { diff --git a/doc/appendix-release-notes.xml b/doc/appendix-release-notes.xml index 4ca73654..d75cbc2b 100644 --- a/doc/appendix-release-notes.xml +++ b/doc/appendix-release-notes.xml @@ -77,7 +77,16 @@ status. + + + + Add %p event notification parameter + providing the node ID of the former primary for the repmgrd_failover_promote event. + + + + diff --git a/doc/event-notifications.xml b/doc/event-notifications.xml index ce4a06ed..860f884c 100644 --- a/doc/event-notifications.xml +++ b/doc/event-notifications.xml @@ -95,7 +95,8 @@ - The following parameters are provided for a subset of event notifications: + The following parameters are provided for a subset of event notifications; their meaning may + change according to context: @@ -108,6 +109,9 @@ node ID of the demoted primary ( only) + + node ID of the former primary (repmgrd_failover_promote only) + @@ -133,7 +137,7 @@ The values provided for %c and %a - will probably contain spaces, so should always be quoted. + may contain spaces, so should always be quoted. diff --git a/repmgrd-physical.c b/repmgrd-physical.c index ddf0f0fe..44f24368 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -1842,6 +1842,7 @@ monitor_streaming_standby(void) int former_upstream_node_id = local_node_info.upstream_node_id; NodeInfoList sibling_nodes = T_NODE_INFO_LIST_INITIALIZER; PQExpBufferData event_details; + t_event_info event_info = T_EVENT_INFO_INITIALIZER; update_node_record_set_primary(local_conn, local_node_info.node_id); record_status = get_node_record(local_conn, local_node_info.node_id, &local_node_info); @@ -1854,12 +1855,16 @@ monitor_streaming_standby(void) initPQExpBuffer(&event_details); appendPQExpBufferStr(&event_details, _("promotion command failed but promotion completed successfully")); - create_event_notification(local_conn, - &config_file_options, - local_node_info.node_id, - "repmgrd_failover_promote", - true, - event_details.data); + + event_info.node_id = former_upstream_node_id; + + create_event_notification_extended(local_conn, + &config_file_options, + local_node_info.node_id, + "repmgrd_failover_promote", + true, + event_details.data, + &event_info); termPQExpBuffer(&event_details); @@ -3703,6 +3708,7 @@ promote_self(void) { PQExpBufferData event_details; + t_event_info event_info = T_EVENT_INFO_INITIALIZER; /* update own internal node record */ record_status = get_node_record(local_conn, local_node_info.node_id, &local_node_info); @@ -3719,13 +3725,16 @@ promote_self(void) failed_primary.node_name, failed_primary.node_id); + event_info.node_id = failed_primary.node_id; + /* local_conn is now the primary connection */ - create_event_notification(local_conn, - &config_file_options, - local_node_info.node_id, - "repmgrd_failover_promote", - true, - event_details.data); + create_event_notification_extended(local_conn, + &config_file_options, + local_node_info.node_id, + "repmgrd_failover_promote", + true, + event_details.data, + &event_info); termPQExpBuffer(&event_details); }