mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Allow altering of two_phase option of a SUBSCRIPTION.
The two_phase option is controlled by both the publisher (as a slot option) and the subscriber (as a subscription option), so the slot option must also be modified. Changing the 'two_phase' option for a subscription from 'true' to 'false' is permitted only when there are no pending prepared transactions corresponding to that subscription. Otherwise, the changes of already prepared transactions can be replicated again along with their corresponding commit leading to duplicate data or errors. To avoid data loss, the 'two_phase' option for a subscription can only be changed from 'false' to 'true' once the initial data synchronization is completed. Therefore this is performed later by the logical replication worker. Author: Hayato Kuroda, Ajin Cherian, Amit Kapila Reviewed-by: Peter Smith, Hou Zhijie, Amit Kapila, Vitaly Davydov, Vignesh C Discussion: https://postgr.es/m/8fab8-65d74c80-1-2f28e880@39088166
This commit is contained in:
@@ -272,11 +272,14 @@ logicalrep_worker_find(Oid subid, Oid relid, bool only_running)
|
||||
* the subscription, instead of just one.
|
||||
*/
|
||||
List *
|
||||
logicalrep_workers_find(Oid subid, bool only_running)
|
||||
logicalrep_workers_find(Oid subid, bool only_running, bool acquire_lock)
|
||||
{
|
||||
int i;
|
||||
List *res = NIL;
|
||||
|
||||
if (acquire_lock)
|
||||
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
|
||||
|
||||
Assert(LWLockHeldByMe(LogicalRepWorkerLock));
|
||||
|
||||
/* Search for attached worker for a given subscription id. */
|
||||
@@ -288,6 +291,9 @@ logicalrep_workers_find(Oid subid, bool only_running)
|
||||
res = lappend(res, w);
|
||||
}
|
||||
|
||||
if (acquire_lock)
|
||||
LWLockRelease(LogicalRepWorkerLock);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -759,7 +765,7 @@ logicalrep_worker_detach(void)
|
||||
|
||||
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
|
||||
|
||||
workers = logicalrep_workers_find(MyLogicalRepWorker->subid, true);
|
||||
workers = logicalrep_workers_find(MyLogicalRepWorker->subid, true, false);
|
||||
foreach(lc, workers)
|
||||
{
|
||||
LogicalRepWorker *w = (LogicalRepWorker *) lfirst(lc);
|
||||
|
||||
Reference in New Issue
Block a user