Fix query in is_active_bdr_node()

Boolean column was not being checked correctly.

Also add detail output in "repmgr node role --check", where the function
is called.
This commit is contained in:
Ian Barwick
2018-01-04 10:46:29 +09:00
parent b26e400199
commit 3d2530d6f9
2 changed files with 13 additions and 7 deletions

View File

@@ -4163,20 +4163,23 @@ is_active_bdr_node(PGconn *conn, const char *node_name)
" SELECT COALESCE(s.active, TRUE) AS active" " SELECT COALESCE(s.active, TRUE) AS active"
" FROM bdr.bdr_nodes n " " FROM bdr.bdr_nodes n "
" LEFT JOIN pg_catalog.pg_replication_slots s " " LEFT JOIN pg_catalog.pg_replication_slots s "
" ON slot_name=bdr.bdr_format_slot_name(n.node_sysid, n.node_timeline, n.node_dboid, (SELECT oid FROM pg_database WHERE datname = current_database())) " " ON s.slot_name=bdr.bdr_format_slot_name(n.node_sysid, n.node_timeline, n.node_dboid, (SELECT oid FROM pg_catalog.pg_database WHERE datname = pg_catalog.current_database())) "
" WHERE node_name='%s' ", " WHERE n.node_name='%s' ",
node_name); node_name);
log_verbose(LOG_DEBUG, "is_active_bdr_node():\n %s", query.data);
res = PQexec(conn, query.data); res = PQexec(conn, query.data);
termPQExpBuffer(&query); termPQExpBuffer(&query);
/* we don't care if the query fails */
if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) == 0) if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) == 0)
{ {
is_active_bdr_node = false; is_active_bdr_node = false;
} }
else else
{ {
is_active_bdr_node = atoi(PQgetvalue(res, 0, 0)) == 1 ? true : false; is_active_bdr_node = atobool(PQgetvalue(res, 0, 0));
} }
PQclear(res); PQclear(res);

View File

@@ -728,8 +728,7 @@ do_node_check_role(PGconn *conn, OutputMode mode, t_node_info *node_info, CheckS
} }
else else
{ {
appendPQExpBuffer( appendPQExpBuffer(&details,
&details,
_("node is primary")); _("node is primary"));
} }
break; break;
@@ -754,8 +753,7 @@ do_node_check_role(PGconn *conn, OutputMode mode, t_node_info *node_info, CheckS
if (is_bdr_db(conn, &output) == false) if (is_bdr_db(conn, &output) == false)
{ {
status = CHECK_STATUS_CRITICAL; status = CHECK_STATUS_CRITICAL;
appendPQExpBuffer( appendPQExpBuffer(&details,
&details,
"%s", output.data); "%s", output.data);
} }
termPQExpBuffer(&output); termPQExpBuffer(&output);
@@ -768,6 +766,11 @@ do_node_check_role(PGconn *conn, OutputMode mode, t_node_info *node_info, CheckS
appendPQExpBuffer(&details, appendPQExpBuffer(&details,
_("node is not an active BDR node")); _("node is not an active BDR node"));
} }
else
{
appendPQExpBuffer(&details,
_("node is an active BDR node"));
}
} }
} }
default: default: