mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Enable get_master_connection() to accept a null value for master_id
Saves worrying about the purpose of various superfluous ints
This commit is contained in:
20
dbutils.c
20
dbutils.c
@@ -485,7 +485,6 @@ get_upstream_connection(PGconn *standby_conn, char *cluster, int node_id,
|
||||
* connection string is placed there.
|
||||
*/
|
||||
|
||||
// ZZZ value placed in `master_id` used by callers in repmgrd
|
||||
PGconn *
|
||||
get_master_connection(PGconn *standby_conn, char *cluster,
|
||||
int *master_id, char *master_conninfo_out)
|
||||
@@ -497,10 +496,14 @@ get_master_connection(PGconn *standby_conn, char *cluster,
|
||||
char master_conninfo_stack[MAXCONNINFO];
|
||||
char *master_conninfo = &*master_conninfo_stack;
|
||||
|
||||
int i;
|
||||
int i,
|
||||
node_id;
|
||||
|
||||
if(master_id != NULL)
|
||||
{
|
||||
*master_id = -1;
|
||||
}
|
||||
|
||||
// ZZZ below old stuff
|
||||
/* find all nodes belonging to this cluster */
|
||||
log_info(_("finding node list for cluster '%s'\n"),
|
||||
cluster);
|
||||
@@ -525,10 +528,10 @@ get_master_connection(PGconn *standby_conn, char *cluster,
|
||||
for (i = 0; i < PQntuples(res1); i++)
|
||||
{
|
||||
/* initialize with the values of the current node being processed */
|
||||
*master_id = atoi(PQgetvalue(res1, i, 0));
|
||||
node_id = atoi(PQgetvalue(res1, i, 0));
|
||||
strncpy(master_conninfo, PQgetvalue(res1, i, 1), MAXCONNINFO);
|
||||
log_info(_("checking role of cluster node '%i'\n"),
|
||||
*master_id);
|
||||
node_id);
|
||||
master_conn = establish_db_connection(master_conninfo, false);
|
||||
|
||||
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||
@@ -555,6 +558,12 @@ get_master_connection(PGconn *standby_conn, char *cluster,
|
||||
{
|
||||
PQclear(res2);
|
||||
PQclear(res1);
|
||||
|
||||
if(master_id != NULL)
|
||||
{
|
||||
*master_id = node_id;
|
||||
}
|
||||
|
||||
return master_conn;
|
||||
}
|
||||
else
|
||||
@@ -562,7 +571,6 @@ get_master_connection(PGconn *standby_conn, char *cluster,
|
||||
/* if it is a standby, clear info */
|
||||
PQclear(res2);
|
||||
PQfinish(master_conn);
|
||||
*master_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
repmgr.c
17
repmgr.c
@@ -480,7 +480,6 @@ do_cluster_show(void)
|
||||
static void
|
||||
do_cluster_cleanup(void)
|
||||
{
|
||||
int master_id;
|
||||
PGconn *conn = NULL;
|
||||
PGconn *master_conn = NULL;
|
||||
PGresult *res;
|
||||
@@ -493,7 +492,7 @@ do_cluster_cleanup(void)
|
||||
/* check if there is a master in this cluster */
|
||||
log_info(_("%s connecting to master database\n"), progname);
|
||||
master_conn = get_master_connection(conn, options.cluster_name,
|
||||
&master_id, NULL);
|
||||
NULL, NULL);
|
||||
if (!master_conn)
|
||||
{
|
||||
log_err(_("cluster cleanup: cannot connect to master\n"));
|
||||
@@ -595,7 +594,6 @@ do_master_register(void)
|
||||
else
|
||||
{
|
||||
PGconn *master_conn;
|
||||
int id;
|
||||
|
||||
if (runtime_options.force)
|
||||
{
|
||||
@@ -619,7 +617,7 @@ do_master_register(void)
|
||||
|
||||
/* Ensure there isn't any other master already registered */
|
||||
master_conn = get_master_connection(conn,
|
||||
options.cluster_name, &id, NULL);
|
||||
options.cluster_name, NULL, NULL);
|
||||
if (master_conn != NULL)
|
||||
{
|
||||
PQfinish(master_conn);
|
||||
@@ -656,8 +654,7 @@ do_standby_register(void)
|
||||
{
|
||||
PGconn *conn;
|
||||
PGconn *master_conn;
|
||||
int master_id,
|
||||
ret;
|
||||
int ret;
|
||||
|
||||
PGresult *res;
|
||||
char sqlquery[QUERY_STR_LEN];
|
||||
@@ -701,7 +698,7 @@ do_standby_register(void)
|
||||
/* check if there is a master in this cluster */
|
||||
log_info(_("%s connecting to master database\n"), progname);
|
||||
master_conn = get_master_connection(conn, options.cluster_name,
|
||||
&master_id, NULL);
|
||||
NULL, NULL);
|
||||
if (!master_conn)
|
||||
{
|
||||
log_err(_("A master must be defined before configuring a slave\n"));
|
||||
@@ -1105,7 +1102,6 @@ do_standby_promote(void)
|
||||
char script[MAXLEN];
|
||||
|
||||
PGconn *old_master_conn;
|
||||
int old_master_id;
|
||||
|
||||
int r,
|
||||
retval;
|
||||
@@ -1139,7 +1135,7 @@ do_standby_promote(void)
|
||||
|
||||
/* we also need to check if there isn't any master already */
|
||||
old_master_conn = get_master_connection(conn,
|
||||
options.cluster_name, &old_master_id, NULL);
|
||||
options.cluster_name, NULL, NULL);
|
||||
if (old_master_conn != NULL)
|
||||
{
|
||||
log_err(_("This cluster already has an active master server\n"));
|
||||
@@ -1220,7 +1216,6 @@ do_standby_follow(void)
|
||||
char script[MAXLEN];
|
||||
char master_conninfo[MAXLEN];
|
||||
PGconn *master_conn;
|
||||
int master_id;
|
||||
|
||||
int r,
|
||||
retval;
|
||||
@@ -1268,7 +1263,7 @@ do_standby_follow(void)
|
||||
}
|
||||
|
||||
master_conn = get_master_connection(conn,
|
||||
options.cluster_name, &master_id, (char *) &master_conninfo);
|
||||
options.cluster_name, NULL, (char *) &master_conninfo);
|
||||
}
|
||||
while (master_conn == NULL && runtime_options.wait_for_master);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user