mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Always use PQstatus to check connection status
This addresses GitHib #234.
This commit is contained in:
@@ -1484,7 +1484,6 @@ create_event_record(PGconn *conn, t_configuration_options *options, int node_id,
|
|||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
|
|
||||||
success = false;
|
success = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
16
repmgr.c
16
repmgr.c
@@ -1053,7 +1053,7 @@ do_cluster_cleanup(void)
|
|||||||
log_info(_("connecting to master database\n"));
|
log_info(_("connecting to master database\n"));
|
||||||
master_conn = get_master_connection(conn, options.cluster_name,
|
master_conn = get_master_connection(conn, options.cluster_name,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("cluster cleanup: cannot connect to master\n"));
|
log_err(_("cluster cleanup: cannot connect to master\n"));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -1325,7 +1325,7 @@ do_standby_register(void)
|
|||||||
log_info(_("connecting to master database\n"));
|
log_info(_("connecting to master database\n"));
|
||||||
master_conn = get_master_connection(conn, options.cluster_name,
|
master_conn = get_master_connection(conn, options.cluster_name,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("a master must be defined before configuring a standby\n"));
|
log_err(_("a master must be defined before configuring a standby\n"));
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -1456,7 +1456,7 @@ do_standby_unregister(void)
|
|||||||
log_info(_("connecting to master database\n"));
|
log_info(_("connecting to master database\n"));
|
||||||
master_conn = get_master_connection(conn, options.cluster_name,
|
master_conn = get_master_connection(conn, options.cluster_name,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("a master must be defined before unregistering a standby\n"));
|
log_err(_("a master must be defined before unregistering a standby\n"));
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -2755,9 +2755,9 @@ do_standby_follow(void)
|
|||||||
master_conn = get_master_connection(conn,
|
master_conn = get_master_connection(conn,
|
||||||
options.cluster_name, &master_id, (char *) &master_conninfo);
|
options.cluster_name, &master_id, (char *) &master_conninfo);
|
||||||
}
|
}
|
||||||
while (master_conn == NULL && runtime_options.wait_for_master);
|
while (PQstatus(master_conn) != CONNECTION_OK && runtime_options.wait_for_master);
|
||||||
|
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("unable to determine new master node\n"));
|
log_err(_("unable to determine new master node\n"));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -2978,7 +2978,7 @@ do_standby_switchover(void)
|
|||||||
/* Check that primary is available */
|
/* Check that primary is available */
|
||||||
remote_conn = get_master_connection(local_conn, options.cluster_name, &remote_node_id, remote_conninfo);
|
remote_conn = get_master_connection(local_conn, options.cluster_name, &remote_node_id, remote_conninfo);
|
||||||
|
|
||||||
if (remote_conn == NULL)
|
if (PQstatus(remote_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("unable to connect to current master node\n"));
|
log_err(_("unable to connect to current master node\n"));
|
||||||
log_hint(_("check that the cluster is correctly configured and this standby is registered\n"));
|
log_hint(_("check that the cluster is correctly configured and this standby is registered\n"));
|
||||||
@@ -4262,7 +4262,7 @@ do_witness_register(PGconn *masterconn)
|
|||||||
param_set("dbname", repmgr_db);
|
param_set("dbname", repmgr_db);
|
||||||
|
|
||||||
/* masterconn will only be set when called from do_witness_create() */
|
/* masterconn will only be set when called from do_witness_create() */
|
||||||
if (masterconn == NULL)
|
if (PQstatus(masterconn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
event_is_register = true;
|
event_is_register = true;
|
||||||
|
|
||||||
@@ -4456,7 +4456,7 @@ do_witness_unregister(void)
|
|||||||
log_info(_("connecting to master server\n"));
|
log_info(_("connecting to master server\n"));
|
||||||
master_conn = get_master_connection(conn, options.cluster_name,
|
master_conn = get_master_connection(conn, options.cluster_name,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("Unable to connect to master server\n"));
|
log_err(_("Unable to connect to master server\n"));
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
|
|||||||
14
repmgrd.c
14
repmgrd.c
@@ -111,17 +111,15 @@ static void check_and_create_pid_file(const char *pid_file);
|
|||||||
static void
|
static void
|
||||||
close_connections()
|
close_connections()
|
||||||
{
|
{
|
||||||
if (master_conn != NULL && PQisBusy(master_conn) == 1)
|
if (PQstatus(master_conn) == CONNECTION_OK && PQisBusy(master_conn) == 1)
|
||||||
cancel_query(master_conn, local_options.master_response_timeout);
|
cancel_query(master_conn, local_options.master_response_timeout);
|
||||||
|
|
||||||
if (my_local_conn != NULL)
|
|
||||||
|
if (PQstatus(my_local_conn) == CONNECTION_OK)
|
||||||
PQfinish(my_local_conn);
|
PQfinish(my_local_conn);
|
||||||
|
|
||||||
if (master_conn != NULL && master_conn != my_local_conn)
|
if (PQstatus(master_conn) == CONNECTION_OK)
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
|
|
||||||
master_conn = NULL;
|
|
||||||
my_local_conn = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -429,7 +427,7 @@ main(int argc, char **argv)
|
|||||||
local_options.cluster_name,
|
local_options.cluster_name,
|
||||||
&master_options.node, NULL);
|
&master_options.node, NULL);
|
||||||
|
|
||||||
if (master_conn == NULL)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
PQExpBufferData errmsg;
|
PQExpBufferData errmsg;
|
||||||
initPQExpBuffer(&errmsg);
|
initPQExpBuffer(&errmsg);
|
||||||
@@ -2013,7 +2011,7 @@ check_connection(PGconn **conn, const char *type, const char *conninfo)
|
|||||||
{
|
{
|
||||||
if (conninfo == NULL)
|
if (conninfo == NULL)
|
||||||
{
|
{
|
||||||
log_err("INTERNAL ERROR: *conn == NULL && conninfo == NULL");
|
log_err("INTERNAL ERROR: *conn == NULL && conninfo == NULL\n");
|
||||||
terminate(ERR_INTERNAL);
|
terminate(ERR_INTERNAL);
|
||||||
}
|
}
|
||||||
*conn = establish_db_connection(conninfo, false);
|
*conn = establish_db_connection(conninfo, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user