fix: remove own node earlier if force is set

We have to remove our own node before we check for a new master if force
is set; else master register would fail on the second time since there
already is a master (ourselves), even if we specify -F
This commit is contained in:
Christian Kruse
2014-01-07 14:16:58 +01:00
parent 9e2f276fcf
commit a97065113d

View File

@@ -565,18 +565,6 @@ do_master_register(void)
PGconn *master_conn; PGconn *master_conn;
int id; int id;
/* Ensure there isn't any other master already registered */
master_conn = getMasterConnection(conn, repmgr_schema,
options.cluster_name, &id,NULL);
if (master_conn != NULL)
{
PQfinish(master_conn);
log_warning(_("There is a master already in cluster %s\n"), options.cluster_name);
exit(ERR_BAD_CONFIG);
}
}
/* Now register the master */
if (runtime_options.force) if (runtime_options.force)
{ {
sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_nodes " sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_nodes "
@@ -593,6 +581,19 @@ do_master_register(void)
} }
} }
/* Ensure there isn't any other master already registered */
master_conn = getMasterConnection(conn, repmgr_schema,
options.cluster_name, &id,NULL);
if (master_conn != NULL)
{
PQfinish(master_conn);
log_warning(_("There is a master already in cluster %s\n"), options.cluster_name);
exit(ERR_BAD_CONFIG);
}
}
/* Now register the master */
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes (id, cluster, name, conninfo, priority) " sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes (id, cluster, name, conninfo, priority) "
"VALUES (%d, '%s', '%s', '%s', %d)", "VALUES (%d, '%s', '%s', '%s', %d)",
repmgr_schema, options.node, options.cluster_name, options.node_name, repmgr_schema, options.node, options.cluster_name, options.node_name,