From bffb8fa11b125009eee1ee1f3136d2ed50f3e5f2 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 31 Mar 2020 10:49:30 +0900 Subject: [PATCH] node check: handle --upstream option when node is primary --- doc/repmgr-node-check.xml | 1 + repmgr-action-node.c | 61 +++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/doc/repmgr-node-check.xml b/doc/repmgr-node-check.xml index 093f8001..063851ed 100644 --- a/doc/repmgr-node-check.xml +++ b/doc/repmgr-node-check.xml @@ -37,6 +37,7 @@ Server role: OK (node is primary) Replication lag: OK (N/A - node is primary) WAL archiving: OK (0 pending files) + Upstream connection: OK (N/A - is primary) Downstream servers: OK (2 of 2 downstream nodes attached) Replication slots: OK (node has no physical replication slots) Missing replication slots: OK (node has no missing physical replication slots) diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 1987e7d9..ff1410c6 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -1358,7 +1358,6 @@ do_node_check_upstream(PGconn *conn, OutputMode mode, t_node_info *node_info, Ch CheckStatus status = CHECK_STATUS_OK; - if (mode == OM_CSV && list_output == NULL) { log_error(_("--csv output not provided with --upstream option")); @@ -1366,36 +1365,48 @@ do_node_check_upstream(PGconn *conn, OutputMode mode, t_node_info *node_info, Ch exit(ERR_BAD_CONFIG); } - if (get_node_record(conn, node_info->upstream_node_id, &upstream_node_info) != RECORD_FOUND) - { - log_error(_("no record found for upstream node %i"), node_info->upstream_node_id); - PQfinish(conn); - exit(ERR_BAD_CONFIG); - } - initPQExpBuffer(&details); - upstream_conn = establish_db_connection(upstream_node_info.conninfo, true); - - /* check our node is connected */ - if (is_downstream_node_attached(upstream_conn, config_file_options.node_name) != NODE_ATTACHED) + if (get_node_record(conn, node_info->upstream_node_id, &upstream_node_info) != RECORD_FOUND) { - appendPQExpBuffer(&details, - _("node \"%s\" (ID: %i) is not attached to expected upstream node \"%s\" (ID: %i)"), - node_info->node_name, - node_info->node_id, - upstream_node_info.node_name, - upstream_node_info.node_id); - status = CHECK_STATUS_CRITICAL; + if (get_recovery_type(conn) == RECTYPE_STANDBY) + { + appendPQExpBuffer(&details, + _("node \"%s\" (ID: %i) is a standby but no upstream record found"), + node_info->node_name, + node_info->node_id); + status = CHECK_STATUS_CRITICAL; + } + else + { + appendPQExpBufferStr(&details, + _("N/A - node is primary")); + } } else { - appendPQExpBuffer(&details, - _("node \"%s\" (ID: %i) is attached to expected upstream node \"%s\" (ID: %i)"), - node_info->node_name, - node_info->node_id, - upstream_node_info.node_name, - upstream_node_info.node_id); + upstream_conn = establish_db_connection(upstream_node_info.conninfo, true); + + /* check our node is connected */ + if (is_downstream_node_attached(upstream_conn, config_file_options.node_name) != NODE_ATTACHED) + { + appendPQExpBuffer(&details, + _("node \"%s\" (ID: %i) is not attached to expected upstream node \"%s\" (ID: %i)"), + node_info->node_name, + node_info->node_id, + upstream_node_info.node_name, + upstream_node_info.node_id); + status = CHECK_STATUS_CRITICAL; + } + else + { + appendPQExpBuffer(&details, + _("node \"%s\" (ID: %i) is attached to expected upstream node \"%s\" (ID: %i)"), + node_info->node_name, + node_info->node_id, + upstream_node_info.node_name, + upstream_node_info.node_id); + } } switch (mode)