From 61f01f8305b4a3895701b0e37a6ffad9b4906d1b Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 20 Oct 2017 14:15:23 +0900 Subject: [PATCH] node rewind: add check for pg_rewind and --dry-run mode Addresses GitHub #330 --- repmgr-action-node.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 068d5c00..b03184e0 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -1676,6 +1676,45 @@ do_node_rejoin(void) exit(ERR_BAD_CONFIG); } + /* + * If --force-rewind specified, check pg_rewind can be used, and + * pre-emptively fetch the list of configuration files which should be + * archived + */ + + if (runtime_options.force_rewind == true) + { + PQExpBufferData reason; + PQExpBufferData msg; + + initPQExpBuffer(&reason); + + if (can_use_pg_rewind(upstream_conn, config_file_options.data_directory, &reason) == false) + { + log_error(_("--force-rewind specified but pg_rewind cannot be used")); + log_detail("%s", reason.data); + termPQExpBuffer(&reason); + PQfinish(upstream_conn); + + exit(ERR_BAD_CONFIG); + } + termPQExpBuffer(&reason); + + initPQExpBuffer(&msg); + appendPQExpBuffer(&msg, + _("prerequisites for using pg_rewind are met")); + + if (runtime_options.dry_run == true) + { + log_info("%s", msg.data); + } + else + { + log_verbose(LOG_INFO, "%s", msg.data); + } + termPQExpBuffer(&msg); + } + /* * Forcibly rewind node if requested (this is mainly for use when this * action is being executed by "repmgr standby switchover") @@ -1704,6 +1743,16 @@ do_node_rejoin(void) " --source-server='%s'", primary_node_record.conninfo); + if (runtime_options.dry_run == true) + { + log_info(_("pg_rewind would now be executed")); + log_detail(_("pg_rewind command is:\n %s"), + command.data); + + PQfinish(upstream_conn); + exit(SUCCESS); + } + log_notice(_("executing pg_rewind")); log_debug("pg_rewind command is:\n %s", command.data);