Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 37c5516

Browse files
committed
Fix corruption of local buffer state during extend of temp relation
A typo has been introduced by 31966b1 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
1 parent 6298673 commit 37c5516

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/backend/storage/buffer/localbuf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ ExtendBufferedRelLocal(BufferManagerRelation bmr,
377377
hash_search(LocalBufHash, (void *) &tag, HASH_ENTER, &found);
378378
if (found)
379379
{
380-
BufferDesc *existing_hdr = GetLocalBufferDescriptor(hresult->id);
380+
BufferDesc *existing_hdr;
381381
uint32 buf_state;
382382

383383
UnpinLocalBuffer(BufferDescriptorGetBuffer(victim_buf_hdr));
@@ -389,7 +389,7 @@ ExtendBufferedRelLocal(BufferManagerRelation bmr,
389389
buf_state = pg_atomic_read_u32(&existing_hdr->state);
390390
Assert(buf_state & BM_TAG_VALID);
391391
Assert(!(buf_state & BM_DIRTY));
392-
buf_state &= BM_VALID;
392+
buf_state &= ~BM_VALID;
393393
pg_atomic_unlocked_write_u32(&existing_hdr->state, buf_state);
394394
}
395395
else

0 commit comments

Comments
 (0)