Hi,
Commit 00d7fb5e2e39198387ae00af8dd18b787b6a4d63 adds
BufferIsExclusiveLocked and BufferIsDirty functions.
They take into account that they can also be called for temporary
tables, but they both have assert, that will always fail
for temporary tables :
***
Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
LW_EXCLUSIVE));
***

They fails because LockBuffer function just skip acquiring lock for
temporary table :
***
if (BufferIsLocal(buffer))
    return;
***

I suppose that fix can be done as in the attached to this email patch
(for REL_17_STABLE)

--
Best regards,
Daniil Davydov
From ee418040d8fb1988fdb2c79ae018e5ee9266c0e9 Mon Sep 17 00:00:00 2001
From: Daniil Davidov <davydovdaniil...@gmail.com>
Date: Thu, 5 Dec 2024 15:07:14 +0700
Subject: [PATCH] Fix isDirty and isLocked for temp tables

---
 src/backend/storage/buffer/bufmgr.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 6181673095..51e90f6d23 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -2465,11 +2465,12 @@ BufferIsExclusiveLocked(Buffer buffer)
 		int			bufid = -buffer - 1;
 
 		bufHdr = GetLocalBufferDescriptor(bufid);
+		Assert(BufferIsPinned(buffer));
+
+		return true;
 	}
-	else
-	{
-		bufHdr = GetBufferDescriptor(buffer - 1);
-	}
+
+	bufHdr = GetBufferDescriptor(buffer - 1);
 
 	Assert(BufferIsPinned(buffer));
 	return LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
@@ -2498,11 +2499,11 @@ BufferIsDirty(Buffer buffer)
 	else
 	{
 		bufHdr = GetBufferDescriptor(buffer - 1);
+		Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
+									LW_EXCLUSIVE));
 	}
 
 	Assert(BufferIsPinned(buffer));
-	Assert(LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr),
-								LW_EXCLUSIVE));
 
 	return pg_atomic_read_u32(&bufHdr->state) & BM_DIRTY;
 }
-- 
2.43.0

Reply via email to