mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
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.
This commit is contained in:
11
dbutils.c
11
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
|
bool
|
||||||
get_replication_info(PGconn *conn, ReplInfo *replication_info)
|
get_replication_info(PGconn *conn, ReplInfo *replication_info)
|
||||||
{
|
{
|
||||||
|
|||||||
14
dbutils.h
14
dbutils.h
@@ -301,22 +301,13 @@ typedef struct BdrNodeInfoList
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char current_timestamp[MAXLEN];
|
char current_timestamp[MAXLEN];
|
||||||
uint64 last_wal_receive_lsn;
|
XLogRecPtr last_wal_receive_lsn;
|
||||||
uint64 last_wal_replay_lsn;
|
XLogRecPtr last_wal_replay_lsn;
|
||||||
char last_xact_replay_timestamp[MAXLEN];
|
char last_xact_replay_timestamp[MAXLEN];
|
||||||
int replication_lag_time;
|
int replication_lag_time;
|
||||||
bool receiving_streamed_wal;
|
bool receiving_streamed_wal;
|
||||||
} ReplInfo;
|
} ReplInfo;
|
||||||
|
|
||||||
#define T_REPLINFO_INTIALIZER { \
|
|
||||||
"", \
|
|
||||||
InvalidXLogRecPtr, \
|
|
||||||
InvalidXLogRecPtr, \
|
|
||||||
"", \
|
|
||||||
0 \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char filepath[MAXPGPATH];
|
char filepath[MAXPGPATH];
|
||||||
@@ -550,6 +541,7 @@ void reset_voting_status(PGconn *conn);
|
|||||||
XLogRecPtr get_current_wal_lsn(PGconn *conn);
|
XLogRecPtr get_current_wal_lsn(PGconn *conn);
|
||||||
XLogRecPtr get_last_wal_receive_location(PGconn *conn);
|
XLogRecPtr get_last_wal_receive_location(PGconn *conn);
|
||||||
XLogRecPtr get_current_lsn(PGconn *conn);
|
XLogRecPtr get_current_lsn(PGconn *conn);
|
||||||
|
void init_replication_info(ReplInfo *replication_info);
|
||||||
bool get_replication_info(PGconn *conn, ReplInfo *replication_info);
|
bool get_replication_info(PGconn *conn, ReplInfo *replication_info);
|
||||||
int get_replication_lag_seconds(PGconn *conn);
|
int get_replication_lag_seconds(PGconn *conn);
|
||||||
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ do_node_status(void)
|
|||||||
|
|
||||||
ItemList warnings = {NULL, NULL};
|
ItemList warnings = {NULL, NULL};
|
||||||
RecoveryType recovery_type = RECTYPE_UNKNOWN;
|
RecoveryType recovery_type = RECTYPE_UNKNOWN;
|
||||||
ReplInfo replication_info = T_REPLINFO_INTIALIZER;
|
ReplInfo replication_info;
|
||||||
t_recovery_conf recovery_conf = T_RECOVERY_CONF_INITIALIZER;
|
t_recovery_conf recovery_conf = T_RECOVERY_CONF_INITIALIZER;
|
||||||
|
|
||||||
char data_dir[MAXPGPATH] = "";
|
char data_dir[MAXPGPATH] = "";
|
||||||
@@ -90,6 +90,9 @@ do_node_status(void)
|
|||||||
return _do_node_status_is_shutdown_cleanly();
|
return _do_node_status_is_shutdown_cleanly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_replication_info(&replication_info);
|
||||||
|
|
||||||
|
|
||||||
/* config file required, so we should have "conninfo" and "data_directory" */
|
/* config file required, so we should have "conninfo" and "data_directory" */
|
||||||
conn = establish_db_connection(config_file_options.conninfo, true);
|
conn = establish_db_connection(config_file_options.conninfo, true);
|
||||||
strncpy(data_dir, config_file_options.data_directory, MAXPGPATH);
|
strncpy(data_dir, config_file_options.data_directory, MAXPGPATH);
|
||||||
|
|||||||
@@ -3024,7 +3024,7 @@ do_standby_switchover(void)
|
|||||||
bool switchover_success = true;
|
bool switchover_success = true;
|
||||||
|
|
||||||
XLogRecPtr remote_last_checkpoint_lsn = InvalidXLogRecPtr;
|
XLogRecPtr remote_last_checkpoint_lsn = InvalidXLogRecPtr;
|
||||||
ReplInfo replication_info = T_REPLINFO_INTIALIZER;
|
ReplInfo replication_info;
|
||||||
|
|
||||||
/* store list of configuration files on the demotion candidate */
|
/* store list of configuration files on the demotion candidate */
|
||||||
KeyValueList remote_config_files = {NULL, NULL};
|
KeyValueList remote_config_files = {NULL, NULL};
|
||||||
@@ -4190,6 +4190,7 @@ do_standby_switchover(void)
|
|||||||
log_verbose(LOG_INFO, _("successfully reconnected to local node"));
|
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
|
* 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
|
* checkpoint LSN. We'll loop for a while as it's possible the standby's
|
||||||
|
|||||||
@@ -2204,7 +2204,7 @@ do_primary_failover(void)
|
|||||||
static void
|
static void
|
||||||
update_monitoring_history(void)
|
update_monitoring_history(void)
|
||||||
{
|
{
|
||||||
ReplInfo replication_info = T_REPLINFO_INTIALIZER;
|
ReplInfo replication_info;
|
||||||
XLogRecPtr primary_last_wal_location = InvalidXLogRecPtr;
|
XLogRecPtr primary_last_wal_location = InvalidXLogRecPtr;
|
||||||
|
|
||||||
long long unsigned int apply_lag_bytes = 0;
|
long long unsigned int apply_lag_bytes = 0;
|
||||||
@@ -2223,6 +2223,8 @@ update_monitoring_history(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_replication_info(&replication_info);
|
||||||
|
|
||||||
if (get_replication_info(local_conn, &replication_info) == false)
|
if (get_replication_info(local_conn, &replication_info) == false)
|
||||||
{
|
{
|
||||||
log_warning(_("unable to retrieve replication status information, unable to update monitoring history"));
|
log_warning(_("unable to retrieve replication status information, unable to update monitoring history"));
|
||||||
|
|||||||
Reference in New Issue
Block a user