From cf03bc64622b22d515f18e868d1719d2240c9ffd Mon Sep 17 00:00:00 2001 From: Simon Riggs Date: Mon, 5 Oct 2009 14:52:36 +0100 Subject: [PATCH] Apply heikki1/0012-Don-t-hold-RecoveryInfoLock-over-lock-sleep.patch --- src/backend/storage/lmgr/lock.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 1e8fc2b7c8..73c3d66c15 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -567,24 +567,14 @@ LockAcquire(const LOCKTAG *locktag, } /* - * Obtain the RecoveryInfoLock if we have a lock that needs to be - * WAL logged. This ensures that we don't concurrently grab a lock - * while we are preparing GetRunningTransactionData(). - * Make sure this definition matches IsProcLockLoggable(), which - * is used to unset. + * Decide if this is the kind of lock that needs to be WAL logged. Make + * sure this definition matches IsProcLockLoggable(), which is used to + * unset. */ if (!RecoveryInProgress() && XLogArchivingActive() && lockmode >= AccessExclusiveLock && locktag->locktag_type == LOCKTAG_RELATION) { - if (dontWait) - { - /* Handle NOWAIT lock requests correctly */ - if (!LWLockConditionalAcquire(RecoveryInfoLock, LW_SHARED)) - return LOCKACQUIRE_NOT_AVAIL; - } - else - LWLockAcquire(RecoveryInfoLock, LW_SHARED); logLockrequest = true; } @@ -613,8 +603,6 @@ LockAcquire(const LOCKTAG *locktag, if (!lock) { LWLockRelease(partitionLock); - if (logLockrequest) - LWLockRelease(RecoveryInfoLock); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"), @@ -681,8 +669,6 @@ LockAcquire(const LOCKTAG *locktag, elog(PANIC, "lock table corrupted"); } LWLockRelease(partitionLock); - if (logLockrequest) - LWLockRelease(RecoveryInfoLock); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"), @@ -812,8 +798,6 @@ LockAcquire(const LOCKTAG *locktag, Assert((lock->nRequested > 0) && (lock->requested[lockmode] >= 0)); Assert(lock->nGranted <= lock->nRequested); LWLockRelease(partitionLock); - if (logLockrequest) - LWLockRelease(RecoveryInfoLock); if (locallock->nLocks == 0) RemoveLocalLock(locallock); return LOCKACQUIRE_NOT_AVAIL; @@ -878,6 +862,15 @@ LockAcquire(const LOCKTAG *locktag, XLogRecData rdata; xl_rel_lock xlrec; + /* + * Ensure that if bgwriter is just making a snapshot of locks + * and running-xacts, we won't write the WAL record until it's done. + * In case the other process didn't see our lock in the lock table yet, + * we want the XLOG_RELATION_LOCK WAL record to appear *after* the + * running-xacts record. + */ + LWLockAcquire(RecoveryInfoLock, LW_SHARED); + /* * First thing we do is ensure that a TransactionId has been * assigned to this transaction. We don't actually need the xid yet -- 2.30.2