Repository navigation
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-7:20260716-101500 |
|
cc @alexey-milovidov @antonio2368 could you review? One-line guard setting the Keeper component in |
|
Workflow [PR], commit [9f30d43] Summary: ❌
AI ReviewSummaryThis PR’s code fix has already landed on Findings
Final Verdict
|
|
@groeneai ZooKeeperLock is too low level for component name. |
A replicated zero-copy merge/mutate task owns the zero-copy exclusive lock via its std::optional<ZeroCopyLock> member. When the task is torn down on a MergeTreeBackgroundExecutor thread while the lock is still held, ~ZooKeeperLock issues Keeper requests (exists/remove) to release the ephemeral node. That teardown runs outside any component scope, so with enforce_keeper_component_tracking enabled the server aborts with "Current component is empty, please set it for your scope using Coordination::setCurrentComponent". The Keeper component is set at the highest level that owns the section doing those ZooKeeper requests: the MutateFromLogEntryTask / MergeFromLogEntryTask destructors. Each explicitly releases zero_copy_lock inside the guarded scope, because the member would otherwise be destroyed after the destructor body, outside the guard. Regression test 04546 pauses a mutation task on a new failpoint fired right after tryCreateZeroCopyExclusiveLock() succeeds, so the task provably holds the lock, then drops the table so the task is destroyed with the lock still held. Related: ClickHouse#110590
a831f7a to
9aa5044
Compare
|
Reworked per review. Component placement (@antonio2368): moved the Keeper component out of the low-level Test sync: the test now enables a new failpoint Verified in both directions locally (embedded Keeper, s3_cache zero-copy,
|
The test synced on the DROP TABLE query appearing in system.processes to assert the mutation task is torn down while holding the zero-copy lock. That does not establish the condition: the task is flagged is_currently_deleting only later, in MergeTreeBackgroundExecutor::removeTasksCorrespondingToStorage (driven by partialShutdown -> background_operations_assignee.finish). If the after-zero-copy-lock failpoint is released before that, the task is requeued and finalized normally, releasing the lock under executeStep's component scope instead of through ~MutateFromLogEntryTask, so the test could pass without exercising the fixed teardown path. Add a pauseable failpoint merge_tree_background_task_marked_for_deletion that fires right after the task is flagged is_currently_deleting (outside the executor mutex, only when a task is actually being deleted). The test now waits on it before resuming, guaranteeing the paused task takes the destruction path. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ove path Co-Authored-By: Claude Opus 4.8 <[email protected]>
…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]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 23/25 (92.00%) · Uncovered code |
CI finish ledger — e727021Every failure below has an owner. Only
Session id: cron:our-pr-ci-monitor:20260717-020000 |
CI finish ledger — e727021CI fully finished on this head (Finish Workflow SUCCESS; only the exempt CH Inc sync remains). All failures owned; none PR-caused (both unrelated to the ZeroCopyLock destructor component-scope fix).
Session id: cron:our-pr-ci-monitor:20260718-033000 |
|
Superseded by #110664 (merged), which lands the same fix: the The functional diff of this branch against current master is empty (only comment wording and include ordering differ), so rebasing off the current merge conflict would add no code. Leaving the close decision to the maintainers; happy to close on request. |
Conflicts were comment-only: master already contains the same component-scope fix in ~MergeFromLogEntryTask/~MutateFromLogEntryTask and in removeTasksCorrespondingToStorage, so master's wording is kept. Also dropped this branch's duplicate ZooKeeperCommon.h includes, its duplicate ~MutateFromLogEntryTask declaration, and its moveParts component guard, which shadowed master's narrower guard and broke the -Werror,-Wshadow build.
| # Let removeTasksCorrespondingToStorage proceed to wait for the (now destroyed) task, so DROP finishes. | ||
| $CLICKHOUSE_CLIENT --query "SYSTEM DISABLE FAILPOINT merge_tree_background_task_marked_for_deletion;" | ||
|
|
||
| # Do not let the (irrelevant) exit status of the background DROP abort the script under `set -e`. |
There was a problem hiding this comment.
SELECT 1 is not a discriminating observable for the destructor-scope bug anymore. zkutil::ZooKeeperLock::~ZooKeeperLock catches and only logs unlock failures (src/Common/ZooKeeper/ZooKeeperLock.cpp:36-44), so on the broken code path the server can stay up and this script still reaches the final query. Swallowing wait "$drop_pid" with || true removes the other signal from the first half as well. That means this regression can pass even when ~MutateFromLogEntryTask releases the zero-copy lock without a Keeper component. Can we keep the stronger check from 04603 here: require the background DROP to finish cleanly and assert via system.text_log that no Current component is empty message was produced after the test started?
There was a problem hiding this comment.
Agree, and I verified both halves of this.
zkutil::ZooKeeperLock::~ZooKeeperLock wraps unlock() in a try whose catch (...) only calls DB::tryLogCurrentException, so on the broken path the server stays up, and with wait "$drop_pid" || true plus a bare SELECT 1 this script has no observable that discriminates the fix from the bug. It can pass with the destructor guard removed.
The stronger form you describe is already on master, in tests/queries/0_stateless/04603_zero_copy_lock_dtor_keeper_component.sh, which merged #110664 adapted from this PR: it requires the background DROP to finish cleanly (wait "$drop_pid", no || true) and then asserts SELECT count() FROM system.text_log WHERE event_time_microseconds >= ... AND message LIKE '%Current component is empty%' is 0, with reference 1\n0 against this copy's 1\n1.
So I am not strengthening 04546. After the master merge into this branch, the entire remaining diff of this PR is 04546 plus its reference file: the two destructor guards, the MergeTreeData::moveParts guard and all three failpoints are already on master. This copy is a strictly weaker duplicate of 04603 and should be dropped rather than fixed. I noted the same conclusion on the PR on 2026-07-18 and I am leaving the close decision to the maintainers.
|
|
||
| # Second scope: the zero-copy part-move path. MergeTreeData::moveParts acquires/uses/releases a | ||
| # local ZeroCopyLock (tryCreateZeroCopyExclusiveLock does Keeper I/O), so it must run under a | ||
| # Keeper component too. A synchronous ALTER ... MOVE PART runs moveParts directly on the query |
There was a problem hiding this comment.
This ALTER TABLE ... MOVE PART is synchronous by default, so it runs under StorageReplicatedMergeTree::alter's existing component scope (src/Storages/StorageReplicatedMergeTree.cpp:6796-6800) and does not exercise the background ExecutableLambdaAdapter path that the MergeTreeData::moveParts guard was added for (src/Storages/MergeTree/MergeTreeData.cpp:11062-11070, 11185-11190). As written, the second half can pass even if the new moveParts component guard is removed. The existing 04603 variant gets this right by setting alter_move_to_space_execute_async = 1 and waiting until the part actually lands on s3_disk; this copy should do the same or be dropped instead of adding a weaker duplicate.
There was a problem hiding this comment.
Agree, and I verified the mechanism.
alter_move_to_space_execute_async defaults to false, and StorageReplicatedMergeTree::alter opens its own Coordination::setCurrentComponent("StorageReplicatedMergeTree::alter") guard at the top, so a synchronous ALTER TABLE ... MOVE PART runs moveParts on the query thread already inside a component scope. It never reaches the background ExecutableLambdaAdapter route that scheduleDataMovingJob submits to background_moves_assignee, which is the unscoped path the MergeTreeData::moveParts guard exists for. So this second half passes with that guard removed.
As with the first half, the correct version is already on master in 04603: it sets alter_move_to_space_execute_async = 1 and then polls system.parts until the part actually lands on s3_disk, so the background moves thread is genuinely exercised.
I am not going to strengthen this copy, because 04546 and its reference file are the whole remaining diff of this PR after the master merge into this branch. Every source hunk it was written for is already on master, so there is nothing here to keep and nothing to add over 04603. Dropping it means closing this PR, which I am leaving to the maintainers.
|
The
Strengthening I am also not relabelling the changelog category to make the gate green. The remaining diff is So the only useful outcome is closing this PR. I am not closing it myself since you reviewed it. @antonio2368 could you close it, or tell me to? |
|
Closed in favor #110664 |
…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 ClickHouse#110670 by @groeneai (renumbered to 04603 because 04546 is already taken on master). Related: ClickHouse#110670 Co-Authored-By: Claude Fable 5 <[email protected]>
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") that could abort the server in debug/sanitizer builds when a zero-copy replicated merge or mutation task holding a zero-copy exclusive lock was torn down by the background executor.Description
A replicated zero-copy merge/mutation task owns the zero-copy exclusive lock via its
std::optional<ZeroCopyLock>member. When such a task is torn down on aMergeTreeBackgroundExecutorthread while the lock is still held,~ZooKeeperLockissues ZooKeeper requests (exists/remove) to release the ephemeral node. That teardown runs outside any Keeper component scope, so withenforce_keeper_component_trackingenabledZooKeeper::pushRequestthrowsCurrent component is empty, please set it for your scope using Coordination::setCurrentComponent(a server abort in debug/sanitizer builds). Reported on #110590 (amd_debug flaky check).The Keeper component is set at the highest level that owns the section doing those ZooKeeper requests: the
MutateFromLogEntryTaskandMergeFromLogEntryTaskdestructors. Each sets the component and then releaseszero_copy_lockexplicitly inside that scope, because the member would otherwise be destroyed after the destructor body, outside the guard. Both task types own astd::optional<ZeroCopyLock>, so both are covered.Observed stack (baseline, before the fix):
Added a stateless regression test (
04546_zero_copy_lock_dtor_keeper_component) that pauses a mutation task on a new failpointrmt_mutate_task_pause_after_zero_copy_lockfired right aftertryCreateZeroCopyExclusiveLock()succeeds, then drops the table so the task is destroyed while it provably holds the lock. Verified locally (embedded Keeper, s3_cache zero-copy,enforce_keeper_component_tracking=1): fails with SIGABRT ("Current component is empty") without the fix, passes with it.