mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +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
|
else
|
||||||
{
|
{
|
||||||
item_list_append(error_list,
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
log_verbose(LOG_DEBUG, "checking %s", upstream_node_info.conninfo);
|
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);
|
set_upstream_last_seen(local_conn);
|
||||||
}
|
}
|
||||||
@@ -1030,7 +1030,7 @@ monitor_streaming_standby(void)
|
|||||||
upstream_node_info.node_id,
|
upstream_node_info.node_id,
|
||||||
degraded_monitoring_elapsed);
|
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)
|
if (config_file_options.connection_check_type == CHECK_PING)
|
||||||
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
upstream_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||||
@@ -1605,7 +1605,7 @@ monitor_streaming_witness(void)
|
|||||||
|
|
||||||
while (true)
|
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)
|
if (upstream_node_info.node_status == NODE_STATUS_UP)
|
||||||
{
|
{
|
||||||
@@ -1694,7 +1694,7 @@ monitor_streaming_witness(void)
|
|||||||
upstream_node_info.node_id,
|
upstream_node_info.node_id,
|
||||||
degraded_monitoring_elapsed);
|
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)
|
if (config_file_options.connection_check_type == CHECK_PING)
|
||||||
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
primary_conn = establish_db_connection(upstream_node_info.conninfo, false);
|
||||||
|
|||||||
26
repmgrd.c
26
repmgrd.c
@@ -819,7 +819,7 @@ show_help(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
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 */
|
/* Check the connection status twice in case it changes after reset */
|
||||||
bool twice = false;
|
bool twice = false;
|
||||||
@@ -829,30 +829,33 @@ check_upstream_connection(PGconn *conn, const char *conninfo)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (PQstatus(conn) != CONNECTION_OK)
|
if (PQstatus(*conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
|
log_debug("connection not OK");
|
||||||
if (twice)
|
if (twice)
|
||||||
return false;
|
return false;
|
||||||
PQreset(conn); /* reconnect */
|
/* reconnect */
|
||||||
|
PQfinish(*conn);
|
||||||
|
*conn = PQconnectdb(conninfo);
|
||||||
twice = true;
|
twice = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!cancel_query(conn, config_file_options.async_query_timeout))
|
if (!cancel_query(*conn, config_file_options.async_query_timeout))
|
||||||
goto failed;
|
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;
|
goto failed;
|
||||||
|
|
||||||
/* execute a simple query to verify connection availability */
|
/* 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_warning(_("unable to send query to upstream"));
|
||||||
log_detail("%s", PQerrorMessage(conn));
|
log_detail("%s", PQerrorMessage(*conn));
|
||||||
goto failed;
|
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;
|
goto failed;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -861,7 +864,10 @@ check_upstream_connection(PGconn *conn, const char *conninfo)
|
|||||||
/* retry once */
|
/* retry once */
|
||||||
if (twice)
|
if (twice)
|
||||||
return false;
|
return false;
|
||||||
PQreset(conn); /* reconnect */
|
|
||||||
|
/* reconnect */
|
||||||
|
PQfinish(*conn);
|
||||||
|
*conn = PQconnectdb(conninfo);
|
||||||
twice = true;
|
twice = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -926,7 +932,7 @@ try_reconnect(PGconn **conn, t_node_info *node_info)
|
|||||||
|
|
||||||
if (ping_result != PGRES_TUPLES_OK)
|
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);
|
close_connection(conn);
|
||||||
*conn = our_conn;
|
*conn = our_conn;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ extern PGconn *local_conn;
|
|||||||
extern bool startup_event_logged;
|
extern bool startup_event_logged;
|
||||||
extern char pid_file[MAXPGPATH];
|
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);
|
void try_reconnect(PGconn **conn, t_node_info *node_info);
|
||||||
|
|
||||||
int calculate_elapsed(instr_time start_time);
|
int calculate_elapsed(instr_time start_time);
|
||||||
|
|||||||
Reference in New Issue
Block a user