From 3d2530d6f9ef92aa3e70672484632ecea5619e92 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 4 Jan 2018 10:46:29 +0900 Subject: [PATCH] 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. --- dbutils.c | 9 ++++++--- repmgr-action-node.c | 11 +++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dbutils.c b/dbutils.c index 63331513..61148274 100644 --- a/dbutils.c +++ b/dbutils.c @@ -4163,20 +4163,23 @@ is_active_bdr_node(PGconn *conn, const char *node_name) " SELECT COALESCE(s.active, TRUE) AS active" " FROM bdr.bdr_nodes n " " 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())) " - " WHERE node_name='%s' ", + " 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 n.node_name='%s' ", node_name); + log_verbose(LOG_DEBUG, "is_active_bdr_node():\n %s", query.data); + res = PQexec(conn, query.data); termPQExpBuffer(&query); + /* we don't care if the query fails */ if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) == 0) { is_active_bdr_node = false; } else { - is_active_bdr_node = atoi(PQgetvalue(res, 0, 0)) == 1 ? true : false; + is_active_bdr_node = atobool(PQgetvalue(res, 0, 0)); } PQclear(res); diff --git a/repmgr-action-node.c b/repmgr-action-node.c index e3ae2842..bd8b252b 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -728,8 +728,7 @@ do_node_check_role(PGconn *conn, OutputMode mode, t_node_info *node_info, CheckS } else { - appendPQExpBuffer( - &details, + appendPQExpBuffer(&details, _("node is primary")); } 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) { status = CHECK_STATUS_CRITICAL; - appendPQExpBuffer( - &details, + appendPQExpBuffer(&details, "%s", output.data); } termPQExpBuffer(&output); @@ -768,6 +766,11 @@ do_node_check_role(PGconn *conn, OutputMode mode, t_node_info *node_info, CheckS appendPQExpBuffer(&details, _("node is not an active BDR node")); } + else + { + appendPQExpBuffer(&details, + _("node is an active BDR node")); + } } } default: