mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 00:46:29 +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;
|
PGresult *res;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
begin_transaction(witnessconn);
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", get_repmgr_schema_quoted(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);
|
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",
|
log_err("Unable to retrieve node records from master:\n%s\n",
|
||||||
PQerrorMessage(masterconn));
|
PQerrorMessage(masterconn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
rollback_transaction(witnessconn);
|
||||||
|
|
||||||
return false;
|
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",
|
log_err("Unable to copy node record to witness database\n%s\n",
|
||||||
PQerrorMessage(witnessconn));
|
PQerrorMessage(witnessconn));
|
||||||
|
rollback_transaction(witnessconn);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
|
commit_transaction(witnessconn);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user