mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Prevent logical rep workers with removed subscriptions from starting.
Any logical rep workers must have their subscription entries in pg_subscription. To ensure this, we need to prevent the launcher from starting new worker corresponding to the subscription that DROP SUBSCRIPTION command is removing. To implement this, previously LogicalRepLauncherLock was introduced and held until the end of transaction running DROP SUBSCRIPTION. But using LWLock for that purpose was not valid. Instead, this commit changes DROP SUBSCRIPTION so that it takes AccessExclusiveLock on pg_subscription, in order to ensure that the launcher cannot see any subscriptions being removed. Also this commit gets rid of LogicalRepLauncherLock. Patch by me, reviewed by Petr Jelinek Discussion: https://www.postgresql.org/message-id/CAHGQGwHPi8ky-yANFfe0sgmhKtsYcQLTnKx07bW9S7-Rn1746w@mail.gmail.com
This commit is contained in:
@@ -305,17 +305,12 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid)
|
||||
/*
|
||||
* Stop the logical replication worker and wait until it detaches from the
|
||||
* slot.
|
||||
*
|
||||
* The caller must hold LogicalRepLauncherLock to ensure that new workers are
|
||||
* not being started during this function call.
|
||||
*/
|
||||
void
|
||||
logicalrep_worker_stop(Oid subid)
|
||||
{
|
||||
LogicalRepWorker *worker;
|
||||
|
||||
Assert(LWLockHeldByMe(LogicalRepLauncherLock));
|
||||
|
||||
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);
|
||||
|
||||
worker = logicalrep_worker_find(subid);
|
||||
@@ -602,9 +597,6 @@ ApplyLauncherMain(Datum main_arg)
|
||||
ALLOCSET_DEFAULT_MAXSIZE);
|
||||
oldctx = MemoryContextSwitchTo(subctx);
|
||||
|
||||
/* Block any concurrent DROP SUBSCRIPTION. */
|
||||
LWLockAcquire(LogicalRepLauncherLock, LW_EXCLUSIVE);
|
||||
|
||||
/* search for subscriptions to start or stop. */
|
||||
sublist = get_subscription_list();
|
||||
|
||||
@@ -628,8 +620,6 @@ ApplyLauncherMain(Datum main_arg)
|
||||
}
|
||||
}
|
||||
|
||||
LWLockRelease(LogicalRepLauncherLock);
|
||||
|
||||
/* Switch back to original memory context. */
|
||||
MemoryContextSwitchTo(oldctx);
|
||||
/* Clean the temporary memory. */
|
||||
|
||||
Reference in New Issue
Block a user