mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
do not exit() in is_witness
This commit is contained in:
13
dbutils.c
13
dbutils.c
@@ -94,11 +94,11 @@ is_standby(PGconn *conn)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
int
|
||||||
is_witness(PGconn *conn, char *schema, char *cluster, int node_id)
|
is_witness(PGconn *conn, char *schema, char *cluster, int node_id)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
bool result = false;
|
int result = 0;
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT witness from %s.repl_nodes where cluster = '%s' and id = %d",
|
sqlquery_snprintf(sqlquery, "SELECT witness from %s.repl_nodes where cluster = '%s' and id = %d",
|
||||||
@@ -107,13 +107,10 @@ is_witness(PGconn *conn, char *schema, char *cluster, int node_id)
|
|||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
log_err(_("Can't query server mode: %s"), PQerrorMessage(conn));
|
log_err(_("Can't query server mode: %s"), PQerrorMessage(conn));
|
||||||
PQclear(res);
|
result = -1;
|
||||||
PQfinish(conn);
|
|
||||||
exit(ERR_DB_QUERY);
|
|
||||||
}
|
}
|
||||||
|
else if (PQntuples(res) == 1 && strcmp(PQgetvalue(res, 0, 0), "t") == 0)
|
||||||
if (PQntuples(res) == 1 && strcmp(PQgetvalue(res, 0, 0), "t") == 0)
|
result = 1;
|
||||||
result = true;
|
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ PGconn *establishDBConnectionByParams(const char *keywords[],
|
|||||||
const char *values[],
|
const char *values[],
|
||||||
const bool exit_on_error);
|
const bool exit_on_error);
|
||||||
int is_standby(PGconn *conn);
|
int is_standby(PGconn *conn);
|
||||||
bool is_witness(PGconn *conn, char *schema, char *cluster, int node_id);
|
int is_witness(PGconn *conn, char *schema, char *cluster, int node_id);
|
||||||
bool is_pgup(PGconn *conn, int timeout);
|
bool is_pgup(PGconn *conn, int timeout);
|
||||||
char *pg_version(PGconn *conn, char* major_version);
|
char *pg_version(PGconn *conn, char* major_version);
|
||||||
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||||
|
|||||||
24
repmgrd.c
24
repmgrd.c
@@ -301,23 +301,31 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ret = is_standby(myLocalConn);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set my server mode, establish a connection to primary
|
* Set my server mode, establish a connection to primary
|
||||||
* and start monitor
|
* and start monitor
|
||||||
*/
|
*/
|
||||||
if (is_witness(myLocalConn, repmgr_schema, local_options.cluster_name, local_options.node))
|
ret = is_witness(myLocalConn, repmgr_schema, local_options.cluster_name, local_options.node);
|
||||||
|
|
||||||
|
if (ret == 1)
|
||||||
myLocalMode = WITNESS_MODE;
|
myLocalMode = WITNESS_MODE;
|
||||||
else if (ret == 1)
|
else if (ret == 0)
|
||||||
myLocalMode = STANDBY_MODE;
|
{
|
||||||
|
ret = is_standby(myLocalConn);
|
||||||
|
|
||||||
|
if (ret == 1)
|
||||||
|
myLocalMode = STANDBY_MODE;
|
||||||
|
else if (ret == 0) /* is the master */
|
||||||
|
myLocalMode = PRIMARY_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX we did this before changing is_standby() to return int; we
|
/* XXX we did this before changing is_standby() to return int; we
|
||||||
* should not exit at this point, but for now we do until we have a
|
* should not exit at this point, but for now we do until we have a
|
||||||
* better strategy */
|
* better strategy */
|
||||||
else if (ret == -1)
|
if (ret == -1)
|
||||||
|
{
|
||||||
exit(1);
|
exit(1);
|
||||||
else /* is the master */
|
}
|
||||||
myLocalMode = PRIMARY_MODE;
|
|
||||||
|
|
||||||
switch (myLocalMode)
|
switch (myLocalMode)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user