From 1a790549eaca067f83d5afec8704f1dca7ea83ca Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 13 Jan 2015 13:40:47 +0900 Subject: [PATCH] Refactor if-statement --- repmgrd.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/repmgrd.c b/repmgrd.c index c5679c0d..d29f1939 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -1154,8 +1154,16 @@ do_failover(void) } } + /* No candidate found */ + if (!find_best) + { + log_err(_("%s: No suitable candidate for promotion found; terminating.\n"), + progname); + terminate(ERR_FAILOVER_FAIL); + } + /* once we know who is the best candidate, promote it */ - if (find_best && (best_candidate.node_id == local_options.node)) + if (best_candidate.node_id == local_options.node) { // ZZZ from loop above this should never happen anyway??? // in fact do_failover is never called if rempgrd is running on a witness, @@ -1190,7 +1198,7 @@ do_failover(void) terminate(ERR_BAD_CONFIG); } } - else if (find_best) + else { /* wait */ sleep(10); @@ -1217,12 +1225,6 @@ do_failover(void) terminate(ERR_BAD_CONFIG); } } - else - { - log_err(_("%s: Did not find candidates. You should check and try manually.\n"), - progname); - terminate(ERR_FAILOVER_FAIL); - } log_debug("failover done\n"); /* to force it to re-calculate mode and master node */