Fix buffer stage size accounting race - #5481
Draft
simonyang08 wants to merge 1 commit into
Draft
Conversation
Signed-off-by: simonyang08 <ppt5928@gmail.com>
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.
Which issue(s) this PR fixes:
Fixes #5479
What this PR does / why we need it:
Buffer#writepreviously deferred the staged-byte metric update until after releasing every chunk lock. A concurrentenqueue_chunkcould remove the staged chunk and subtract its committed size before the matching addition, making the rawstage_sizegauge transiently negative.This change records committed staged bytes before releasing each chunk monitor. It deliberately does not acquire the Buffer-global lock in that position, preserving the existing lock-order constraint. A deterministic regression test pauses the writer at
mon_exitand verifies that the staged bytes transfer to the queue without a negative intermediate gauge.Docs Changes:
None.
Release Note:
Fix a race that could make the internal buffer
stage_sizegauge transiently negative while a write and chunk enqueue overlap.Validation:
bundle exec ruby -Itest test/plugin/test_stage_size_race.rb- 1 test, 5 assertions, passedbundle exec ruby -Itest test/plugin/test_buffer.rb- 73 tests, 431 assertions, passedgit diff --check- passedbundle exec rake testwas also attempted under WSL on/mnt/d; unrelated environment failures were observed around DrvFS permissions, CRLF shebangs, Unix sockets, and unavailable YJIT. The focused buffer suites above are green.AI assistance:
This change was prepared with OpenAI Codex assistance and reviewed and validated by the contributor.