From 73982859f6e4aae482e70534c1421c2956a71102 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 28 Feb 2018 12:33:47 +0900 Subject: [PATCH] repmgrd: improve log output - emit explicit startup NOTICE - emit NOTICE when falling back to degraded monitoring on a primary node - improve log message and event notification details when monitoring a former primary which has been reconnected as a standby --- repmgrd-physical.c | 31 ++++++++++++++++++++----------- repmgrd.c | 2 ++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/repmgrd-physical.c b/repmgrd-physical.c index d76f5a81..9a7392a8 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -318,6 +318,7 @@ monitor_streaming_primary(void) monitoring_state = MS_DEGRADED; INSTR_TIME_SET_CURRENT(degraded_monitoring_start); + log_notice(_("unable to connect to local node, falling back to degraded monitoring")); } } @@ -364,20 +365,19 @@ monitor_streaming_primary(void) { local_node_info.node_status = NODE_STATUS_UP; - initPQExpBuffer(&event_details); - /* check to see if the node has been restored as a standby */ if (get_recovery_type(local_conn) == RECTYPE_STANDBY) { PGconn *new_primary_conn; + initPQExpBuffer(&event_details); + appendPQExpBuffer(&event_details, _("reconnected to node after %i seconds, node is now a standby, switching to standby monitoring"), degraded_monitoring_elapsed); log_notice("%s", event_details.data); termPQExpBuffer(&event_details); - primary_node_id = UNKNOWN_NODE_ID; new_primary_conn = get_primary_connection_quiet(local_conn, &primary_node_id, NULL); @@ -430,10 +430,15 @@ monitor_streaming_primary(void) if (resume_monitoring == true) { monitoring_state = MS_NORMAL; + log_notice(_("former primary has been restored as standby after %i seconds, updating node record and resuming monitoring"), + degraded_monitoring_elapsed); + + initPQExpBuffer(&event_details); appendPQExpBuffer(&event_details, - _("former primary has been restored as standby after %i seconds, updating node record and resuming monitoring"), - degraded_monitoring_elapsed); + _("node restored as standby after %i seconds, monitoring connection to upstream node %i"), + degraded_monitoring_elapsed, + local_node_info.upstream_node_id); create_event_notification(new_primary_conn, &config_file_options, @@ -441,7 +446,8 @@ monitor_streaming_primary(void) "repmgrd_standby_reconnect", true, event_details.data); - log_notice("%s", event_details.data); + + termPQExpBuffer(&event_details); close_connection(&new_primary_conn); @@ -480,6 +486,7 @@ monitor_streaming_primary(void) { monitoring_state = MS_NORMAL; + initPQExpBuffer(&event_details); appendPQExpBuffer(&event_details, _("reconnected to primary node after %i seconds, resuming monitoring"), degraded_monitoring_elapsed); @@ -520,7 +527,7 @@ loop: if (monitoring_state == MS_DEGRADED) { - log_detail(_("waiting for primary to reappear")); + log_detail(_("waiting for the node to become available")); } INSTR_TIME_SET_CURRENT(log_status_interval_start); @@ -2503,18 +2510,20 @@ do_election(void) if (config_file_options.failover == FAILOVER_MANUAL) { - log_notice(_("this node is not configured for automatic failover so will not be considered as promotion candidate")); + log_notice(_("this node is not configured for automatic failover so will not be considered as promotion candidate, and will not follow the new primary")); + log_detail(_("\"failover\" is set to \"manual\" in repmgr.conf")); + log_hint(_("manually execute \"repmgr standby follow\" to have this node follow the new primary")); - return ELECTION_LOST; + return ELECTION_NOT_CANDIDATE; } - /* node priority is set to zero - don't ever become a candidate */ + /* node priority is set to zero - don't become a candidate, and lose by default */ if (local_node_info.priority <= 0) { log_notice(_("this node's priority is %i so will not be considered as an automatic promotion candidate"), local_node_info.priority); - return ELECTION_NOT_CANDIDATE; + return ELECTION_LOST; } /* get all active nodes attached to upstream, excluding self */ diff --git a/repmgrd.c b/repmgrd.c index 706d988e..81f18489 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -254,6 +254,8 @@ main(int argc, char **argv) strncpy(config_file_options.log_level, cli_log_level, MAXLEN); } + log_notice(_("repmgrd (repmgr %s) starting up"), REPMGR_VERSION); + /* * -m/--monitoring-history, if provided, will override repmgr.conf's * monitoring_history; this is for backwards compatibility as it's