diff options
author | Tomas Vondra | 2017-01-09 20:52:56 +0000 |
---|---|---|
committer | Tomas Vondra | 2017-01-09 20:52:56 +0000 |
commit | 512af227199a480f74b2906ab534a07453e80c28 (patch) | |
tree | ba5e23556eca4116d3cdf5dabdc23482666b451a | |
parent | de96aa9b0a5bc3e49921c0b928e94cdcdd516013 (diff) |
fix SharedQueuesInit to register the tranche properly
The code was mixing code for named and regular tranches (identified
by just ID, in this case LWTRANCHE_SHARED_QUEUES). So switch to
the LWLockRegisterTranche() approach.
There were a two more bugs though:
1) The tranche struct was local in the block, which does not work as
it's referenced in the global array without creating a copy. So just
make it static and global.
2) The locks were not properly initialized. Add a LWLockInitialize
call to the loop.
-rw-r--r-- | src/backend/pgxc/squeue/squeue.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/backend/pgxc/squeue/squeue.c b/src/backend/pgxc/squeue/squeue.c index fdc67551fb..4fbae5b31b 100644 --- a/src/backend/pgxc/squeue/squeue.c +++ b/src/backend/pgxc/squeue/squeue.c @@ -120,6 +120,7 @@ typedef struct SQueueHeader */ static HTAB *SharedQueues = NULL; static LWLockPadded *SQueueLocks = NULL; +static LWLockTranche SharedQueueLocksTranche; /* * Pool of synchronization items @@ -224,19 +225,21 @@ SharedQueuesInit(void) { int i, l; int nlocks = (NUM_SQUEUES * (MaxDataNodes-1)); - LWLockTranche tranche; + bool foundLocks; /* Initialize LWLocks for queues */ - SQueueLocks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nlocks); + SQueueLocks = (LWLockPadded *) ShmemInitStruct("Shared Queue Locks", + sizeof(LWLockPadded) * nlocks, &foundLocks); - tranche.name = "Shared Queue Locks"; - tranche.array_base = SQueueLocks; - tranche.array_stride = sizeof(LWLockPadded); + /* either both syncs and locks, or none of them */ + Assert(! foundLocks); - /* Register the trannche tranche in the main tranches array */ - LWLockRegisterTranche(LWTRANCHE_SHARED_QUEUES, &tranche); + SharedQueueLocksTranche.name = "Shared Queue Locks"; + SharedQueueLocksTranche.array_base = SQueueLocks; + SharedQueueLocksTranche.array_stride = sizeof(LWLockPadded); - Assert(SQueueLocks == GetNamedLWLockTranche("Shared Queue Locks")); + /* Register the trannche tranche in the main tranches array */ + LWLockRegisterTranche(LWTRANCHE_SHARED_QUEUES, &SharedQueueLocksTranche); l = 0; for (i = 0; i < NUM_SQUEUES; i++) @@ -249,6 +252,10 @@ SharedQueuesInit(void) for (j = 0; j < MaxDataNodes-1; j++) { InitSharedLatch(&sqs->sqs_consumer_sync[j].cs_latch); + + LWLockInitialize(&(SQueueLocks[l]).lock, + LWTRANCHE_SHARED_QUEUES); + sqs->sqs_consumer_sync[j].cs_lwlock = &(SQueueLocks[l++]).lock; } } |