mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgrd: use PQping() as a first test of whether an upstream node is available
It's possible the upstream node may be temporarily not accepting connections but is still running, so we only confirm that connections are not possible once PQping() reports a negative result. This feature has been adapted from repmgr4.
This commit is contained in:
16
dbutils.c
16
dbutils.c
@@ -2137,3 +2137,19 @@ get_last_wal_receive_location(PGconn *conn)
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_server_available(const char *conninfo)
|
||||
{
|
||||
PGPing status = PQping(conninfo);
|
||||
|
||||
log_verbose(LOG_DEBUG, "is_server_available(): ping status for \"%s\" is %i\n", conninfo, (int)status);
|
||||
|
||||
if (status == PQPING_OK)
|
||||
return true;
|
||||
|
||||
log_warning("is_server_available(): ping status for \"%s\" is %i\n", conninfo, (int)status);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -146,5 +146,6 @@ int get_data_checksum_version(const char *data_directory);
|
||||
/* backported from repmgr 4.x */
|
||||
XLogRecPtr parse_lsn(const char *str);
|
||||
XLogRecPtr get_last_wal_receive_location(PGconn *conn);
|
||||
bool is_server_available(const char *conninfo);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -879,9 +879,7 @@ standby_monitor(void)
|
||||
* local_options.reconnect_interval seconds
|
||||
*/
|
||||
|
||||
check_connection(&upstream_conn, upstream_node_type, upstream_conninfo);
|
||||
|
||||
if (PQstatus(upstream_conn) != CONNECTION_OK)
|
||||
if (!check_connection(&upstream_conn, upstream_node_type, upstream_conninfo))
|
||||
{
|
||||
int previous_master_node_id = master_options.node;
|
||||
|
||||
@@ -2137,8 +2135,11 @@ check_connection(PGconn **conn, const char *type, const char *conninfo)
|
||||
{
|
||||
int connection_retries;
|
||||
|
||||
if (conninfo != NULL && is_server_available(conninfo))
|
||||
return true;
|
||||
|
||||
/*
|
||||
* Check if the node is still available if after
|
||||
* Check if the node is still available; if after
|
||||
* local_options.reconnect_attempts * local_options.reconnect_interval
|
||||
* seconds of retries we cannot reconnect return false
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user