On Sun, Jan 26, 2025 at 9:49 PM Tom Lane <t...@sss.pgh.pa.us> wrote:
> Srinath Reddy <srinath2...@gmail.com> writes: > > as suggested did the changes and attached the patch for the same. > > Uh ... what in the world is the point of changing > BufferIsExclusiveLocked's signature? > > as suggested did not change the BufferIsExclusiveLocked's signature and here's the patch for the same. Regards, Srinath Reddy Sadipiralla, EDB: https://www.enterprisedb.com <http://www.enterprisedb.com/>
From 3d232e3f5d94acd0493dce1a51a3c8d51e49a1c8 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Date: Wed, 29 Jan 2025 07:04:18 +0530 Subject: [PATCH 1/1] Handle local buffer cases properly in BufferIsExclusiveLocked and BufferIsDirty --- src/backend/storage/buffer/bufmgr.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index 0d8849bf89..23c9edfb71 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -2463,7 +2463,8 @@ ExtendBufferedRelShared(BufferManagerRelation bmr, /* * BufferIsExclusiveLocked * - * Checks if buffer is exclusive-locked. + * Checks if buffer is exclusive-locked,For local buffers we act as exclusive lock is always + * held,because we don't initialize content locks for local buffers. * * Buffer must be pinned. */ @@ -2472,20 +2473,22 @@ BufferIsExclusiveLocked(Buffer buffer) { BufferDesc *bufHdr; + Assert(BufferIsPinned(buffer)); + if (BufferIsLocal(buffer)) { int bufid = -buffer - 1; bufHdr = GetLocalBufferDescriptor(bufid); + return true; } else { bufHdr = GetBufferDescriptor(buffer - 1); - } - - Assert(BufferIsPinned(buffer)); - return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr), + return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr), LW_EXCLUSIVE); + } + } /* @@ -2501,6 +2504,8 @@ BufferIsDirty(Buffer buffer) { BufferDesc *bufHdr; + Assert(BufferIsPinned(buffer)); + if (BufferIsLocal(buffer)) { int bufid = -buffer - 1; @@ -2510,11 +2515,9 @@ BufferIsDirty(Buffer buffer) else { bufHdr = GetBufferDescriptor(buffer - 1); - } - - Assert(BufferIsPinned(buffer)); - Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr), + Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr), LW_EXCLUSIVE)); + } return pg_atomic_read_u32(&bufHdr->state) & BM_DIRTY; } -- 2.43.0