mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgrd: add option "connection_check_type"
This enable selection of the method repmgrd uses to check whether the upstream node is available. Possible values are: - "ping" (default): uses PQping() to check server availability - "connection": executes a query on the connection to check server availability (similar to repmgr3.x).
This commit is contained in:
52
repmgrd.c
52
repmgrd.c
@@ -818,6 +818,58 @@ show_help(void)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
check_upstream_connection(PGconn *conn, const char *conninfo)
|
||||
{
|
||||
/* Check the connection status twice in case it changes after reset */
|
||||
bool twice = false;
|
||||
|
||||
if (config_file_options.connection_check_type == CHECK_PING)
|
||||
return is_server_available(conninfo);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
{
|
||||
if (twice)
|
||||
return false;
|
||||
PQreset(conn); /* reconnect */
|
||||
twice = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cancel_query(conn, config_file_options.async_query_timeout))
|
||||
goto failed;
|
||||
|
||||
if (wait_connection_availability(conn, config_file_options.async_query_timeout) != 1)
|
||||
goto failed;
|
||||
|
||||
/* execute a simple query to verify connection availability */
|
||||
if (PQsendQuery(conn, "SELECT 1") == 0)
|
||||
{
|
||||
log_warning(_("unable to send query to upstream"));
|
||||
log_detail("%s", PQerrorMessage(conn));
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (wait_connection_availability(conn, config_file_options.async_query_timeout) != 1)
|
||||
goto failed;
|
||||
|
||||
break;
|
||||
|
||||
failed:
|
||||
/* retry once */
|
||||
if (twice)
|
||||
return false;
|
||||
PQreset(conn); /* reconnect */
|
||||
twice = true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
try_reconnect(PGconn **conn, t_node_info *node_info)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user