Repository navigation
Install CAS decommission test callbacks before workers start - #2801
Merged
Merged
Conversation
ThreadSanitizer reported a data race in `CASDecommission.FenceLossOnAListPageStillRunsTheConfirm`. The test installs clock callbacks after `Pool::openForDecommission` has started the lease renewer. The main thread assigns the clock's `std::function` while the renewer calls the same object from `CasOperation::replace`. Owning the captured clock keeps that clock alive, but does not make replacement of the enclosing `std::function` safe. Protect the clock and request-sleep callbacks in `CasRequests` with separate `SharedMutex` instances. Callback calls take `SharedLockGuard`, and test setters take `UniqueLock`. Hold shared ownership until the callback returns, including exception unwinding, so a setter cannot replace or destroy a callable that another thread is still using. Separate mutexes allow a sleep callback to issue a request that reads the clock without acquiring the same mutex again. Keep the existing `now_ms` and `sleep_ms` call expressions. These names now refer to private methods that acquire the guards, while the stored callbacks become `now_ms_fn` and `sleep_ms_fn`. Existing request loops, hot-key handling, and `pause` therefore use the protected accessors without changes to their call sites or retry logic. Apply the same protection to `CasRefLedger::recovery_retry_sleep_fn`. Both `setCasRetrySleepForTest` and `setRefRecoveryRetrySleepForTest` replace this callback under exclusive ownership. Recovery holds shared ownership during backoff, after releasing the table's `state_mutex`. The callback guard is released before the exception path reacquires `state_mutex`, preserving the existing recovery cleanup order. Use the project's TSA-aware lock wrappers and mark all three callback fields with `TSA_GUARDED_BY`. Document that the mutexes protect callback replacement by tests while background work is running. Shared ownership still allows concurrent callback calls; captured mutable state must remain thread-safe. Fix the shared callback APIs rather than only the failing decommission call site. This also covers other tests that replace callbacks on an already open pool, while preserving the existing decommission callback selection and clock precedence. CI: https://github.com/Altinity/ClickHouse/actions/runs/41911689821 Related: #2798 Validation: `git diff --check` passed. Source review covered callback accesses, recovery exception cleanup, and existing reentrant test callbacks. Builds, tests, and a TSan rerun were not run as requested. Signed-off-by: Konstantin Morozov <[email protected]>
k-morozov
marked this pull request as ready for review
November 5, 2026 18:15
Calling the stored `std::function` does not change the `CasRequests` object. The callback mutex is already `mutable`, so shared locking works in a const method while still protecting callback replacement. Keep the callback storage non-mutable and retain the existing lock scope. CI: https://github.com/Altinity/ClickHouse/actions/runs/41911689821 Validation: `git diff --check` passed. Builds and tests were not run as requested. Signed-off-by: Konstantin Morozov <[email protected]>
The original TSan race in `CASDecommission.FenceLossOnAListPageStillRunsTheConfirm` came from replacing an admin pool's clock callback after `Pool::openForDecommission` had already started its lease renewer. The previous repair protected callback replacement and invocation with shared mutexes, adding locking to ordinary production requests as well. Use initialization order to remove that overlap. All three request planes already receive `PoolConfig::boot_ms_fn` and `PoolConfig::retry_sleep_fn` in the `Pool` constructor. Initialize the ref recovery retry callback from the same configuration before `mountWritable` can start workers, and remove the post-open admin setters from `decommissionPoolMember`. Remove the callback mutexes and their guards from `CasRequests` and `CasRefLedger`. Restore direct `std::function` calls under the existing `now_ms` and `sleep_ms` names. Callback setters require setup without concurrent callback use; they no longer support replacement during active work. Captured mutable state still needs its own synchronization. Keep the local `control_requests` setup: its callbacks are installed before the first `admit`, and the admin workers use separate engines. The admin planes now use the configured callbacks. Explicit drain callbacks fill empty configuration fields and still directly configure the local control engine. No existing caller supplies different callbacks through both channels. Make the first async completion check fatal in `CASGCTeardownStop.OpenPlaneSleepReturnsAtOnceOnceTeardownBegan`. After a timeout, the test must not continue replacing a sleep callback while the earlier async `pause` may still be running. Validation: `git diff --check` passed. Independent source reviews covered setter callers, worker startup, detached snapshot and recovery tasks, callback ownership, and timeout paths. Builds, tests, and a TSan rerun were not run as requested. CI: https://github.com/Altinity/ClickHouse/actions/runs/41911689821 Related: #2798 Signed-off-by: Konstantin Morozov <[email protected]>
filimonov
marked this pull request as ready for review
November 10, 2026 22:34
filimonov
approved these changes
Nov 10, 2026
filimonov
left a comment
Member
There was a problem hiding this comment.
Code is ok, only the comments need some improvements.
Not for this PR, a follow-up: the comments around this path now say the wrong thing.
Tools/CasDecommission.h:67-70says the drain fns "replace" the admin pool's clock and sleep. They now only fillPoolConfig::boot_ms_fn/retry_sleep_fnwhen unset; only the control engine gets them unconditionally. No caller passes both today, but the doc is wrong.Pool/CasPool.cpp:950-957says the worker pair never runs in unit tests.openForDecommissionforcesbackground_watermark, so decommission tests do run it. That is why this race looked impossible.Pool/CasPool.hsetter docs (setCasRequestNowFnForTestand friends) should say "before workers start;openForDecommissionstarts them". The fix relies on that rule.openForDecommissioncould call the existing adapterref_ledger.setCasRetrySleepForTest(config.retry_sleep_fn)(CasRefLedger.cpp:269) instead of the 8-line lambda, with a one-line note that it must precedemountWritable.- the
CasRequests.hhunk deletes the only sentence that states the rule ("test setters ... belong to setup, before any operation runs"). That sentence is what this fix depends on
filimonov
added a commit
that referenced
this pull request
Nov 10, 2026
Install CAS decommission test callbacks before workers start (cherry picked from commit 943249e) Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov
added a commit
that referenced
this pull request
Nov 10, 2026
Follow-up to #2801 (review #2801 (review)): - `decommissionPoolMember` doc: the drain fns fill `PoolConfig::boot_ms_fn` / `retry_sleep_fn` when unset and reach the pool through its config, before its renewer starts; only the control engine takes them unconditionally. - `mountWritable` comment: `openForDecommission` forces `background_watermark`, so the decommission unit tests do run the worker pair. - `Pool` test setter docs: call before the background workers start; `openForDecommission` starts them inside the open. - `openForDecommission`: reuse `CasRefLedger::setCasRetrySleepForTest` instead of an inline adapter lambda. - `CasRequests` doc: restore the sentence that the test setters write members and belong to setup. `CAS*` gtest gate (ASan): 2909 tests passed. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov
added a commit
that referenced
this pull request
Nov 11, 2026
Install CAS decommission test callbacks before workers start (cherry picked from commit 943249e) Signed-off-by: Mikhail Filimonov <[email protected]>
filimonov
added a commit
that referenced
this pull request
Nov 11, 2026
Follow-up to #2801 (review #2801 (review)): - `decommissionPoolMember` doc: the drain fns fill `PoolConfig::boot_ms_fn` / `retry_sleep_fn` when unset and reach the pool through its config, before its renewer starts; only the control engine takes them unconditionally. - `mountWritable` comment: `openForDecommission` forces `background_watermark`, so the decommission unit tests do run the worker pair. - `Pool` test setter docs: call before the background workers start; `openForDecommission` starts them inside the open. - `openForDecommission`: reuse `CasRefLedger::setCasRetrySleepForTest` instead of an inline adapter lambda. - `CasRequests` doc: restore the sentence that the test setters write members and belong to setup. `CAS*` gtest gate (ASan): 2909 tests passed. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Mikhail Filimonov <[email protected]>
7 of 31 tasks
filimonov
added a commit
to filimonov/ClickHouse
that referenced
this pull request
Nov 11, 2026
Altinity#2801 drops the post-open test clock setters in decommissionPoolMember; its CI reds are tracked elsewhere (CAS-430, CAS-440, CAS-340) or base-level. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Mikhail Filimonov <[email protected]>
Member
|
Ported to The port also applies the review #2801 (review) in 2f89c5d: comment and doc fixes around the decommission clock and sleep seams, and |
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.
TSan reported a data race in
CASDecommission.FenceLossOnAListPageStillRunsTheConfirm:decommissionPoolMemberinstalled the test clock and sleep callbacks on the admin pool afterPool::openForDecommissionhad started the lease renewer, which reads the samestd::functionobjects.Install the callbacks before any worker thread exists instead of guarding them with locks. The request planes already take
boot_ms_fnandretry_sleep_fnfromPoolConfigin thePoolconstructor, anddecommissionPoolMemberfills those fields from the drain callbacks. The ref-recovery sleep was the only seam reached solely through the post-open setter, soopenForDecommissionnow sets it fromconfig.retry_sleep_fnbeforemountWritablestarts the renewer. The post-open setter block is removed.Changes
Pool::openForDecommission: set the ref-recovery retry sleep fromconfig.retry_sleep_fnbeforemountWritable.decommissionPoolMember: drop the post-opensetCasRequestNowFnForTest/setCasRetrySleepForTestblock.gtest_cas_gc_teardown_stop.cpp:ASSERT_EQon the first pause, so the sleep setters never run while that pause may still read the callback.Risks / notes
SYSTEM CAS DROP POOL MEMBERpasses no drain callbacks, and production never setsPoolConfig::boot_ms_fn/retry_sleep_fn, so the new block is skipped there.antalya-26.8has the same post-open install inTools/CasDecommission.cpp; the code has diverged, so it needs its own patch.Testing
Unit tests (tsan)green: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2801&sha=3963b4f40ecff91f8b657adc0f820918c29e9626&name_0=PRCloses: #2798
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
...
Documentation entry for user-facing changes
...
CI/CD Options
Exclude tests:
Regression jobs to run: