From ae67e086a410861186027fdd5865cfe6b68b4dec Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 23 Jun 2017 11:37:42 +0900 Subject: [PATCH] repmgr master unregister: tighten behaviour --- log.c | 2 +- repmgr-action-master.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/log.c b/log.c index 520c8cfb..ad5bf648 100644 --- a/log.c +++ b/log.c @@ -21,7 +21,7 @@ #define DEFAULT_SYSLOG_FACILITY LOG_LOCAL0 #endif -#define REPMGR_DEBUG +/* #define REPMGR_DEBUG */ static int detect_log_facility(const char *facility); static void _stderr_log_with_level(const char *level_name, int level, const char *fmt, va_list ap) diff --git a/repmgr-action-master.c b/repmgr-action-master.c index a69f5c49..b2f076b5 100644 --- a/repmgr-action-master.c +++ b/repmgr-action-master.c @@ -375,23 +375,39 @@ do_master_unregister(void) /* If we can connect to the node, perform some sanity checks on it */ else { + bool can_unregister = true; t_recovery_type recovery_type = get_recovery_type(target_node_conn); /* Node appears to be a standby */ if (recovery_type == RECTYPE_STANDBY) { + /* We'll refuse to do anything unless the node record shows it as a master */ + + if (target_node_info_ptr->type != MASTER) + { + log_error(_("node %s (id: %i) is a %s, unable to unregister"), + target_node_info_ptr->node_name, + target_node_info_ptr->node_id, + get_node_type_string(target_node_info_ptr->type)); + can_unregister = false; + } /* * If --F/--force not set, hint that it might be appropriate to * register the node as a standby rather than unregister as master */ - if (!runtime_options.force) + else if (!runtime_options.force) { - log_error(_("node %s (id: %i) is a standby, unable to unregister"), + log_error(_("node %s (id: %i) is running as a standby, unable to unregister"), target_node_info_ptr->node_name, target_node_info_ptr->node_id); log_hint(_("the node can be registered as a standby with \"repmgr standby register --force\"")); log_hint(_("use \"repmgr master unregister --force\" to remove this node's metadata entirely")); + can_unregister = false; + } + + if (can_unregister == false) + { PQfinish(target_node_conn); PQfinish(master_conn); exit(ERR_BAD_CONFIG); @@ -423,7 +439,7 @@ do_master_unregister(void) target_node_info_ptr->node_name, target_node_info_ptr->node_id); - if (master_node_info.active == true) + if (master_node_info.active == false) { log_hint(_("node is marked as inactive, activate with \"repmgr master register --force\"")); }