diff options
author | Tomas Vondra | 2016-11-09 15:19:59 +0000 |
---|---|---|
committer | Tomas Vondra | 2016-11-09 15:19:59 +0000 |
commit | 4b905e900a2a1ccc9fd15e32b77839d01dffad75 (patch) | |
tree | fd6dfc5b5c7091272f3acb407bdb70d9f4c1f0d0 | |
parent | 29cbb9fdc33b7d346b2d66351782b42f5c4c3b8a (diff) |
allocate SQueue LWLocks using a named tranche (dynamically)
LWLockAssign() got removed so this is the only way to do this.
In any case, once we switch to the built-in shared queues, this should
not be needed at all I believe.
-rw-r--r-- | src/backend/pgxc/squeue/squeue.c | 23 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lwlock.c | 5 | ||||
-rw-r--r-- | src/include/storage/lwlock.h | 3 |
3 files changed, 21 insertions, 10 deletions
diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c index a938571147..fdc67551fb 100644 --- a/src/backend/pgxc/squeue/squeue.c +++ b/src/backend/pgxc/squeue/squeue.c @@ -45,7 +45,7 @@ int SQueueSize = 64; typedef struct ConsumerSync { - LWLockId cs_lwlock; /* Synchronize access to the consumer queue */ + LWLock *cs_lwlock; /* Synchronize access to the consumer queue */ Latch cs_latch; /* The latch consumer is waiting on */ } ConsumerSync; @@ -119,7 +119,7 @@ typedef struct SQueueHeader * is SharedQueue */ static HTAB *SharedQueues = NULL; - +static LWLockPadded *SQueueLocks = NULL; /* * Pool of synchronization items @@ -222,8 +222,23 @@ SharedQueuesInit(void) &found); if (!found) { - int i; + int i, l; + int nlocks = (NUM_SQUEUES * (MaxDataNodes-1)); + LWLockTranche tranche; + + /* Initialize LWLocks for queues */ + SQueueLocks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nlocks); + + tranche.name = "Shared Queue Locks"; + tranche.array_base = SQueueLocks; + tranche.array_stride = sizeof(LWLockPadded); + + /* Register the trannche tranche in the main tranches array */ + LWLockRegisterTranche(LWTRANCHE_SHARED_QUEUES, &tranche); + + Assert(SQueueLocks == GetNamedLWLockTranche("Shared Queue Locks")); + l = 0; for (i = 0; i < NUM_SQUEUES; i++) { SQueueSync *sqs = GET_SQUEUE_SYNC(i); @@ -234,7 +249,7 @@ SharedQueuesInit(void) for (j = 0; j < MaxDataNodes-1; j++) { InitSharedLatch(&sqs->sqs_consumer_sync[j].cs_latch); - sqs->sqs_consumer_sync[j].cs_lwlock = LWLockAssign(); + sqs->sqs_consumer_sync[j].cs_lwlock = &(SQueueLocks[l++]).lock; } } } diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 2199cf43c8..950ea74649 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -372,11 +372,6 @@ NumLWLocksByNamedTranches(void) int numLocks = 0; int i; -#ifdef XCP - /* squeue.c needs one per consumer node in each shared queue. - * Max number of consumers is MaxDataNodes-1 */ - numLocks += NUM_SQUEUES * (MaxDataNodes-1); -#endif for (i = 0; i < NamedLWLockTrancheRequests; i++) numLocks += NamedLWLockTrancheRequestArray[i].num_lwlocks; diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index e41a3ae0db..42a5bf7c26 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -235,7 +235,8 @@ typedef enum BuiltinTrancheIds LWTRANCHE_BUFFER_MAPPING, LWTRANCHE_LOCK_MANAGER, LWTRANCHE_PREDICATE_LOCK_MANAGER, - LWTRANCHE_FIRST_USER_DEFINED + LWTRANCHE_FIRST_USER_DEFINED, + LWTRANCHE_SHARED_QUEUES } BuiltinTrancheIds; /* |