mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
repmgrd: handle reconnect to restarted server when using "connection" checks
This commit is contained in:
@@ -632,7 +632,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
||||
else
|
||||
{
|
||||
item_list_append(error_list,
|
||||
_("value for \"connection_check_type\" must be \"ping\" or \"connect\"\n"));
|
||||
_("value for \"connection_check_type\" must be \"ping\" or \"connection\"\n"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -831,7 +831,7 @@ monitor_streaming_standby(void)
|
||||
while (true)
|
||||
{
|
||||
log_verbose(LOG_DEBUG, "checking %s", upstream_node_info.conninfo);
|
||||
if (check_upstream_connection(upstream_conn, upstream_node_info.conninfo) == true)
|
||||
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == true)
|
||||
{
|
||||
set_upstream_last_seen(local_conn);
|
||||
}
|
||||
@@ -1030,7 +1030,7 @@ monitor_streaming_standby(void)
|
||||
upstream_node_info.node_id,
|
||||
degraded_monitoring_elapsed);
|
||||
|
||||
if (check_upstream_connection(upstream_conn, upstream_node_info.conninfo) == true)
|
||||
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == true)
|
||||
{
|
||||
if (config_file_options.connection_check_type == CHECK_PING)
|
||||
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||
@@ -1605,7 +1605,7 @@ monitor_streaming_witness(void)
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (check_upstream_connection(upstream_conn, upstream_node_info.conninfo) == false)
|
||||
if (check_upstream_connection(&upstream_conn, upstream_node_info.conninfo) == false)
|
||||
{
|
||||
if (upstream_node_info.node_status == NODE_STATUS_UP)
|
||||
{
|
||||
@@ -1694,7 +1694,7 @@ monitor_streaming_witness(void)
|
||||
upstream_node_info.node_id,
|
||||
degraded_monitoring_elapsed);
|
||||
|
||||
if (check_upstream_connection(primary_conn, upstream_node_info.conninfo) == true)
|
||||
if (check_upstream_connection(&primary_conn, upstream_node_info.conninfo) == true)
|
||||
{
|
||||
if (config_file_options.connection_check_type == CHECK_PING)
|
||||
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||
|
||||
26
repmgrd.c
26
repmgrd.c
@@ -819,7 +819,7 @@ show_help(void)
|
||||
|
||||
|
||||
bool
|
||||
check_upstream_connection(PGconn *conn, const char *conninfo)
|
||||
check_upstream_connection(PGconn **conn, const char *conninfo)
|
||||
{
|
||||
/* Check the connection status twice in case it changes after reset */
|
||||
bool twice = false;
|
||||
@@ -829,30 +829,33 @@ check_upstream_connection(PGconn *conn, const char *conninfo)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
if (PQstatus(*conn) != CONNECTION_OK)
|
||||
{
|
||||
log_debug("connection not OK");
|
||||
if (twice)
|
||||
return false;
|
||||
PQreset(conn); /* reconnect */
|
||||
/* reconnect */
|
||||
PQfinish(*conn);
|
||||
*conn = PQconnectdb(conninfo);
|
||||
twice = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cancel_query(conn, config_file_options.async_query_timeout))
|
||||
if (!cancel_query(*conn, config_file_options.async_query_timeout))
|
||||
goto failed;
|
||||
|
||||
if (wait_connection_availability(conn, config_file_options.async_query_timeout) != 1)
|
||||
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)
|
||||
if (PQsendQuery(*conn, "SELECT 1") == 0)
|
||||
{
|
||||
log_warning(_("unable to send query to upstream"));
|
||||
log_detail("%s", PQerrorMessage(conn));
|
||||
log_detail("%s", PQerrorMessage(*conn));
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (wait_connection_availability(conn, config_file_options.async_query_timeout) != 1)
|
||||
if (wait_connection_availability(*conn, config_file_options.async_query_timeout) != 1)
|
||||
goto failed;
|
||||
|
||||
break;
|
||||
@@ -861,7 +864,10 @@ check_upstream_connection(PGconn *conn, const char *conninfo)
|
||||
/* retry once */
|
||||
if (twice)
|
||||
return false;
|
||||
PQreset(conn); /* reconnect */
|
||||
|
||||
/* reconnect */
|
||||
PQfinish(*conn);
|
||||
*conn = PQconnectdb(conninfo);
|
||||
twice = true;
|
||||
}
|
||||
}
|
||||
@@ -926,7 +932,7 @@ try_reconnect(PGconn **conn, t_node_info *node_info)
|
||||
|
||||
if (ping_result != PGRES_TUPLES_OK)
|
||||
{
|
||||
log_info("original connnection no longer available, using new connection");
|
||||
log_info("original connection no longer available, using new connection");
|
||||
close_connection(conn);
|
||||
*conn = our_conn;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ extern PGconn *local_conn;
|
||||
extern bool startup_event_logged;
|
||||
extern char pid_file[MAXPGPATH];
|
||||
|
||||
bool check_upstream_connection(PGconn *conn, const char *conninfo);
|
||||
bool check_upstream_connection(PGconn **conn, const char *conninfo);
|
||||
void try_reconnect(PGconn **conn, t_node_info *node_info);
|
||||
|
||||
int calculate_elapsed(instr_time start_time);
|
||||
|
||||
Reference in New Issue
Block a user