u70b3 commented on code in PR #203:
URL: https://github.com/apache/paimon-cpp/pull/203#discussion_r3802032730
##########
src/paimon/common/factories/io_hook_test.cpp:
##########
@@ -64,4 +68,49 @@ TEST(IOHookTest, TestThrowExceptionMode) {
hook->Clear();
}
+// Regression test for the data race on IOHook's mode: Reset()/Clear() run on
one
+// thread while other threads call Try() concurrently. Under a ThreadSanitizer
build
+// this deterministically reports the unsynchronized mode access; functionally
it must
+// never crash and every Try() must return OK.
+TEST(IOHookTest, TestConcurrentResetAndTry) {
+ auto hook = IOHook::GetInstance();
+
+ constexpr int32_t kResetIterations = 200000;
+ constexpr int32_t kTryIterations = 50000;
+ constexpr int32_t kNumWorkers = 4;
+
+ std::atomic<bool> observed_error{false};
+
+ std::thread reset_thread([hook]() {
Review Comment:
Agreed — same class of hazard: with the reset thread free-running 200k fixed
iterations before the workers were even spawned, a loaded CI runner or a
TSan-slowed build could serialize the two sides completely, and since every
iteration ends in `Clear()` the workers would then only ever see SILENT — a
silent no-op masquerading as a concurrency gate. A test that can pass with zero
overlap does not just miss the torn-state bug, it masks it behind false
confidence.
Fixed structurally:
- All five threads now block on a shared start barrier and are released
together.
- The reset loop has no fixed iteration count: it hammers `Reset(INT64_MAX,
RETURN_ERROR)` / `Clear()` until every worker has completed all its `Try()`
iterations (a `workers_done` counter), so overlap covers the workers' entire
lifetime by construction.
- Side benefit: the fixed 200k-iteration cost is gone, so the test is faster
under TSan while being strictly stronger (~120ms in Debug).
Validation on Kunpeng-920 (aarch64), latest head (1bc6650): 20× shuffled
stress runs of this test plus the singleton storm under TSan — zero reports;
Debug suite green under 20× `--gtest_shuffle` and `--gtest_repeat=5
--gtest_shuffle`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]