0011-bufmgr-Detect-some-missing-BufferPrepareToSetHintBit.patch
text/x-patch
Filename: 0011-bufmgr-Detect-some-missing-BufferPrepareToSetHintBit.patch
Type: text/x-patch
Part: 10
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0011
Subject: bufmgr: Detect some missing BufferPrepareToSetHintBits() calls
| File | + | − |
|---|---|---|
| src/backend/storage/buffer/bufmgr.c | 18 | 0 |
From ff2960acfb0e20efc4a0484f5f4617123a0903e2 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Mon, 28 Oct 2024 18:11:23 -0400
Subject: [PATCH 11/12] bufmgr: Detect some missing
BufferPrepareToSetHintBits() calls
Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
src/backend/storage/buffer/bufmgr.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 4080e8f9b5b..e619ebd38ff 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -5363,6 +5363,24 @@ MarkBufferDirtyHintImpl(Buffer buffer, bool buffer_std, bool single_hint_write)
/* here, either share or exclusive lock is OK */
Assert(LWLockHeldByMe(BufferDescriptorGetContentLock(bufHdr)));
+ /*
+ * A share-locked buffer may only be marked dirty for hints after having
+ * gotten the permission to do so with BufferPrepareToSetHintBits(). It'd
+ * perhaps be cheap enough to test this even outside of assert enabled
+ * builds, but LWLockHeldByMeInMode() says "debug support only".
+ */
+#ifdef USE_ASSERT_CHECKING
+ if (!single_hint_write)
+ {
+ uint32 buf_state = pg_atomic_read_u32(&bufHdr->state);
+
+ if (!LWLockHeldByMeInMode(BufferDescriptorGetContentLock(bufHdr), LW_EXCLUSIVE))
+ {
+ Assert(buf_state & BM_SETTING_HINTS);
+ }
+ }
+#endif
+
/*
* This routine might get called many times on the same page, if we are
* making the first scan after commit of an xact that added/deleted many
--
2.39.5