summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-01-05 20:10:46 +0900
committerMichael Paquier <michael@paquier.xyz>2024-01-05 20:10:46 +0900
commit37c5516633c833de6bdb57a1752a2f8e8f0d5420 (patch)
treea13048196a19987e738803a0cfe4f093105911ad
parent6298673f4b91b8b5815855785cc30f0ac390988e (diff)
Fix corruption of local buffer state during extend of temp relation
A typo has been introduced by 31966b151e6a when updating the state of a local buffer when a temporary relation is extended, for the case of a block included in the relation range extended, when it is already found in the hash table holding the local buffers. In this case, BM_VALID should be cleared, but the buffer state was changed so as BM_VALID remained while clearing the other flags. As reported on the thread, it was possible to corrupt the state of the local buffers on ENOSPC, but the states would be corrupted on any kind of ERROR during the relation extend (like partial writes or some other errno). Reported-by: Alexander Lakhin Author: Tender Wang Reviewed-by: Richard Guo, Alexander Lakhin, Michael Paquier Discussion: https://postgr.es/m/18259-6e256429825dd435@postgresql.org Backpatch-through: 16
-rw-r--r--src/backend/storage/buffer/localbuf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index 567b8d15ef0..55953c3e3e8 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -377,7 +377,7 @@ ExtendBufferedRelLocal(BufferManagerRelation bmr,
hash_search(LocalBufHash, (void *) &tag, HASH_ENTER, &found);
if (found)
{
- BufferDesc *existing_hdr = GetLocalBufferDescriptor(hresult->id);
+ BufferDesc *existing_hdr;
uint32 buf_state;
UnpinLocalBuffer(BufferDescriptorGetBuffer(victim_buf_hdr));
@@ -389,7 +389,7 @@ ExtendBufferedRelLocal(BufferManagerRelation bmr,
buf_state = pg_atomic_read_u32(&existing_hdr->state);
Assert(buf_state & BM_TAG_VALID);
Assert(!(buf_state & BM_DIRTY));
- buf_state &= BM_VALID;
+ buf_state &= ~BM_VALID;
pg_atomic_unlocked_write_u32(&existing_hdr->state, buf_state);
}
else