mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 00:46:29 +00:00
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:
20
dbutils.c
20
dbutils.c
@@ -1382,3 +1382,23 @@ update_node_record_set_upstream(PGconn *conn, char *cluster_name, int this_node_
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PGresult *
|
||||||
|
get_node_record(PGconn *conn, char *cluster, int node_id)
|
||||||
|
{
|
||||||
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
|
||||||
|
sprintf(sqlquery,
|
||||||
|
"SELECT id, upstream_node_id, conninfo, type, slot_name, active "
|
||||||
|
" FROM %s.repl_nodes "
|
||||||
|
" WHERE cluster = '%s' "
|
||||||
|
" AND id = %i",
|
||||||
|
get_repmgr_schema_quoted(conn),
|
||||||
|
cluster,
|
||||||
|
node_id);
|
||||||
|
|
||||||
|
log_debug("get_node_record(): %s\n", sqlquery);
|
||||||
|
|
||||||
|
return PQexec(conn, sqlquery);
|
||||||
|
}
|
||||||
|
|||||||
@@ -67,5 +67,6 @@ bool create_node_record(PGconn *conn, char *action, int node, char *type, int u
|
|||||||
bool delete_node_record(PGconn *conn, int node, char *action);
|
bool delete_node_record(PGconn *conn, int node, char *action);
|
||||||
bool create_event_record(PGconn *conn, t_configuration_options *options, int node_id, char *event, bool successful, char *details);
|
bool create_event_record(PGconn *conn, t_configuration_options *options, int node_id, char *event, bool successful, char *details);
|
||||||
bool update_node_record_set_upstream(PGconn *conn, char *cluster_name, int this_node_id, int new_upstream_node_id);
|
bool update_node_record_set_upstream(PGconn *conn, char *cluster_name, int this_node_id, int new_upstream_node_id);
|
||||||
|
PGresult * get_node_record(PGconn *conn, char *cluster, int node_id);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
28
repmgr.c
28
repmgr.c
@@ -753,28 +753,38 @@ do_master_register(void)
|
|||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PQfinish(master_conn);
|
||||||
|
|
||||||
/* XXX we should check if a node with a different ID is registered as
|
/* 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
|
master, otherwise it would be possible to insert a duplicate record
|
||||||
with --force, which would result in an unwelcome "multi-master" situation
|
with --force, which would result in an unwelcome "multi-master" situation
|
||||||
*/
|
*/
|
||||||
PQfinish(master_conn);
|
|
||||||
|
|
||||||
/* 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;
|
||||||
bool node_record_deleted;
|
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,
|
res = get_node_record(conn, options.cluster_name, options.node);
|
||||||
options.node,
|
if (PQntuples(res))
|
||||||
"master register");
|
|
||||||
|
|
||||||
if (node_record_deleted == false)
|
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
log_notice(_("deleting existing master record with id %i\n"), options.node);
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
13
repmgrd.c
13
repmgrd.c
@@ -2226,23 +2226,12 @@ check_and_create_pid_file(const char *pid_file)
|
|||||||
t_node_info
|
t_node_info
|
||||||
get_node_info(PGconn *conn, char *cluster, int node_id)
|
get_node_info(PGconn *conn, char *cluster, int node_id)
|
||||||
{
|
{
|
||||||
char sqlquery[QUERY_STR_LEN];
|
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
t_node_info node_info = { NODE_NOT_FOUND, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false};
|
t_node_info node_info = { NODE_NOT_FOUND, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false};
|
||||||
|
|
||||||
sprintf(sqlquery,
|
res = get_node_record(conn, cluster, node_id);
|
||||||
"SELECT id, upstream_node_id, conninfo, type, slot_name, active "
|
|
||||||
" FROM %s.repl_nodes "
|
|
||||||
" WHERE cluster = '%s' "
|
|
||||||
" AND id = %i",
|
|
||||||
get_repmgr_schema_quoted(conn),
|
|
||||||
local_options.cluster_name,
|
|
||||||
node_id);
|
|
||||||
|
|
||||||
log_debug("get_node_info(): %s\n", sqlquery);
|
|
||||||
|
|
||||||
res = PQexec(my_local_conn, sqlquery);
|
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
PQExpBufferData errmsg;
|
PQExpBufferData errmsg;
|
||||||
|
|||||||
Reference in New Issue
Block a user