]> granicus.if.org Git - postgresql/commitdiff
Fix RBM_ZERO_AND_LOCK mode to not acquire lock on local buffers.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 13 May 2015 06:44:43 +0000 (09:44 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 13 May 2015 07:06:38 +0000 (10:06 +0300)
Commit 81c45081 introduced a new RBM_ZERO_AND_LOCK mode to ReadBuffer, which
takes a lock on the buffer before zeroing it. However, you cannot take a
lock on a local buffer, and you got a segfault instead. The version of that
patch committed to master included a check for !isLocalBuf, and therefore
didn't crash, but oddly I missed that in the back-patched versions. This
patch adds that check to the back-branches too.

RBM_ZERO_AND_LOCK mode is only used during WAL replay, and in hash indexes.
WAL replay only deals with shared buffers, so the only way to trigger the
bug is with a temporary hash index.

Reported by Artem Ignatyev, analysis by Tom Lane.

src/backend/storage/buffer/bufmgr.c

index 386c585320e816954d9f8d6581e50360419fa7ad..f684e3390076f55748d30b26b52d0f8a2760a02f 100644 (file)
@@ -483,7 +483,8 @@ ReadBuffer_common(SMgrRelation smgr, bool isLocalBuf, ForkNumber forkNum,
         * (Note that we cannot use LockBuffer() of LockBufferForCleanup() here,
         * because they assert that the buffer is already valid.)
         */
-       if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
+       if ((mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK) &&
+               !isLocalBuf)
                LWLockAcquire(bufHdr->content_lock, LW_EXCLUSIVE);
 
        if (isLocalBuf)