From 68e3a9d7ab5bcfeb01124be4340662199ed1aea2 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 14 Apr 2015 13:09:02 +0900 Subject: [PATCH] Improve promotion failure handling Exit with error; don't attempt to write event log as master connection will not be valid at this point. --- repmgr.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/repmgr.c b/repmgr.c index cb624c1b..3aeaacab 100644 --- a/repmgr.c +++ b/repmgr.c @@ -1619,42 +1619,28 @@ do_standby_promote(void) if (promote_sucess == false) { - PQExpBufferData details; - initPQExpBuffer(&details); - appendPQExpBuffer(&details, - "Node %i could not be promoted to master", - options.node); - - create_event_record(old_master_conn, - &options, - options.node, - "standby_promote", - false, - details.data); - /* XXX exit with error? */ log_err(_(retval == 1 ? "STANDBY PROMOTE failed, this is still a standby node.\n" : "connection to node lost!\n")); - } - else - { - PQExpBufferData details; - initPQExpBuffer(&details); - appendPQExpBuffer(&details, - "Node %i was successfully promoted to master", - options.node); - - log_notice(_("STANDBY PROMOTE successful. You should REINDEX any hash indexes you have.\n")); - /* Log the event */ - create_event_record(conn, - &options, - options.node, - "standby_promote", - true, - details.data); + exit(ERR_FAILOVER_FAIL); } - PQfinish(old_master_conn); + PQExpBufferData details; + initPQExpBuffer(&details); + appendPQExpBuffer(&details, + "Node %i was successfully promoted to master", + options.node); + + log_notice(_("STANDBY PROMOTE successful. You should REINDEX any hash indexes you have.\n")); + + /* Log the event */ + create_event_record(conn, + &options, + options.node, + "standby_promote", + true, + details.data); + PQfinish(conn); return;