From f9a1861ded2240d0ca47f3d717462ecee11467cb Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Sat, 2 Feb 2019 18:36:59 +0900 Subject: [PATCH] Refactor ReplInfo struct handling Eventually we'll want to have this contain the optional replication info contained in the t_node_info struct, which should then contain a pointer to a ReplInfo struct. --- dbutils.c | 11 +++++++++++ dbutils.h | 14 +++----------- repmgr-action-node.c | 5 ++++- repmgr-action-standby.c | 3 ++- repmgrd-physical.c | 4 +++- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/dbutils.c b/dbutils.c index 6af1d459..fc3feb6d 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1414,6 +1414,17 @@ get_primary_node_id(PGconn *conn) } +void +init_replication_info(ReplInfo *replication_info) +{ + memset(replication_info->current_timestamp, 0, sizeof(replication_info->current_timestamp)); + replication_info->last_wal_receive_lsn = InvalidXLogRecPtr; + replication_info->last_wal_replay_lsn = InvalidXLogRecPtr; + memset(replication_info->last_xact_replay_timestamp, 0, sizeof(replication_info->last_xact_replay_timestamp)); + replication_info->replication_lag_time = 0; + replication_info->receiving_streamed_wal = true; +} + bool get_replication_info(PGconn *conn, ReplInfo *replication_info) { diff --git a/dbutils.h b/dbutils.h index 57fcd4bf..a0fa3f54 100644 --- a/dbutils.h +++ b/dbutils.h @@ -301,22 +301,13 @@ typedef struct BdrNodeInfoList typedef struct { char current_timestamp[MAXLEN]; - uint64 last_wal_receive_lsn; - uint64 last_wal_replay_lsn; + XLogRecPtr last_wal_receive_lsn; + XLogRecPtr last_wal_replay_lsn; char last_xact_replay_timestamp[MAXLEN]; int replication_lag_time; bool receiving_streamed_wal; } ReplInfo; -#define T_REPLINFO_INTIALIZER { \ - "", \ - InvalidXLogRecPtr, \ - InvalidXLogRecPtr, \ - "", \ - 0 \ -} - - typedef struct { char filepath[MAXPGPATH]; @@ -550,6 +541,7 @@ void reset_voting_status(PGconn *conn); XLogRecPtr get_current_wal_lsn(PGconn *conn); XLogRecPtr get_last_wal_receive_location(PGconn *conn); XLogRecPtr get_current_lsn(PGconn *conn); +void init_replication_info(ReplInfo *replication_info); bool get_replication_info(PGconn *conn, ReplInfo *replication_info); int get_replication_lag_seconds(PGconn *conn); void get_node_replication_stats(PGconn *conn, t_node_info *node_info); diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 0fb38b7c..abc3badc 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -75,7 +75,7 @@ do_node_status(void) ItemList warnings = {NULL, NULL}; RecoveryType recovery_type = RECTYPE_UNKNOWN; - ReplInfo replication_info = T_REPLINFO_INTIALIZER; + ReplInfo replication_info; t_recovery_conf recovery_conf = T_RECOVERY_CONF_INITIALIZER; char data_dir[MAXPGPATH] = ""; @@ -90,6 +90,9 @@ do_node_status(void) return _do_node_status_is_shutdown_cleanly(); } + init_replication_info(&replication_info); + + /* config file required, so we should have "conninfo" and "data_directory" */ conn = establish_db_connection(config_file_options.conninfo, true); strncpy(data_dir, config_file_options.data_directory, MAXPGPATH); diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 48c11a19..4763987c 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -3024,7 +3024,7 @@ do_standby_switchover(void) bool switchover_success = true; XLogRecPtr remote_last_checkpoint_lsn = InvalidXLogRecPtr; - ReplInfo replication_info = T_REPLINFO_INTIALIZER; + ReplInfo replication_info; /* store list of configuration files on the demotion candidate */ KeyValueList remote_config_files = {NULL, NULL}; @@ -4190,6 +4190,7 @@ do_standby_switchover(void) log_verbose(LOG_INFO, _("successfully reconnected to local node")); } + init_replication_info(&replication_info); /* * Compare standby's last WAL receive location with the primary's last * checkpoint LSN. We'll loop for a while as it's possible the standby's diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 5dc0a10a..4dc19b14 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -2204,7 +2204,7 @@ do_primary_failover(void) static void update_monitoring_history(void) { - ReplInfo replication_info = T_REPLINFO_INTIALIZER; + ReplInfo replication_info; XLogRecPtr primary_last_wal_location = InvalidXLogRecPtr; long long unsigned int apply_lag_bytes = 0; @@ -2223,6 +2223,8 @@ update_monitoring_history(void) return; } + init_replication_info(&replication_info); + if (get_replication_info(local_conn, &replication_info) == false) { log_warning(_("unable to retrieve replication status information, unable to update monitoring history"));