From cd3312496e1dbdc6cc39f838fec3cd46501f57ae Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 6 Feb 2019 09:30:45 +0900 Subject: [PATCH] Rename functions which return an LSN for clarity --- dbutils.c | 20 +++++++++++++++----- dbutils.h | 4 ++-- repmgr-action-standby.c | 4 ++-- repmgr-client.c | 2 +- repmgrd-physical.c | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dbutils.c b/dbutils.c index 20f71d55..e2da25de 100644 --- a/dbutils.c +++ b/dbutils.c @@ -4551,9 +4551,16 @@ reset_voting_status(PGconn *conn) /* replication status functions */ /* ============================ */ - +/* + * Returns the current LSN on the primary. + * + * This just executes "pg_current_wal_lsn()". + * + * Function "get_node_current_lsn()" below will return the latest + * LSN regardless of recovery state. + */ XLogRecPtr -get_current_wal_lsn(PGconn *conn) +get_primary_current_lsn(PGconn *conn) { PGresult *res = NULL; XLogRecPtr ptr = InvalidXLogRecPtr; @@ -4577,6 +4584,7 @@ get_current_wal_lsn(PGconn *conn) return ptr; } + XLogRecPtr get_last_wal_receive_location(PGconn *conn) { @@ -4602,9 +4610,11 @@ get_last_wal_receive_location(PGconn *conn) return ptr; } - +/* + * Returns the latest LSN for the node regardless of recovery state. + */ XLogRecPtr -get_current_lsn(PGconn *conn) +get_node_current_lsn(PGconn *conn) { PQExpBufferData query; PGresult *res = NULL; @@ -4678,7 +4688,7 @@ get_current_lsn(PGconn *conn) if (PQresultStatus(res) != PGRES_TUPLES_OK) { - log_db_error(conn, query.data, _("unable to execute get_current_lsn()")); + log_db_error(conn, query.data, _("unable to execute get_node_current_lsn()")); } else if (!PQgetisnull(res, 0, 0)) { diff --git a/dbutils.h b/dbutils.h index 568ba9fa..43e193a9 100644 --- a/dbutils.h +++ b/dbutils.h @@ -538,9 +538,9 @@ bool get_new_primary(PGconn *conn, int *primary_node_id); void reset_voting_status(PGconn *conn); /* replication status functions */ -XLogRecPtr get_current_wal_lsn(PGconn *conn); +XLogRecPtr get_primary_current_lsn(PGconn *conn); +XLogRecPtr get_node_current_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); diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index bb499feb..020fdd8e 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -2532,7 +2532,7 @@ do_standby_follow(void) t_system_identification local_identification = T_SYSTEM_IDENTIFICATION_INITIALIZER; bool can_follow; - XLogRecPtr local_xlogpos = get_current_lsn(local_conn); + XLogRecPtr local_xlogpos = get_node_current_lsn(local_conn); /* Check local replication connection - we want to execute IDENTIFY_SYSTEM * to get the current timeline ID, which might not yet be written to @@ -3234,7 +3234,7 @@ do_standby_switchover(void) * to unexpected behaviour when the standby is promoted. * * For switchover we'll mandate that WAL replay *must not* be paused. - * For a promote operation we can proceed if WAL replay is paused + * For a promote operation we can proceed if WAL replay is paused and * there is no more available WAL to be replayed, as we can be sure the * primary is down already, but in a switchover context there's * potentially a window for more WAL to be received before we shut down diff --git a/repmgr-client.c b/repmgr-client.c index 08071101..0e9ac9c1 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -3321,7 +3321,7 @@ check_node_can_attach(TimeLineID local_tli, XLogRecPtr local_xlogpos, PGconn *fo if (follow_target_identification.timeline == local_tli) { - XLogRecPtr follow_target_xlogpos = get_current_lsn(follow_target_conn); + XLogRecPtr follow_target_xlogpos = get_node_current_lsn(follow_target_conn); if (local_xlogpos == InvalidXLogRecPtr || follow_target_xlogpos == InvalidXLogRecPtr) { diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 4dc19b14..e09d1d54 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -2242,7 +2242,7 @@ update_monitoring_history(void) local_node_info.node_id); } - primary_last_wal_location = get_current_wal_lsn(primary_conn); + primary_last_wal_location = get_primary_current_lsn(primary_conn); if (primary_last_wal_location == InvalidXLogRecPtr) {