"primary register": ensure --force works if another primary is registered but not running

This commit is contained in:
Ian Barwick
2019-04-23 16:50:17 +09:00
parent 6cbf436bf8
commit 3129da221e
2 changed files with 29 additions and 30 deletions

View File

@@ -53,9 +53,10 @@
<listitem> <listitem>
<para> <para>
&repmgr;: when executing <link linkend="repmgr-standby-clone"><command>repmgr standby clone</command></link> &repmgr;: when executing <link linkend="repmgr-primary-register"><command>repmgr primary register</command></link>
in <option>--dry-run</option> mode, ensure provision of the <option>--force</option> option with the <option>--force</option> option, if another primary record exists but the associated node is
does not result in an existing data directory being modified in any way. unreachable (or running as a standby), set that node's record to inactive to enable the current node
to be registered as a primary.
</para> </para>
</listitem> </listitem>

View File

@@ -96,28 +96,6 @@ do_primary_register(void)
initialize_voting_term(conn); initialize_voting_term(conn);
/* Ensure there isn't another registered node which is primary */
primary_conn = get_primary_connection(conn, &current_primary_id, NULL);
if (primary_conn != NULL)
{
if (current_primary_id != config_file_options.node_id)
{
/*
* it's impossible to add a second primary to a streaming
* replication cluster
*/
log_error(_("there is already an active registered primary (node ID: %i) in this cluster"), current_primary_id);
PQfinish(primary_conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
/* we've probably connected to ourselves */
PQfinish(primary_conn);
}
begin_transaction(conn); begin_transaction(conn);
/* /*
@@ -128,12 +106,32 @@ do_primary_register(void)
current_primary_id = get_primary_node_id(conn); current_primary_id = get_primary_node_id(conn);
if (current_primary_id != NODE_NOT_FOUND && current_primary_id != config_file_options.node_id) if (current_primary_id != NODE_NOT_FOUND && current_primary_id != config_file_options.node_id)
{ {
log_error(_("another node with id %i is already registered as primary"), current_primary_id); log_debug("XXX %i", current_primary_id);
log_detail(_("a streaming replication cluster can have only one primary node")); primary_conn = establish_primary_db_connection(conn, false);
rollback_transaction(conn); if (PQstatus(primary_conn) == CONNECTION_OK)
PQfinish(conn); {
exit(ERR_BAD_CONFIG); if (get_recovery_type(primary_conn) == RECTYPE_PRIMARY)
{
log_error(_("there is already an active registered primary (node ID: %i) in this cluster"),
current_primary_id);
log_detail(_("a streaming replication cluster can have only one primary node"));
log_hint(_("ensure this node is shut down before registering a new primary"));
PQfinish(primary_conn);
rollback_transaction(conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
log_warning(_("node %is is registered as primary but running as a standby"),
current_primary_id);
PQfinish(primary_conn);
}
log_notice(_("setting node %i's node record to inactive"),
current_primary_id);
update_node_record_set_active(conn, current_primary_id, false);
} }
/* /*