Skip to content

Set Coordination component in PartMovesBetweenShardsOrchestrator - #101462

Merged
antonio2368 merged 4 commits into
ClickHouse:masterfrom
groeneai:fix/set-coordination-component-part-moves-orchestrator
Apr 8, 2026
Merged

antonio2368 merged 4 commits into
ClickHouse:masterfrom
groeneai:fix/set-coordination-component-part-moves-orchestrator

Conversation

@groeneai

@groeneai groeneai commented Apr 1, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix LOGICAL_ERROR crash "Current component is empty" when querying system.part_moves_between_shards with enforce_keeper_component_tracking enabled.

What this PR does

When enforce_keeper_component_tracking is enabled, all ZooKeeper requests must have a coordination component set via Coordination::setCurrentComponent(). The PartMovesBetweenShardsOrchestrator was missing these guards, causing crashes in stress tests.

Root cause: getEntries() → syncStateFromZK() → zk->getChildren() → pushRequest() throws LOGICAL_ERROR because no component is set in thread-local storage.

Trigger: Any query to system.part_moves_between_shards when a ReplicatedMergeTree table exists. The stress test 02841_not_ready_set_bug.sh does exactly this. 14+ unrelated PRs affected in CI.

Fix: Add Coordination::setCurrentComponent("PartMovesBetweenShardsOrchestrator") RAII guard at all four public entry points:

  • run() — background orchestrator thread
  • getEntries() — called from system.part_moves_between_shards
  • getEntryByUUID() — called when killing a part move
  • killPartMoveToShard() — called from KILL PART_MOVE_TO_SHARD

This follows the same pattern used in PRs #98663, #99630, #98188 to fix the same class of missing-component bugs.

Stack trace (from CI):

Coordination::ZooKeeper::pushRequest() @ ZooKeeperImpl.cpp:1414
Coordination::ZooKeeper::list() @ ZooKeeperImpl.cpp:1745
zkutil::ZooKeeper::getChildren() @ ZooKeeper.cpp:387
PartMovesBetweenShardsOrchestrator::syncStateFromZK() @ line 93
PartMovesBetweenShardsOrchestrator::getEntries() @ line 704
StorageReplicatedMergeTree::getPartMovesBetweenShardsEntries() @ line 7748
StorageSystemPartMovesBetweenShards::fillData() @ line 121

Testing

  • Reproduced crash locally with enforce_keeper_component_tracking: true
  • Fix verified: 20/20 runs pass, original test 02841_not_ready_set_bug passes 5/5
  • Added regression test 04077_part_moves_between_shards_keeper_component

Version info

  • Merged into: 26.4.1.663-master (included in 26.4 and later)
  • Backported to: 26.3.33.151

When enforce_keeper_component_tracking is enabled, ZooKeeper requests
require a coordination component to be set via setCurrentComponent().
PartMovesBetweenShardsOrchestrator's methods (run, getEntries,
getEntryByUUID, killPartMoveToShard) make ZooKeeper calls without
setting the component, causing LOGICAL_ERROR crashes with
"Current component is empty".

This was triggered by stress tests running queries against
system.part_moves_between_shards, which calls getEntries() ->
syncStateFromZK() -> zk->getChildren(). The crash affected 14+
unrelated PRs in CI.

Fix: Add Coordination::setCurrentComponent RAII guard at all four
public entry points that can trigger ZK access.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@groeneai

groeneai commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260401-064500)

a) Deterministic repro? ✅ SELECT * FROM system.part_moves_between_shards with enforce_keeper_component_tracking: true and a ReplicatedMergeTree table crashes 100% of the time without the fix.

b) Root cause? ✅ PartMovesBetweenShardsOrchestrator::getEntries() → syncStateFromZK() → zk->getChildren() → pushRequest() at ZooKeeperImpl.cpp:1414. The pushRequest checks Coordination::getCurrentComponent() in thread-local storage. When called from a user query thread (via system.part_moves_between_shards), no component has been set, so it throws LOGICAL_ERROR.

c) Fix matches root cause? ✅ Added Coordination::setCurrentComponent() RAII guards at all 4 public entry points. Same pattern as PRs #98663, #99630, #98188.

d) New tests added? ✅ 04077_part_moves_between_shards_keeper_component.sql — creates a ReplicatedMergeTree table and queries system.part_moves_between_shards (20/20 passes).

e) Demonstrated in both directions? ✅ Without fix: LOGICAL_ERROR crash on every execution. With fix: 20/20 passes, 02841_not_ready_set_bug passes 5/5.

f) Fix is general? ✅ All 4 public methods covered: run(), getEntries(), getEntryByUUID(), killPartMoveToShard().

@groeneai

