[#300] Make BufferPool.get honor its timeout when allocating a buffer#301
Merged
vharseko merged 1 commit intoJul 23, 2026
Conversation
… allocating a buffer
BufferPool.get() honored its timeout budget only when claiming a buffer
that already held the wanted page. On a pool miss, allocBuffer() gave up
after a single clock sweep of 2 x bufferCount ticks and threw a raw
IllegalStateException("No available Buffers"), so concurrent sweepers
racing over a small hot pool could stochastically fail a plain read
instead of waiting.
allocBuffer() now returns null on sweep exhaustion, as its javadoc
already promised, and get() retries the whole lookup with a short sleep
outside the hash-lock stripe until the timeout budget expires, then
throws a checked InUseException per the documented contract. The claim
path and the allocation path now share a single budget measured from
get() entry.
Surfaced by TransactionTest2.transactionsWithInterrupts on a
windows-latest CI cell where a worker died with "No available Buffers"
during the interrupt storm against the 20-buffer test pool.
Fixes OpenIdentityPlatform#300
maximthomas
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BufferPool.get()honored itstimeoutbudget only on themustClaimpath (claiming a buffer that already holds the wanted page). On a pool miss,allocBuffer()performed a single clock sweep of2 × bufferCountticks and then threw a rawIllegalStateException("No available Buffers"). Sweep ticks are wasted on touched, claimed, or transiently non-detachable buffers, and the clock is shared, so concurrent sweepers race past each other's candidates — on a small hot pool a thread can stochastically burn its whole sweep and fail a plain read instead of waiting.Surfaced by
TransactionTest2.transactionsWithInterruptson awindows-latestCI cell (run 30011500179): a worker died withNo available Buffersduring the 10-second interrupt storm against the 20-buffer test pool, tripping the worker-death assertion added in #288.Fix
allocBuffer()returnsnullon sweep exhaustion — as its javadoc already promised — instead of throwing.get()retries the whole lookup with a short sleep (RETRY_SLEEP_TIME, 50 ms) until the timeout budget expires, then throws a checkedInUseException, matching the method's documented contract. The sleep happens after thefinallyhas released the hash-lock stripe, and each retry re-searches the hash table in case another thread loaded the page meanwhile.get()entry, which also removes the old unbounded-wait pathology where every outer-loopcontinuerestarted themustClaimclock.Tests
testGetHonorsTimeoutWhenPoolExhausted— with every buffer writer-claimed,get()for an absent page fails withInUseExceptionand not before its timeout expires (the old behavior — an immediateIllegalStateException— fails both assertions).testGetWaitsForReleasedBuffer— aget()blocked on an exhausted pool succeeds as soon as another thread releases a buffer, and not earlier. Pool exhaustion is only declared after two consecutive allocation failures so a transient claim by a background thread is not mistaken for exhaustion.Verified locally:
BufferPoolTest(7/7),TransactionTest2#transactionsWithInterruptsplus related (4/4, balance agrees),BufferTest,BufferTest2,BufferMaxPack,MVCCPruneBufferTest,VolumeTestall green.Fixes #300