diff --git a/repmgr--4.0.sql b/repmgr--4.0.sql index 83f907b1..26e4abff 100644 --- a/repmgr--4.0.sql +++ b/repmgr--4.0.sql @@ -106,6 +106,11 @@ CREATE FUNCTION set_local_node_id(INT) AS 'MODULE_PATHNAME', 'set_local_node_id' LANGUAGE C STRICT; +CREATE FUNCTION get_local_node_id() + RETURNS INT + AS 'MODULE_PATHNAME', 'get_local_node_id' + LANGUAGE C STRICT; + CREATE FUNCTION standby_set_last_updated() RETURNS TIMESTAMP WITH TIME ZONE AS 'MODULE_PATHNAME', 'standby_set_last_updated' diff --git a/repmgr.c b/repmgr.c index 347148d5..29bb183b 100644 --- a/repmgr.c +++ b/repmgr.c @@ -86,39 +86,33 @@ void _PG_fini(void); static void repmgr_shmem_startup(void); Datum set_local_node_id(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(set_local_node_id); -Datum standby_set_last_updated(PG_FUNCTION_ARGS); +Datum get_local_node_id(PG_FUNCTION_ARGS); +PG_FUNCTION_INFO_V1(get_local_node_id); +Datum standby_set_last_updated(PG_FUNCTION_ARGS); PG_FUNCTION_INFO_V1(standby_set_last_updated); Datum standby_get_last_updated(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(standby_get_last_updated); Datum set_voting_status_initiated(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(set_voting_status_initiated); Datum notify_follow_primary(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(notify_follow_primary); Datum get_new_primary(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(get_new_primary); Datum reset_voting_status(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(reset_voting_status); Datum am_bdr_failover_handler(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(am_bdr_failover_handler); Datum unset_bdr_failover_handler(PG_FUNCTION_ARGS); - PG_FUNCTION_INFO_V1(unset_bdr_failover_handler); @@ -236,6 +230,23 @@ set_local_node_id(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } + +Datum +get_local_node_id(PG_FUNCTION_ARGS) +{ + int local_node_id = UNKNOWN_NODE_ID; + + if (!shared_state) + PG_RETURN_NULL(); + + LWLockAcquire(shared_state->lock, LW_SHARED); + local_node_id = shared_state->local_node_id; + LWLockRelease(shared_state->lock); + + PG_RETURN_INT32(local_node_id); +} + + /* update and return last updated with current timestamp */ Datum standby_set_last_updated(PG_FUNCTION_ARGS) diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 2032f24b..718f4c4e 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -1347,6 +1347,9 @@ do_upstream_standby_failover(void) /* reconnect to local node */ local_conn = establish_db_connection(config_file_options.conninfo, false); + /* refresh shared memory settings which will have been zapped by the restart */ + repmgrd_set_local_node_id(local_conn, config_file_options.node_id); + if (update_node_record_set_upstream(primary_conn, local_node_info.node_id, primary_node_info.node_id) == false) @@ -1599,6 +1602,10 @@ wait_primary_notification(int *new_primary_id) *new_primary_id, i); return true; } + + log_verbose(LOG_DEBUG, "waiting for new primary notification, %i of max %i seconds", + i, config_file_options.primary_notification_timeout); + sleep(1); } @@ -1754,9 +1761,9 @@ follow_new_primary(int new_primary_id) return FAILOVER_STATE_FOLLOW_FAIL; } - /* refresh shared memory settings which will have been zapped by the restart */ local_conn = establish_db_connection(local_node_info.conninfo, false); + /* refresh shared memory settings which will have been zapped by the restart */ repmgrd_set_local_node_id(local_conn, config_file_options.node_id); initPQExpBuffer(&event_details);