"standby follow": initial implementation of --dry-run option

GitHub #363.
This commit is contained in:
Ian Barwick
2018-02-01 14:16:49 +09:00
parent c0a53471e1
commit c54045bcd8
3 changed files with 74 additions and 12 deletions

View File

@@ -48,6 +48,32 @@
</para>
</refsect1>
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term><option>--dry-run</option></term>
<listitem>
<para>
Check prerequisites but don't actually follow a new standby.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-W</option></term>
<term><option>--wait</option></term>
<listitem>
<para>
Wait for a primary to appear.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Event notifications</title>
<para>

View File

@@ -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("");

View File

@@ -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");
}
}