From c54045bcd8b1a2bef10adc76e6ac01dbc920e718 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 1 Feb 2018 14:16:49 +0900 Subject: [PATCH] "standby follow": initial implementation of --dry-run option GitHub #363. --- doc/repmgr-standby-follow.sgml | 26 +++++++++++++++++++++ repmgr-action-standby.c | 41 ++++++++++++++++++++++++++++++++++ repmgr-client.c | 19 ++++++---------- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/doc/repmgr-standby-follow.sgml b/doc/repmgr-standby-follow.sgml index 19e5cf95..2c6104ad 100644 --- a/doc/repmgr-standby-follow.sgml +++ b/doc/repmgr-standby-follow.sgml @@ -48,6 +48,32 @@ + + Options + + + + + + + Check prerequisites but don't actually follow a new standby. + + + + + + + + + + Wait for a primary to appear. + + + + + + + Event notifications diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index fe82bbc7..65bbe96f 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -1647,6 +1647,15 @@ do_standby_follow(void) exit(ERR_BAD_CONFIG); } + if (runtime_options.dry_run == true) + { + log_info(_("connected to node %i, checking for current primary"), primary_id); + } + else + { + log_verbose(LOG_INFO, _("connected to node %i, checking for current primary"), primary_id); + } + record_status = get_node_record(primary_conn, primary_id, &primary_node_record); if (record_status != RECORD_FOUND) @@ -1657,6 +1666,19 @@ do_standby_follow(void) exit(ERR_BAD_CONFIG); } + if (runtime_options.dry_run == true) + { + log_info(_("primary node is \"%s\" (ID: %i)"), + primary_node_record.node_name, + primary_id); + } + else + { + log_verbose(LOG_INFO, ("primary node is \"%s\" (ID: %i)"), + primary_node_record.node_name, + primary_id); + } + /* XXX check this is not current upstream anyway */ /* check replication connection */ initialize_conninfo_params(&repl_conninfo, false); @@ -1673,6 +1695,10 @@ do_standby_follow(void) PQfinish(primary_conn); exit(ERR_BAD_CONFIG); } + else if (runtime_options.dry_run == true) + { + log_info(_("replication connection to primary node was successful")); + } /* check system_identifiers match */ local_system_identifier = get_system_identifier(config_file_options.data_directory); @@ -1696,10 +1722,24 @@ do_standby_follow(void) PQfinish(repl_conn); exit(ERR_BAD_CONFIG); } + else if (runtime_options.dry_run == true) + { + log_info(_("local and primary system identifiers match")); + log_detail(_("system identifier is %lu"), local_system_identifier); + } + + /* TODO: check timelines*/ PQfinish(repl_conn); free_conninfo_params(&repl_conninfo); + if (runtime_options.dry_run == true) + { + log_info(_("prerequisites for executing STANDBY FOLLOW are met")); + exit(SUCCESS); + } + + initPQExpBuffer(&follow_output); success = do_standby_follow_internal(primary_conn, @@ -5426,6 +5466,7 @@ do_standby_help(void) puts(""); printf(_(" \"standby follow\" instructs a standby node to follow a new primary.\n")); puts(""); + printf(_(" --dry-run perform checks but don't actually follow the new primary\n")); printf(_(" -W, --wait wait for a primary to appear\n")); puts(""); diff --git a/repmgr-client.c b/repmgr-client.c index f8a179f9..b22c8bfd 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -1579,8 +1579,7 @@ check_cli_parameters(const int action) case NODE_STATUS: break; default: - item_list_append_format( - &cli_warnings, + item_list_append_format(&cli_warnings, _("--is-shutdown-cleanly will be ignored when executing %s"), action_name(action)); } @@ -1593,8 +1592,7 @@ check_cli_parameters(const int action) case STANDBY_SWITCHOVER: break; default: - item_list_append_format( - &cli_warnings, + item_list_append_format(&cli_warnings, _("--always-promote will be ignored when executing %s"), action_name(action)); } @@ -1608,8 +1606,7 @@ check_cli_parameters(const int action) case NODE_REJOIN: break; default: - item_list_append_format( - &cli_warnings, + item_list_append_format(&cli_warnings, _("--force-rewind will be ignored when executing %s"), action_name(action)); } @@ -1623,8 +1620,7 @@ check_cli_parameters(const int action) case NODE_REJOIN: break; default: - item_list_append_format( - &cli_warnings, + item_list_append_format(&cli_warnings, _("--config-files will be ignored when executing %s"), action_name(action)); } @@ -1638,6 +1634,7 @@ check_cli_parameters(const int action) case PRIMARY_UNREGISTER: case STANDBY_CLONE: case STANDBY_REGISTER: + case STANDBY_FOLLOW: case STANDBY_SWITCHOVER: case WITNESS_REGISTER: case WITNESS_UNREGISTER: @@ -1645,8 +1642,7 @@ check_cli_parameters(const int action) case NODE_SERVICE: break; default: - item_list_append_format( - &cli_warnings, + item_list_append_format(&cli_warnings, _("--dry-run is not effective when executing %s"), action_name(action)); } @@ -1668,8 +1664,7 @@ check_cli_parameters(const int action) if (used_options > 1) { /* TODO: list which options were used */ - item_list_append( - &cli_errors, + item_list_append(&cli_errors, "only one of --csv, --nagios and --optformat can be used"); } }