groeneai commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368 @Michicosun — could you review this? This is the same class of missing setCurrentComponent bug you both fixed before (PRs #98663, #98188). PartMovesBetweenShardsOrchestrator was the remaining unfixed code path causing 14+ CI stress test crashes.

@antonio2368 antonio2368 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job putting the component guards at correct place.


PartMovesBetweenShardsOrchestrator::Entry PartMovesBetweenShardsOrchestrator::getEntryByUUID(const UUID & task_uuid)
{
auto component_guard = Coordination::setCurrentComponent("PartMovesBetweenShardsOrchestrator");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as it's covered by killPartMoveToShard.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — removed in dd3739b. getEntryByUUID is private and only called from killPartMoveToShard, so the guard there was indeed redundant.

@antonio2368 antonio2368 self-assigned this Apr 1, 2026
@antonio2368 antonio2368 added the can be tested Allows running workflows for external contributors label Apr 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [96ac68a]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_binary, 2/5) failure
test_distributed_frozen_replica/test.py::test_cluster_all_replicas_query[3-test_cluster_secure] FAIL cidb
Integration tests (arm_binary, distributed plan, 3/4) error
Integration tests (arm_binary, distributed plan, 4/4) error

AI Review

Summary

This PR fixes a real correctness issue in PartMovesBetweenShardsOrchestrator: ZooKeeper calls could run without a coordination component when enforce_keeper_component_tracking is enabled, triggering LOGICAL_ERROR with Current component is empty. The fix adds Coordination::setCurrentComponent guards at the relevant public entry points and adds a focused stateless regression test. I did not find blocker or major issues in the diff.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 1, 2026
getEntryByUUID is a private method only called from killPartMoveToShard,
which already sets the Coordination component guard. The guard in
getEntryByUUID was therefore redundant.

Addresses review feedback from @antonio2368.
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@groeneai

groeneai commented Apr 7, 2026

Copy link
Copy Markdown
Collaborator Author

Done — merged latest master (includes the SimSIMD SVE MSan fix from #101239) into the branch. CI should re-run with the fix included.

@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 25.00% (3/12) · Uncovered code

Full report · Diff report

@antonio2368
antonio2368 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into ClickHouse:master with commit ef3b391 Apr 8, 2026
159 of 163 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 8, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

26.3 is the only active release branch without this fix, and a test that is being backported there right now aborts the server because of it.

Stress test (amd_tsan) on #122038 (the robot's 26.3 backport of my #118360, which @ Algunenano labelled pr-must-backport earlier today) failed with the exact LOGICAL_ERROR this PR fixed, in the frame this PR guarded. It is the only failing check on that PR:

https://github.com/ClickHouse/ClickHouse/actions/runs/36027584268/job/107756108610

InterpreterKillQueryQuery::execute
 -> InterpreterKillQueryQuery::getSelectResult            // SELECT over system.part_moves_between_shards
   -> StorageSystemPartMovesBetweenShards::fillData
     -> StorageReplicatedMergeTree::getPartMovesBetweenShardsEntries
       -> PartMovesBetweenShardsOrchestrator::getEntries  // first of the 3 sites this PR guarded
         -> syncStateFromZK -> zk->getChildren -> ZooKeeper::pushRequest
           -> LOGICAL_ERROR "Current component is empty" -> abortOnFailedAssertion -> abort

#118360 adds 05082_kill_and_system_on_cluster_access_types.sh, which runs KILL PART_MOVE_TO_SHARD; InterpreterKillQueryQuery.cpp:454-461 turns that into a SELECT over system.part_moves_between_shards. tests/config/install.sh:328 links zookeeper_enforce_component_name.yaml unconditionally, so every stateless and stress run has enforce_keeper_component_tracking=true. On master this PR's guard absorbs it; 26.3 has no guard.

Branch state, measured against this PR's merge commit ef3b391f15fe161e29c69576223a913c5b5c7d3f:

  • 26.3: absent. compare/26.3...ef3b391f is diverged, and PartMovesBetweenShardsOrchestrator.cpp at ref=26.3 has 0 occurrences of setCurrentComponent.
  • 26.7, 26.8, 26.9: present. Each is behind with ahead_by: 0, and has 3 occurrences.

26.3 was cut 2026-03-19, 20 days before this merged, while 26.4 was cut 2026-04-21 and inherited the guard, so 26.3 is the only active branch on the wrong side of the cut. No cherry-pick or backport branch for this PR has ever existed, so nothing was declined earlier.

Scope, stated plainly: enforce_keeper_component_tracking defaults to false, so a stock 26.3 server is unaffected. With it enabled the query raises LOGICAL_ERROR, and a debug or sanitizer build turns that into an abort (Exception.cpp:114). The damage visible today is 26.3 CI.

@alexey-milovidov could you apply v26.3-must-backport to this PR? Per ci/tools/cherry_pick.py:1004 a version label targets 26.3 plus every newer active release, and pre_check at :217 skips a branch whose tip already contains the merge commit, so this should yield a single cherry-pick for 26.3 and leave 26.7/26.8/26.9 alone. The cherry-pick carries the regression test 04077_part_moves_between_shards_keeper_component.sql with it.

@PedroTadim

Copy link
Copy Markdown
Member

Backporting to merge #122038

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 25, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 25, 2026
PedroTadim added a commit that referenced this pull request Sep 25, 2026
Backport #101462 to 26.3: Set Coordination component in PartMovesBetweenShardsOrchestrator
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants