Repository navigation
Fix async bounded read buffer readbigat race - #112573
Conversation
readBigAt may be called concurrently from multiple threads (e.g. by ParallelReadBuffer), but it consumed the pending prefetch_future without synchronization: two threads could both pass the validity check and both call get on the same future, which is undefined behavior and aborts in practice. Now the prefetch consumption is guarded by a mutex, and prefetch publishes the file range it may cover, so that readBigAt callers whose range falls outside of it skip the lock and read directly from impl without waiting for the prefetch (readBigAt of every impl supporting it uses per-call state, independent of the sequential read path). A non-overlapping readBigAt also no longer drops the prefetch - it is left pending for a reader of the covered range. Adds a unit test reproducing the race: with a prefetch in flight, concurrent readBigAt calls used to abort with SIGABRT. Co-Authored-By: Claude Fable 5 <[email protected]>
…he submit offset The result's offset field already accounts for the page cache block alignment (see ThreadPoolRemoteFSReader::execute), so the served prefetch range always begins at the request offset and the aligned window begin only made the window over-inclusive. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [762fa93] Summary: ❌
AI ReviewSummaryThis PR serializes consumption of an in-flight prefetch in Missing context / blind spots
Final Verdict✅ No blocking findings at the current head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 241/255 (94.51%) · Uncovered code |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 75/81 (92.59%) · Uncovered code |
readBigAt now always consumes (drops) an in-flight prefetch before reading from impl, because readBigAt of impl must not run concurrently with the sequential prefetch read (e.g. ReadBufferFromHDFS shares one hdfsFile between hdfsRead and hdfsPread). Concurrent readBigAt callers race on the consumption, so it is guarded by a mutex, and an atomic flag keeps the common no-prefetch case lock-free. The previous logic serving the head of the range from the prefetched buffer (with the progress shifting for ParallelReadBuffer) is removed. Also guard the lazily initialized file_size of CachedOnDiskReadBufferFromFile with a mutex: tryGetFileSize may be called from concurrent readBigAt calls. Add a test reading through AsynchronousBoundedReadBuffer over a cached buffer concurrently with a prefetch in flight. Co-Authored-By: Claude Fable 5 <[email protected]>
Restore the logic serving readBigAt from the prefetched buffer, removed in the previous commit: dropping the prefetch unconditionally regressed the small-object object storage path (a duplicate range request on S3/Azure/HTTP after waiting for the prefetch anyway). Moreover, the consumed prefetch data is now retained in a member, so all readBigAt calls whose range starts inside it are served from it, not only the one that consumed the prefetch. The retained data is immutable once published (via the store to the atomic prefetch_pending) and is only invalidated by the sequential prefetch before it reuses the buffer. Adds a deterministic test for serving multiple reads from the retained prefetch and a counter assertion in the concurrent test. Co-Authored-By: Claude Fable 5 <[email protected]>
arsenmuk
left a comment
There was a problem hiding this comment.
all looks good to me. We discussed additional edge cases privately and decided that it's not applicable
Build profile diff (arm_release)No arm_release build profile data for commit 762fa93 - the build was skipped, reused from cache, or predates profile upload. |
`CachedReadBufferConcurrentReadBigAtWithPrefetch` passes the real file size into the `CachedOnDiskReadBufferFromFile` constructor, which pre-populates `ReadBufferFromFileBase::file_size`, so `readBigAt` never reaches the lazy `tryGetFileSize` path guarded by `file_size_mutex`. Add `CachedReadBufferConcurrentReadBigAtUnknownFileSize`, which constructs the buffer with size `0` (treated as unknown) and issues concurrent `readBigAt` calls, so the resolution of `file_size` is actually exercised. Without the fix the test fails with `std::bad_optional_access` in `CachedOnDiskReadBufferFromFile::readBigAt` (`file_size.value()` was read before `getFileSize` had initialized it). Addresses #112573 (comment)
…adbigat-race' into fix-async-bounded-read-buffer-readbigat-race
|
ClickGap analysis — checking which release branches are affected by the bug this PR fixes. ReproductionBuild unit tests from a pre-fix revision (e.g. 26.7) and run:
ninja unit_tests_dbms
./unit_tests_dbms --gtest_filter='AsynchronousBoundedReadBufferTest.concurrentReadBigAtWithPrefetch:FileCacheTest.CachedReadBufferConcurrentReadBigAtUnknownFileSize'
Observed without the fix: concurrent readBigAt calls with a prefetch in flight both call get() on the same prefetch_future -> std::future_error / SIGABRT; the file-cache test throws std::bad_optional_access from file_size.value() in CachedOnDiskReadBufferFromFile::readBigAt. No SQL-level repro: the path needs an object-storage read pipeline plus concurrent positioned reads, and the race is timing-dependent.Affected versions
Summary: reproduced on Backport the fix to cc introducing PR author: @fm4v Analysis metadata
|
Backport #112573 to 26.7: Fix async bounded read buffer readbigat race
Backport #112573 to 26.6: Fix async bounded read buffer readbigat race
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix AsynchronousBoundedReadBuffer's readBigAt data race. Closes #109678.
Version info
26.8.1.1240(included in26.8and later)26.7.4.27,26.6.3.51