mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +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:
@ -461,7 +461,12 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
|
||||
if (stmt->drop_slot)
|
||||
PreventTransactionChain(isTopLevel, "DROP SUBSCRIPTION ... DROP SLOT");
|
||||
|
||||
rel = heap_open(SubscriptionRelationId, RowExclusiveLock);
|
||||
/*
|
||||
* Lock pg_subscription with AccessExclusiveLock to ensure
|
||||
* that the launcher doesn't restart new worker during dropping
|
||||
* the subscription
|
||||
*/
|
||||
rel = heap_open(SubscriptionRelationId, AccessExclusiveLock);
|
||||
|
||||
tup = SearchSysCache2(SUBSCRIPTIONNAME, MyDatabaseId,
|
||||
CStringGetDatum(stmt->subname));
|
||||
@ -528,14 +533,9 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
|
||||
/* Clean up dependencies */
|
||||
deleteSharedDependencyRecordsFor(SubscriptionRelationId, subid, 0);
|
||||
|
||||
/* Protect against launcher restarting the worker. */
|
||||
LWLockAcquire(LogicalRepLauncherLock, LW_EXCLUSIVE);
|
||||
|
||||
/* Kill the apply worker so that the slot becomes accessible. */
|
||||
logicalrep_worker_stop(subid);
|
||||
|
||||
LWLockRelease(LogicalRepLauncherLock);
|
||||
|
||||
/* Remove the origin tracking if exists. */
|
||||
snprintf(originname, sizeof(originname), "pg_%u", subid);
|
||||
originid = replorigin_by_name(originname, true);
|
||||
|
Reference in New Issue
Block a user