mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
Make witness server node update an atomic operation
If the connection to the primary is lost, roll back to the previously known state. TRUNCATE is of course not MVCC-friendly, but that shouldn't matter here as only one process should ever be looking at this table.
This commit is contained in:
@@ -1125,6 +1125,8 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
||||
PGresult *res;
|
||||
int i;
|
||||
|
||||
begin_transaction(witnessconn);
|
||||
|
||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", get_repmgr_schema_quoted(witnessconn));
|
||||
|
||||
log_verbose(LOG_DEBUG, "witness_copy_node_records():\n%s\n", sqlquery);
|
||||
@@ -1149,6 +1151,8 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
||||
log_err("Unable to retrieve node records from master:\n%s\n",
|
||||
PQerrorMessage(masterconn));
|
||||
PQclear(res);
|
||||
rollback_transaction(witnessconn);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1186,11 +1190,15 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
||||
|
||||
log_err("Unable to copy node record to witness database\n%s\n",
|
||||
PQerrorMessage(witnessconn));
|
||||
rollback_transaction(witnessconn);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
commit_transaction(witnessconn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user