From 8aaf6571a0b349093216b1fc4cfad647f26e6703 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 7 Feb 2019 14:14:24 +0900 Subject: [PATCH] "cluster show": display node priority GitHUb #541. --- doc/repmgr-cluster-show.sgml | 28 +++++++++++++++------------- repmgr-action-cluster.c | 29 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/doc/repmgr-cluster-show.sgml b/doc/repmgr-cluster-show.sgml index fa748303..ce43ff34 100644 --- a/doc/repmgr-cluster-show.sgml +++ b/doc/repmgr-cluster-show.sgml @@ -44,11 +44,11 @@ $ repmgr -f /etc/repmgr.conf cluster show - ID | Name | Role | Status | Upstream | Location | Connection string - ----+-------+---------+-----------+----------+----------+----------------------------------------- - 1 | node1 | primary | * running | | default | host=db_node1 dbname=repmgr user=repmgr - 2 | node2 | standby | running | node1 | default | host=db_node2 dbname=repmgr user=repmgr - 3 | node3 | standby | running | node1 | default | host=db_node3 dbname=repmgr user=repmgr + ID | Name | Role | Status | Upstream | Location | Priority | Connection string + ----+-------+---------+-----------+----------+----------+----------+----------------------------------------- + 1 | node1 | primary | * running | | default | 100 | host=db_node1 dbname=repmgr user=repmgr + 2 | node2 | standby | running | node1 | default | 100 | host=db_node2 dbname=repmgr user=repmgr + 3 | node3 | standby | running | node1 | default | 100 | host=db_node3 dbname=repmgr user=repmgr @@ -61,21 +61,23 @@ $ repmgr -f /etc/repmgr.conf cluster show - ID | Name | Role | Status | Upstream | Location | Connection string - ----+-------+---------+----------------------+----------+----------+----------------------------------------- - 1 | node1 | primary | ? unreachable | | default | host=db_node1 dbname=repmgr user=repmgr - 2 | node2 | standby | ! running as primary | node1 | default | host=db_node2 dbname=repmgr user=repmgr - 3 | node3 | standby | running | node1 | default | host=db_node3 dbname=repmgr user=repmgr + ID | Name | Role | Status | Upstream | Location | Priority | Connection string + ----+-------+---------+----------------------+----------+----------+----------+----------------------------------------- + 1 | node1 | primary | ? unreachable | | default | 100 | host=db_node1 dbname=repmgr user=repmgr + 2 | node2 | standby | ! running as primary | node1 | default | 100 | host=db_node2 dbname=repmgr user=repmgr + 3 | node3 | standby | running | node1 | default | 100 | host=db_node3 dbname=repmgr user=repmgr WARNING: following issues were detected - node "node1" (ID: 1) is registered as an active primary but is unreachable - node "node2" (ID: 2) is registered as standby but running as primary + - unable to connect to node "node1" (ID: 1) + - node "node1" (ID: 1) is registered as an active primary but is unreachable + - node "node2" (ID: 2) is registered as standby but running as primary + HINT: execute with --verbose option to see connection error messages Node availability is tested by connecting from the node where repmgr cluster show is executed, and does not necessarily imply the node is down. See and to get - a better overviews of connections between nodes. + better overviews of connections between nodes. diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index 1fa797c3..d9595533 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -24,7 +24,7 @@ #include "repmgr-client-global.h" #include "repmgr-action-cluster.h" -#define SHOW_HEADER_COUNT 7 +#define SHOW_HEADER_COUNT 8 typedef enum { @@ -34,6 +34,7 @@ typedef enum SHOW_STATUS, SHOW_UPSTREAM_NAME, SHOW_LOCATION, + SHOW_PRIORITY, SHOW_CONNINFO } ShowHeader; @@ -109,6 +110,12 @@ do_cluster_show(void) strncpy(headers_show[SHOW_STATUS].title, _("Status"), MAXLEN); strncpy(headers_show[SHOW_UPSTREAM_NAME].title, _("Upstream"), MAXLEN); strncpy(headers_show[SHOW_LOCATION].title, _("Location"), MAXLEN); + + if (runtime_options.compact == true) + strncpy(headers_show[SHOW_PRIORITY].title, _("Prio."), MAXLEN); + else + strncpy(headers_show[SHOW_PRIORITY].title, _("Priority"), MAXLEN); + strncpy(headers_show[SHOW_CONNINFO].title, _("Connection string"), MAXLEN); /* @@ -137,7 +144,7 @@ do_cluster_show(void) for (cell = nodes.head; cell; cell = cell->next) { PQExpBufferData details; - PQExpBufferData node_id; + PQExpBufferData buf; cell->node_info->conn = establish_db_connection_quiet(cell->node_info->conninfo); @@ -362,16 +369,25 @@ do_cluster_show(void) PQfinish(cell->node_info->conn); cell->node_info->conn = NULL; - initPQExpBuffer(&node_id); - appendPQExpBuffer(&node_id, "%i", cell->node_info->node_id); - headers_show[SHOW_ID].cur_length = strlen(node_id.data); - termPQExpBuffer(&node_id); + initPQExpBuffer(&buf); + appendPQExpBuffer(&buf, "%i", cell->node_info->node_id); + headers_show[SHOW_ID].cur_length = strlen(buf.data); + termPQExpBuffer(&buf); headers_show[SHOW_ROLE].cur_length = strlen(get_node_type_string(cell->node_info->type)); headers_show[SHOW_NAME].cur_length = strlen(cell->node_info->node_name); headers_show[SHOW_STATUS].cur_length = strlen(cell->node_info->details); headers_show[SHOW_UPSTREAM_NAME].cur_length = strlen(cell->node_info->upstream_node_name); + + initPQExpBuffer(&buf); + appendPQExpBuffer(&buf, "%i", cell->node_info->priority); + headers_show[SHOW_PRIORITY].cur_length = strlen(buf.data); + termPQExpBuffer(&buf); + headers_show[SHOW_LOCATION].cur_length = strlen(cell->node_info->location); + + + headers_show[SHOW_CONNINFO].cur_length = strlen(cell->node_info->conninfo); for (i = 0; i < SHOW_HEADER_COUNT; i++) @@ -433,6 +449,7 @@ do_cluster_show(void) printf("| %-*s ", headers_show[SHOW_STATUS].max_length, cell->node_info->details); printf("| %-*s ", headers_show[SHOW_UPSTREAM_NAME].max_length, cell->node_info->upstream_node_name); printf("| %-*s ", headers_show[SHOW_LOCATION].max_length, cell->node_info->location); + printf("| %-*i ", headers_show[SHOW_PRIORITY].max_length, cell->node_info->priority); if (headers_show[SHOW_CONNINFO].display == true) {