Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 74fa53c

Browse files
knizhnikkelvich
authored andcommitted
Fix race condition in MtmUnlock
1 parent 26ce1b8 commit 74fa53c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

bgwpool.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tcop/pquery.h"
1414

1515
#include "bgwpool.h"
16+
#include "multimaster.h"
1617

1718
bool MtmIsLogicalReceiver;
1819
int MtmMaxWorkers;
@@ -32,6 +33,8 @@ static void BgwPoolMainLoop(BgwPool* pool)
3233
void* work;
3334
static PortalData fakePortal;
3435

36+
MTM_ELOG(LOG, "Start background worker %d, shutdown=%d", MyProcPid, pool->shutdown);
37+
3538
MtmIsLogicalReceiver = true;
3639
MtmPool = pool;
3740

@@ -48,7 +51,7 @@ static void BgwPoolMainLoop(BgwPool* pool)
4851
while (true) {
4952
PGSemaphoreLock(&pool->available);
5053
SpinLockAcquire(&pool->lock);
51-
if (pool->shutdown) {
54+
if (pool->shutdown) {
5255
break;
5356
}
5457
size = *(int*)&pool->queue[pool->head];
@@ -83,6 +86,7 @@ static void BgwPoolMainLoop(BgwPool* pool)
8386
SpinLockRelease(&pool->lock);
8487
}
8588
SpinLockRelease(&pool->lock);
89+
MTM_ELOG(LOG, "Shutdown background worker %d", MyProcPid);
8690
}
8791

8892
void BgwPoolInit(BgwPool* pool, BgwPoolExecutor executor, char const* dbname, char const* dbuser, size_t queueSize, size_t nWorkers)

multimaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ void MtmUnlock(void)
338338
Assert(Mtm->lastLockHolder == MyProcPid);
339339
return;
340340
}
341-
LWLockRelease((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID]);
342341
Mtm->lastLockHolder = 0;
342+
LWLockRelease((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID]);
343343
}
344344

345345
void MtmLockNode(int nodeId, LWLockMode mode)

0 commit comments

Comments
 (0)