-
Notifications
You must be signed in to change notification settings - Fork 22
fix(build): repair singleton double-checked locking race and harden aarch64 portability #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
566965f
fix: repair Singleton double-checked locking race and harden aarch64 …
u70b3 1621270
fix(common): address portability review feedback
u70b3 6e18c75
test(common): make concurrency regression gates structurally sound
u70b3 890fad4
perf(common): gate IOHook shared_mutex behind armed flag
u70b3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The race fix itself is welcome — Reset()/Clear() and Try() were genuinely racy before. My concern is where the lock landed: Try() is invoked by CHECK_HOOK on every local-file IO (in local_file.cpp, hook_ is always initialized to IOHook::GetInstance(), so the guard never skips it). The old implementation was lock-free (fetch_add + an atomic pos_ load); the new one takes a std::shared_mutex shared lock on every IO.
Suggested fix: gate the lock behind an "armed" flag. The hook is never armed in production — the default state is exactly what Clear() sets up (pos_ = -1, SILENT), and writers only exist in tests. So we can keep the mutex for correctness on the armed path while restoring a lock-free fast path for the disabled state:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point — done in 993b2d5 by gating the synchronized path behind an atomic
armedflag:Try()now starts with a lock-free fast path: a single acquire load, returning OK immediately in the disabled state (the production default). Theshared_mutexis only taken once armed.Reset()publishes the complete configuration under the mutex and then release-storesarmed; armed readers acquire the mutex before touchingmode_/pos_, so an observed armed state always implies a complete configuration.Clear()disarms first (still under the mutex) so IO threads drop off the lock as soon as possible.IOCount()now counts only while armed. AllIOCount()consumers are tests, and the header documents the contract.IOHookTest.TestDisabledFastPathpins the disabled behavior (Try always OK, no counting, re-arm/disarm restores it). The existingTestConcurrentResetAndTryhammersReset(INT64_MAX, RETURN_ERROR)/Clear()continuously, so workers keep switching between the fast and armed paths under TSan.Validation on Kunpeng-920 (aarch64), head 993b2d5: factories suite 10/10 (plus 20×
--gtest_shuffleand a--gtest_repeat=5 --gtest_shufflerun);paimon-common-test1450/1450;paimon-common-sst-file-format-test32/32; TSan clean over 20 shuffled stress runs of the race tests; pre-commit andgit diff --checkclean.