From 59eca2be307feb787adbf20e88a06a7056a1a8fc Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 24 Jan 2019 10:31:45 +0900 Subject: [PATCH] node rejoin: improve error code handling - return ERR_REJOIN_FAIL in all cases where the rejoin operation fails - ensure ERR_FOLLOW_FAIL is not returned - document error codes --- doc/repmgr-node-check.sgml | 2 ++ doc/repmgr-node-rejoin.sgml | 53 +++++++++++++++++++++++++++++++++++++ repmgr-action-node.c | 9 ++++--- repmgr-action-standby.c | 8 +++--- repmgr-action-standby.h | 2 +- 5 files changed, 65 insertions(+), 9 deletions(-) diff --git a/doc/repmgr-node-check.sgml b/doc/repmgr-node-check.sgml index 88f00ec6..9d85ce35 100644 --- a/doc/repmgr-node-check.sgml +++ b/doc/repmgr-node-check.sgml @@ -165,6 +165,7 @@ Following exit codes can be emitted by repmgr status check if no individual check was specified. + @@ -186,6 +187,7 @@ + diff --git a/doc/repmgr-node-rejoin.sgml b/doc/repmgr-node-rejoin.sgml index c906bd2e..30ab4c9b 100644 --- a/doc/repmgr-node-rejoin.sgml +++ b/doc/repmgr-node-rejoin.sgml @@ -255,6 +255,59 @@ + + Exit codes + + Following exit codes can be emitted by repmgr node rejoin: + + + + + + + + + The node rejoin succeeded; or if was provided, + no issues were detected which would prevent the node rejoin. + + + + + + + + + A configuration issue was detected which prevented &repmgr; from + continuing with the node rejoin. + + + + + + + + + The node could not be restarted. + + + + + + + + + The node rejoin operation failed. + + + + + + + + + + + See also diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 05a28800..7fe9b0df 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -2174,7 +2174,7 @@ do_node_rejoin(void) log_error(_("database is still running in state \"%s\""), describe_db_state(db_state)); log_hint(_("\"repmgr node rejoin\" cannot be executed on a running node")); - exit(ERR_BAD_CONFIG); + exit(ERR_REJOIN_FAIL); } /* check if cleanly shut down */ @@ -2193,7 +2193,7 @@ do_node_rejoin(void) log_detail(_("pg_rewind will not be able to run")); } log_hint(_("database should be restarted then shut down cleanly after crash recovery completes")); - exit(ERR_BAD_CONFIG); + exit(ERR_REJOIN_FAIL); } } @@ -2255,7 +2255,7 @@ do_node_rejoin(void) if (can_follow == false) { PQfinish(upstream_conn); - exit(ERR_BAD_CONFIG); + exit(ERR_REJOIN_FAIL); } } @@ -2358,7 +2358,7 @@ do_node_rejoin(void) termPQExpBuffer(&command_output); - exit(ERR_BAD_CONFIG); + exit(ERR_REJOIN_FAIL); } termPQExpBuffer(&command_output); @@ -2471,6 +2471,7 @@ do_node_rejoin(void) upstream_conn, &primary_node_record, &follow_output, + ERR_REJOIN_FAIL, &follow_error_code); if (success == false) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index eb1aee2d..83281c4d 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -2561,6 +2561,7 @@ do_standby_follow(void) follow_target_conn, &follow_target_node_record, &follow_output, + ERR_FOLLOW_FAIL, &follow_error_code); /* unable to restart the standby */ @@ -2665,7 +2666,7 @@ do_standby_follow(void) * this function. */ bool -do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int *error_code) +do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int general_error_code, int *error_code) { t_node_info local_node_record = T_NODE_INFO_INITIALIZER; int original_upstream_node_id = UNKNOWN_NODE_ID; @@ -2691,7 +2692,7 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n log_error(_("unable to retrieve record for node %i"), config_file_options.node_id); - *error_code = ERR_FOLLOW_FAIL; + *error_code = ERR_BAD_CONFIG; return false; } @@ -2818,7 +2819,7 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n if (!create_recovery_file(&local_node_record, &recovery_conninfo, config_file_options.data_directory, true)) { - *error_code = ERR_FOLLOW_FAIL; + *error_code = general_error_code; return false; } @@ -2969,7 +2970,6 @@ do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_n return false; } - appendPQExpBuffer(output, _("node %i is now attached to node %i"), config_file_options.node_id, diff --git a/repmgr-action-standby.h b/repmgr-action-standby.h index 62f11f32..eaba0871 100644 --- a/repmgr-action-standby.h +++ b/repmgr-action-standby.h @@ -28,7 +28,7 @@ extern void do_standby_switchover(void); extern void do_standby_help(void); -extern bool do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int *error_code); +extern bool do_standby_follow_internal(PGconn *primary_conn, PGconn *follow_target_conn, t_node_info *follow_target_node_record, PQExpBufferData *output, int general_error_code, int *error_code);