mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
Ensure 'master register --force' can't create more than one active primary node record
This commit is contained in:
26
repmgr.c
26
repmgr.c
@@ -793,6 +793,8 @@ do_master_register(void)
|
|||||||
bool schema_exists = false;
|
bool schema_exists = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
int primary_node_id = UNKNOWN_NODE_ID;
|
||||||
|
|
||||||
bool record_created;
|
bool record_created;
|
||||||
|
|
||||||
conn = establish_db_connection(options.conninfo, true);
|
conn = establish_db_connection(options.conninfo, true);
|
||||||
@@ -849,19 +851,29 @@ do_master_register(void)
|
|||||||
|
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
|
|
||||||
/* XXX we should check if a node with a different ID is registered as
|
begin_transaction(conn);
|
||||||
master, otherwise it would be possible to insert a duplicate record
|
|
||||||
with --force, which would result in an unwelcome "multi-master" situation
|
/*
|
||||||
|
* Check if a node with a different ID is registered as primary. This shouldn't
|
||||||
|
* happen but could do if an existing master was shut down without being
|
||||||
|
* unregistered.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
primary_node_id = get_master_node_id(conn, options.cluster_name);
|
||||||
|
if (primary_node_id != NODE_NOT_FOUND && primary_node_id != options.node)
|
||||||
|
{
|
||||||
|
log_err(_("another node with id %i is already registered as master\n"), primary_node_id);
|
||||||
|
rollback_transaction(conn);
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
/* Delete any existing record for this node if --force set */
|
/* Delete any existing record for this node if --force set */
|
||||||
if (runtime_options.force)
|
if (runtime_options.force)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
bool node_record_deleted;
|
bool node_record_deleted;
|
||||||
|
|
||||||
begin_transaction(conn);
|
|
||||||
|
|
||||||
res = get_node_record(conn, options.cluster_name, options.node);
|
res = get_node_record(conn, options.cluster_name, options.node);
|
||||||
if (PQntuples(res))
|
if (PQntuples(res))
|
||||||
{
|
{
|
||||||
@@ -878,7 +890,6 @@ do_master_register(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commit_transaction(conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -896,10 +907,13 @@ do_master_register(void)
|
|||||||
|
|
||||||
if (record_created == false)
|
if (record_created == false)
|
||||||
{
|
{
|
||||||
|
rollback_transaction(conn);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(ERR_DB_QUERY);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commit_transaction(conn);
|
||||||
|
|
||||||
/* Log the event */
|
/* Log the event */
|
||||||
create_event_record(conn,
|
create_event_record(conn,
|
||||||
&options,
|
&options,
|
||||||
|
|||||||
Reference in New Issue
Block a user