aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/buffer/localbuf.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2025-03-15 12:30:07 -0400
committerAndres Freund <andres@anarazel.de>2025-03-15 22:07:48 -0400
commitdd6f2618f681e699cb5f2122a3f036beaa89f992 (patch)
tree2349ca577965fe2ec074c0eb86aeb4861612adde /src/backend/storage/buffer/localbuf.c
parent0762a151b0e018944694ccac07e521adcdf7a06f (diff)
downloadpostgresql-dd6f2618f681e699cb5f2122a3f036beaa89f992.tar.gz
postgresql-dd6f2618f681e699cb5f2122a3f036beaa89f992.zip
localbuf: Introduce TerminateLocalBufferIO()
Previously TerminateLocalBufferIO() was open-coded in multiple places, which doesn't seem like a great idea. While TerminateLocalBufferIO() currently is rather simple, an upcoming patch requires additional code to be added to TerminateLocalBufferIO(), making this modification particularly worthwhile. For some reason FlushRelationBuffers() previously cleared BM_JUST_DIRTIED, even though that's never set for temporary buffers. This is not carried over as part of this change. Reviewed-by: Melanie Plageman <melanieplageman@gmail.com> Discussion: https://postgr.es/m/CAAKRu_b9anbWzEs5AAF9WCvcEVmgz-1AkHSQ-CLLy-p7WHzvFw@mail.gmail.com
Diffstat (limited to 'src/backend/storage/buffer/localbuf.c')
-rw-r--r--src/backend/storage/buffer/localbuf.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index 5331091132d..86b1c4c7c68 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -235,7 +235,6 @@ GetLocalVictimBuffer(void)
*/
if (pg_atomic_read_u32(&bufHdr->state) & BM_DIRTY)
{
- uint32 buf_state = pg_atomic_read_u32(&bufHdr->state);
instr_time io_start;
SMgrRelation oreln;
Page localpage = (char *) LocalBufHdrGetBlock(bufHdr);
@@ -259,8 +258,7 @@ GetLocalVictimBuffer(void)
IOOP_WRITE, io_start, 1, BLCKSZ);
/* Mark not-dirty now in case we error out below */
- buf_state &= ~BM_DIRTY;
- pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
+ TerminateLocalBufferIO(bufHdr, true, 0);
pgBufferUsage.local_blks_written++;
}
@@ -484,6 +482,31 @@ MarkLocalBufferDirty(Buffer buffer)
}
/*
+ * Like TerminateBufferIO, but for local buffers
+ */
+void
+TerminateLocalBufferIO(BufferDesc *bufHdr, bool clear_dirty, uint32 set_flag_bits)
+{
+ /* Only need to adjust flags */
+ uint32 buf_state = pg_atomic_read_u32(&bufHdr->state);
+
+ /* BM_IO_IN_PROGRESS isn't currently used for local buffers */
+
+ /* Clear earlier errors, if this IO failed, it'll be marked again */
+ buf_state &= ~BM_IO_ERROR;
+
+ if (clear_dirty)
+ buf_state &= ~BM_DIRTY;
+
+ buf_state |= set_flag_bits;
+ pg_atomic_unlocked_write_u32(&bufHdr->state, buf_state);
+
+ /* local buffers don't track IO using resowners */
+
+ /* local buffers don't use the IO CV, as no other process can see buffer */
+}
+
+/*
* InvalidateLocalBuffer -- mark a local buffer invalid.
*
* If check_unreferenced is true, error out if the buffer is still