Check for existing master record before deleting it

Otherwise repmgr implies it's deleting a record which isn't actually
there.
This commit is contained in:
Ian Barwick
2015-09-24 17:39:39 +09:00
parent 43874d5576
commit 8e7d110a22
4 changed files with 41 additions and 21 deletions

View File

@@ -753,28 +753,38 @@ do_master_register(void)
exit(ERR_BAD_CONFIG);
}
PQfinish(master_conn);
/* XXX we should check if a node with a different ID is registered as
master, otherwise it would be possible to insert a duplicate record
with --force, which would result in an unwelcome "multi-master" situation
*/
PQfinish(master_conn);
/* Delete any existing record for this node if --force set */
if (runtime_options.force)
{
PGresult *res;
bool node_record_deleted;
log_notice(_("deleting existing master record with id %i\n"), options.node);
begin_transaction(conn);
node_record_deleted = delete_node_record(conn,
options.node,
"master register");
if (node_record_deleted == false)
res = get_node_record(conn, options.cluster_name, options.node);
if (PQntuples(res))
{
PQfinish(conn);
exit(ERR_BAD_CONFIG);
log_notice(_("deleting existing master record with id %i\n"), options.node);
node_record_deleted = delete_node_record(conn,
options.node,
"master register");
if (node_record_deleted == false)
{
rollback_transaction(conn);
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
}
commit_transaction(conn);
}