Improve subscription locking
This avoids "tuple concurrently updated" errors when a ALTER or DROP SUBSCRIPTION writes to pg_subscription_rel at the same time as a worker. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
This commit is contained in:
parent
42794d6749
commit
cb9079cd51
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
#include "nodes/makefuncs.h"
|
#include "nodes/makefuncs.h"
|
||||||
|
|
||||||
|
#include "storage/lmgr.h"
|
||||||
|
|
||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
@ -246,6 +248,8 @@ SetSubscriptionRelState(Oid subid, Oid relid, char state,
|
|||||||
bool nulls[Natts_pg_subscription_rel];
|
bool nulls[Natts_pg_subscription_rel];
|
||||||
Datum values[Natts_pg_subscription_rel];
|
Datum values[Natts_pg_subscription_rel];
|
||||||
|
|
||||||
|
LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock);
|
||||||
|
|
||||||
rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock);
|
rel = heap_open(SubscriptionRelRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
/* Try finding existing mapping. */
|
/* Try finding existing mapping. */
|
||||||
|
@ -644,6 +644,9 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
|
|||||||
subid = HeapTupleGetOid(tup);
|
subid = HeapTupleGetOid(tup);
|
||||||
sub = GetSubscription(subid, false);
|
sub = GetSubscription(subid, false);
|
||||||
|
|
||||||
|
/* Lock the subscription so nobody else can do anything with it. */
|
||||||
|
LockSharedObject(SubscriptionRelationId, subid, 0, AccessExclusiveLock);
|
||||||
|
|
||||||
/* Form a new tuple. */
|
/* Form a new tuple. */
|
||||||
memset(values, 0, sizeof(values));
|
memset(values, 0, sizeof(values));
|
||||||
memset(nulls, false, sizeof(nulls));
|
memset(nulls, false, sizeof(nulls));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user