Repository navigation
Add missing Keeper component guard to MutateFromLogEntryTask/MergeFromLogEntryTask destructors - #110664
Conversation
…mLogEntryTask destructors Both tasks hold a `zero_copy_lock` (a `ZeroCopyLock` wrapping a `zkutil::ZooKeeperLock`) while performing a replicated mutation/merge with `allow_remote_fs_zero_copy_replication` enabled. The lock is released explicitly in `prepare()`/`finalize()` on the normal paths, but if the task is destroyed while still holding the lock -- e.g. on cancellation before that explicit unlock is reached -- the implicit destructor chain (`~MutateFromLogEntryTask`/`~MergeFromLogEntryTask` -> `~ZeroCopyLock` -> `~ZooKeeperLock` -> `unlock()`) issues a real ZooKeeper request to remove the lock's ephemeral node. That destructor chain runs from `MergeTreeBackgroundExecutor::routine`'s generic task cleanup, which has no Keeper component scope set. With `enforce_keeper_component_tracking=1` (as in integration tests and debug/ sanitizer builds), the request throws `LOGICAL_ERROR: Current component is empty, please set it for your scope using Coordination::setCurrentComponent`, which aborts the server. Add an explicit destructor to each task that resets `zero_copy_lock` under a `Coordination::setCurrentComponent` guard, following the precedent of `DDLWorker::shutdown` explicitly clearing `active_node_holders` under a guard rather than putting the guard in the shared, generic `ZooKeeperLock`/`ZeroCopyLock` destructor itself. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110590&sha=5695f5662ad462d511ecdd527cbfefcd51f46a37&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 Related: #110590
|
Workflow [PR], commit [70a750e] Summary: ✅
AI ReviewSummaryThis PR adds explicit Final VerdictStatus: ✅ Approve |
|
Check this: #110670 |
`MergeTreeData::moveParts` acquires the same `ZeroCopyLock` as the replicated merge/mutate tasks, but from an unguarded scope: it calls `tryCreateZeroCopyExclusiveLock` and `waitZeroCopyLockToDisappear`, and the local `lock` releases its ephemeral node via `~ZooKeeperLock` at scope exit -- all of which issue ZooKeeper requests. Both background call sites (`scheduleDataMovingJob` and the async branch of `movePartsToSpace`) run `moveParts` through `ExecutableLambdaAdapter`, which never sets a Keeper component. So with `enforce_keeper_component_tracking=1`, zero-copy part moves still hit the `LOGICAL_ERROR` "Current component is empty" (a server abort in debug/sanitizer builds), even after the merge/mutate task destructors were guarded. Set `Coordination::setCurrentComponent` at the top of the zero-copy branch of `moveParts`, covering lock acquisition, the wait loop, and the local `lock`'s destruction. Found while reviewing #110664: #110664 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ssing-keeper-component
|
Thanks @nikitamikhaylov — #110670 is essentially the same fix: it adds guarded destructors to Two differences after the latest push here:
They are near-duplicates, so only one should land. Whichever you prefer, the ideal end state combines both: the task-destructor guards and the |
…t a Keeper component The AI review kept this PR at request-changes because nothing in-tree proved the guarded destructor path is exercised: the existing failpoints (`rmt_mutate_task_pause_in_prepare`, `rmt_merge_task_sleep_in_prepare`) fire before `tryCreateZeroCopyExclusiveLock`, so a future refactor could drop the guards and CI would stay green. Add two pauseable failpoints and a stateless test: - `rmt_mutate_task_pause_after_zero_copy_lock` pauses `MutateFromLogEntryTask::prepare` right after the zero-copy exclusive lock is acquired, so the task provably holds the lock; - `merge_tree_background_task_marked_for_deletion` pauses `MergeTreeBackgroundExecutor::removeTasksCorrespondingToStorage` right after active tasks are flagged `is_currently_deleting`, guaranteeing the resumed task takes the destruction path (cancel + destroy via the task destructor) instead of being requeued and finalized normally. The test `04603_zero_copy_lock_dtor_keeper_component` synchronizes on both failpoints, drops the table while the mutation task still holds the lock, and checks the server survives `~ZooKeeperLock` releasing the ephemeral node from the destructor (stateless runs enable `enforce_keeper_component_tracking`, so before this PR's guards that release threw the `LOGICAL_ERROR` "Current component is empty ..."). A second scope covers the sibling `MergeTreeData::moveParts` path via a synchronous `ALTER TABLE ... MOVE PART` to a zero-copy disk. The failpoints and test are adapted from #110670 by @groeneai (renumbered to 04603 because 04546 is already taken on master). Related: #110670 Co-Authored-By: Claude Fable 5 <[email protected]>
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110664&sha=7bf9c474f2de227b55fc3510d97b158c1bbc5639&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%202%2F2%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. It is a ThreadSanitizer data race in |
|
@alexey-milovidov Investigated. STID 1679-3e61 is the write side of the shared-remote-reader race in Root cause: #110154 releases The failing run here ( |
… bug Address the AI review (Request changes) on `5ea61b78`. The previous version of `04603_zero_copy_lock_dtor_keeper_component.sh` only checked server liveness, which cannot tell the fixed code from the buggy code: `~ZooKeeperLock` catches and logs `unlock` failures, and the background moves executor catches task exceptions, so a missing `Coordination::setCurrentComponent` guard logs `Current component is empty ...` instead of aborting the server. Two fixes: - Add an observable that fails when a guard is removed: after both scopes, assert `system.text_log` contains no `Current component is empty` message produced during the test. The background `DROP TABLE rmt SYNC` result is no longer discarded either (`wait` now propagates its exit status under `set -e`). - Make the part-move scope actually exercise the background `MergeTreeData::moveParts` path. A synchronous `ALTER ... MOVE PART` runs `moveParts` on the query thread under `StorageReplicatedMergeTree::alter`'s existing component scope, so it never hit the bug. Setting `alter_move_to_space_execute_async = 1` schedules the move on a background moves thread via `ExecutableLambdaAdapter` with no component set upstream, and the test waits until the part is relocated to `s3_disk` (which never happens if the guard is missing, since the background task throws first). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 29/31 (93.55%) · Uncovered code |
Checked, we should merge both. |
Master merged `04603_zero_copy_lock_dtor_keeper_component` (#110664), which collides with this PR's `04603_qbit_distance_parallel_replicas_scalar_subquery`. Renumber the two QBit tests to the next free numbers: - `04603_qbit_distance_parallel_replicas_scalar_subquery` -> `04604` - `04604_qbit_distance_parallel_replicas_constant_reference` -> `04605` Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`MergeTreeData::moveParts` acquires the same `ZeroCopyLock` as the replicated merge/mutate tasks, but from an unguarded scope: it calls `tryCreateZeroCopyExclusiveLock` and `waitZeroCopyLockToDisappear`, and the local `lock` releases its ephemeral node via `~ZooKeeperLock` at scope exit -- all of which issue ZooKeeper requests. Both background call sites (`scheduleDataMovingJob` and the async branch of `movePartsToSpace`) run `moveParts` through `ExecutableLambdaAdapter`, which never sets a Keeper component. So with `enforce_keeper_component_tracking=1`, zero-copy part moves still hit the `LOGICAL_ERROR` "Current component is empty" (a server abort in debug/sanitizer builds), even after the merge/mutate task destructors were guarded. Set `Coordination::setCurrentComponent` at the top of the zero-copy branch of `moveParts`, covering lock acquisition, the wait loop, and the local `lock`'s destruction. Found while reviewing ClickHouse#110664: ClickHouse#110664 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-missing-keeper-component Add missing Keeper component guard to MutateFromLogEntryTask/MergeFromLogEntryTask destructors
Master merged `04603_zero_copy_lock_dtor_keeper_component` (ClickHouse#110664), which collides with this PR's `04603_qbit_distance_parallel_replicas_scalar_subquery`. Renumber the two QBit tests to the next free numbers: - `04603_qbit_distance_parallel_replicas_scalar_subquery` -> `04604` - `04604_qbit_distance_parallel_replicas_constant_reference` -> `04605` Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Related: #110590
Related: #110670
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
LOGICAL_ERROR(Current component is empty, please set it for your scope using Coordination::setCurrentComponent) that could abort the server in debug/sanitizer builds (or fail underenforce_keeper_component_tracking=1) when a zero-copy exclusive lock was released outside any Keeper component scope. This happened in two sibling paths: (1) when a replicated merge or mutation task holding the lock was destroyed before its explicit unlock was reached, e.g. on cancellation, and (2) when a background zero-copy part move acquired/released the lock.MutateFromLogEntryTaskandMergeFromLogEntryTasknow release theirzero_copy_lockunder aCoordination::setCurrentComponentguard in an explicit destructor (matching the existingDDLWorker::shutdownprecedent forEphemeralNodeHolder), andMergeTreeData::movePartssets the component around its zero-copy section (tryCreateZeroCopyExclusiveLock,waitZeroCopyLockToDisappear, and the local lock's release). A deterministic regression test (04603_zero_copy_lock_dtor_keeper_component, adapted from #110670) covers both paths: two pauseable failpoints let it destroy a mutation task while it provably holds the zero-copy lock, and a synchronousALTER TABLE ... MOVE PARTto a zero-copy disk exercises themovePartspath.Found while investigating an unrelated CI failure on #110590:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110590&sha=5695f5662ad462d511ecdd527cbfefcd51f46a37&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
Documentation entry for a feature (a user-readable short description of the changes that goes into user-facing documentation.md):
N/A
Version info
26.7.1.1106(included in26.7and later)