mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
"primary register": ensure --force works if another primary is registered but not running
This commit is contained in:
@@ -48,9 +48,10 @@
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
&repmgr;: when executing <link linkend="repmgr-standby-clone"><command>repmgr standby clone</command></link>
|
||||
in <option>--dry-run</option> mode, ensure provision of the <option>--force</option> option
|
||||
does not result in an existing data directory being modified in any way.
|
||||
&repmgr;: when executing <link linkend="repmgr-primary-register"><command>repmgr primary register</command></link>
|
||||
with the <option>--force</option> option, if another primary record exists but the associated node is
|
||||
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>
|
||||
</listitem>
|
||||
|
||||
|
||||
@@ -96,28 +96,6 @@ do_primary_register(void)
|
||||
|
||||
initialize_voting_term(conn);
|
||||
|
||||
/* Ensure there isn't another registered node which is primary */
|
||||
primary_conn = get_primary_connection(conn, ¤t_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);
|
||||
|
||||
/*
|
||||
@@ -128,12 +106,32 @@ do_primary_register(void)
|
||||
current_primary_id = get_primary_node_id(conn);
|
||||
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_detail(_("a streaming replication cluster can have only one primary node"));
|
||||
log_debug("XXX %i", current_primary_id);
|
||||
primary_conn = establish_primary_db_connection(conn, false);
|
||||
|
||||
rollback_transaction(conn);
|
||||
PQfinish(conn);
|
||||
exit(ERR_BAD_CONFIG);
|
||||
if (PQstatus(primary_conn) == CONNECTION_OK)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user