Skip to content

Commit bd061ef

Browse files
ashutosh-bapatCommitfest Bot
authored andcommitted
Additional validation for buffer in the ring
If the buffer pool has been shrunk, the buffers in the buffer list may not be valid anymore. Modify GetBufferFromRing to check if the buffer is still valid before using it. This makes GetBufferFromRing() a bit more expensive because of additional boolean condition. That may not be expensive enough to affect query performance. The alternative to that is more complex as explained below. The strategy object is created in CurrentMemoryContext and is not available in any global structure thus accessible when processing buffer resizing barriers. We may modify GetAccessStrategy() to register strategy in a global linked list and then arrange to deregister it once it's no more in use. Looking at the places which use GetAccessStrategy(), fixing all those may be some work. Ashutosh Bapat
1 parent 3afe31b commit bd061ef

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/backend/storage/buffer/freelist.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,12 +948,13 @@ GetBufferFromRing(BufferAccessStrategy strategy, uint32 *buf_state)
948948
strategy->current = 0;
949949

950950
/*
951-
* If the slot hasn't been filled yet, tell the caller to allocate a new
952-
* buffer with the normal allocation strategy. He will then fill this
953-
* slot by calling AddBufferToRing with the new buffer.
951+
* If the slot hasn't been filled yet or the buffer in the slot has been
952+
* invalidated when buffer pool was shrunk, tell the caller to allocate a new
953+
* buffer with the normal allocation strategy. He will then fill this slot
954+
* by calling AddBufferToRing with the new buffer.
954955
*/
955956
bufnum = strategy->buffers[strategy->current];
956-
if (bufnum == InvalidBuffer)
957+
if (bufnum == InvalidBuffer || bufnum > NBuffers)
957958
return NULL;
958959

959960
/*

0 commit comments

Comments
 (0)