Skip to content

Pull the replication log before MOVE PART ... TO SHARD checks the part (flaky 05495_part_moves_between_shards_step_retry) - #129409

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-move-part-to-shard-pull-log-before-predicate
Nov 6, 2026
Merged

Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-move-part-to-shard-pull-log-before-predicate

Conversation

@groeneai

@groeneai groeneai commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #76039

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Failure. 05495_part_moves_between_shards_step_retry (added in #129029) times out in Fast test (arm_darwin), 4 of about 200 runs since 2026-11-04, e.g. #110211, #129179. Its ALTER TABLE ... MOVE PART ... TO SHARD fails with Part all_0_0_0 does not contain in snapshot of previous virtual parts. (PART_IS_TEMPORARILY_LOCKED), so no move entry is created and the polling loops run until the timeout.

Root cause. A part inserted on a replica enters virtual_parts only when the background queueUpdatingTask pulls its log entry. movePartitionToShard builds a merge predicate, which snapshots virtual_parts before pulling the log, and canUsePartInMerges rejects a part missing from that snapshot. The server logs of the failing jobs show the MOVE starting while the background pull of the insert's entry was still in flight. #76039 fixed the same race for DETACH/DROP PART by pulling the log before getMergePredicate; movePartitionToShard, whose check is a copy of dropPart's, did not get that call.

Change. Call queue.pullLogsToQueue(..., MERGE_PREDICATE) before getMergePredicate in movePartitionToShard, as dropPartImpl does.

Validation. The new test 05507_part_move_to_shard_after_unpulled_insert (STOP PULLING, INSERT, then START PULLING and MOVE in one call) fails 20/20 without the change with the same error and passes 50/50 with it under random settings; 05495 and 03356_pull_entry_before_detach_part pass 50/50.


Workflow [PR]
Sync PR [sync-upstream/pr/129409]

Version info

  • Merged into: 26.11.1.1510-master (included in 26.11 and later)

groeneai and others added 2 commits November 4, 2026 23:17
…redicate

A part inserted on a replica enters that replica's `queue.virtual_parts`
only when the replica pulls the part's own GET_PART log entry, which the
background `queueUpdatingTask` does asynchronously. `movePartitionToShard`
builds a `ReplicatedMergeTreeZooKeeperMergePredicate`, whose constructor
snapshots `virtual_parts` into `prev_virtual_parts` before it pulls the log,
and `canUsePartInMerges` rejects a part missing from that snapshot. So
`ALTER TABLE ... MOVE PART ... TO SHARD` issued right after an INSERT on the
same replica fails with "Part ... does not contain in snapshot of previous
virtual parts. (PART_IS_TEMPORARILY_LOCKED)" while the background pull is
still in flight. On the macOS Fast test runner the client round trips are
short enough to hit this window, which makes
05495_part_moves_between_shards_step_retry time out.

`dropPartImpl` got the same fix in ClickHouse#76039 (pull the log with
MERGE_PREDICATE before `getMergePredicate`); `movePartitionToShard`, whose
check block is a copy of `dropPart`'s, never did. Port that call.

The new test stops log pulling, inserts, then restarts pulling and moves
the part in one client call, so the insert's entry is not in the queue when
the MOVE starts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SYSTEM STOP PULLING REPLICATION LOG only cancels the pull blocker; it does
not wait for a pullLogsToQueue that already passed the blocker check. The
queue-updating task started by CREATE TABLE could therefore read /log after
the INSERT and put the part into virtual parts, so the test could pass without
the fix by timing alone. SYSTEM SYNC REPLICA src PULL finishes that pull before
the blocker is set, the same drain 02903_rmt_retriable_merge_exception uses.

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

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 rounds, 1 finding) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ SYSTEM STOP PULLING REPLICATION LOG does not wait for a pull already in flight, so the new test could pass without the fix (ReplicatedMergeTreeQueue.cpp:849 checks the blocker before reading /log) AGREE, fixed in f3172ab the test drains the post-CREATE pull with SYSTEM SYNC REPLICA src PULL before STOP, as 02903_rmt_retriable_merge_exception.sh does; still 20/20 FAIL without the change
2 💡 optimize() also builds the predicate without a pull first DISAGREE it only selects parts and never rejects a named part; separate code path

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261105-000000

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05507_part_move_to_shard_after_unpulled_insert drains the post-CREATE pull (SYNC REPLICA ... PULL), stops log pulling, inserts, then restarts pulling and runs the MOVE in one client call: 20/20 FAIL on the master debug snapshot and 20/20 FAIL on this tree without the change, all with Code: 384 ... does not contain in snapshot of previous virtual parts.
b Root cause explained? Yes. A freshly inserted part is in virtual_parts only after the replica pulls its own log entry (background task). The merge predicate built by movePartitionToShard snapshots virtual_parts before it pulls, and canUsePartInMerges rejects a part missing from the snapshot, so a MOVE racing the background pull is rejected.
c Fix matches root cause? Yes. The MOVE pulls the log before building the predicate, the same call #76039 added to dropPartImpl.
d Test intent preserved / new tests added? Yes. New regression test 05507; 05495 is unchanged and passes 50/50.
e Both directions demonstrated? Yes. Base 20/20 FAIL (two base binaries), fix 50/50 OK with random settings; in every fix run the ALTER's own query pulled the insert's entry (server log).
f Fix is general across code paths? Yes. Of all getMergePredicate callers only DROP/DETACH PART (already pulls) and MOVE PART TO SHARD check a user-named part with canUsePartInMerges; background merge selection just skips a not-yet-pulled part.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for data types: the check is on part names. The test reads the part name from system.parts, so insert fault injection cannot change it.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or protocol change; one extra log pull per MOVE PART ... TO SHARD.
i Invariants and contracts preserved? Yes. pullLogsToQueue serializes on pull_logs_to_queue_mutex; the predicate's copy-then-pull order is untouched. With log pulling stopped the MOVE still fails with Log pulling is cancelled. (ABORTED), as before.

Session id: cron:clickhouse-impl-slot-41:20261104-235100

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix @CheSema, could you review this and add the can be tested label so CI runs? movePartitionToShard builds its merge predicate before pulling the replication log, so a just-inserted part can be missing from the virtual-parts snapshot and the MOVE fails with PART_IS_TEMPORARILY_LOCKED; this adds the same pullLogsToQueue(MERGE_PREDICATE) call that #76039 added to dropPartImpl.

@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f3172ab]

Summary: ✅


AI Review

Summary

Reviewed PR head f3172ab2fbfeb7c55a38c00d577215a48d6e4257 and all prior discussion. The change pulls the replication log before MOVE PART ... TO SHARD snapshots virtual_parts, preventing a freshly inserted part from being rejected with PART_IS_TEMPORARILY_LOCKED. No actionable findings. The new regression test 05507_part_move_to_shard_after_unpulled_insert and existing 05495_part_moves_between_shards_step_retry both pass in the Fast test report.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. labels Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f3172ab2f with master dc0b52ea1 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 38 s compile time in total, 7 of them have a recent master baseline.

Job report

@Algunenano Algunenano 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.

LGTM. @groeneai Please audit the code and see if there are any more issues remaining like this

@Algunenano
Algunenano added this pull request to the merge queue Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I am auditing the other ReplicatedMergeTree paths that take a merge-predicate (virtual parts) snapshot before pulling the replication log; I will follow up here with a PR (or my findings) shortly.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

@Algunenano I audited it and found no other instance, so there is no follow-up PR.

The stale state is prev_virtual_parts, which the predicate copies before its own pullLogsToQueue; the check that rejects a part on it is canUsePartInMerges. Every getMergePredicate caller on master:

Caller Reached from Result
dropPartImpl DROP/DETACH PART, clearEmptyParts, clearUnusedPatchParts pulls the log first (#76039)
movePartitionToShard MOVE PART ... TO SHARD this PR
optimize OPTIMIZE [PARTITION] [FINAL] not affected: the rejection is CANNOT_SELECT, so the retry loop calls waitForProcessingQueue (which pulls the log) and builds a new predicate that has the part
mergeSelectingTask background merges and mutations the part is skipped until the next round
removePartAndEnqueueFetch, createEmptyPartInsteadOfLost, tryFinalizeMutations background do not call canUsePartInMerges

MOVE PART/PARTITION TO DISK/VOLUME reads virtual_parts directly (isVirtualPart), but it returns false for a part that is not there yet, so it does not reject it.

In CIDB over the last 60 days, does not contain in snapshot of previous virtual parts appears only in 05495 failures. SharedMergeTree is not in this repository, so I did not check it.

Merged via the queue into ClickHouse:master with commit 0a8bddf Nov 6, 2026
547 of 549 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 6, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 6, 2026
A test added by a PR now fails the Fast test when it runs longer than 15 s,
or 7.5 s when it is tagged `no-parallel` (or `sequential`). Existing tests
are not checked.

The Config Workflow hook `store_data.py` stores, for a PR, the files under
`tests/queries/0_stateless/` that GitHub reports as `added` or `copied` as
the KV key `new_stateless_test_files`. A renamed test is an old test, so it
is not included. `fast_test.py` marks an `OK` row of such a test as `FAIL`
when its duration is over the limit, reusing
`Targeting.functional_test_source_file` and
`Targeting.is_sequential_functional_test` from `find_tests.py`. The parent
`Tests` result goes from `OK` to `FAIL`; an `ERROR` or `FAIL` is kept. The
merge queue and master runs store no key, so they are not checked.

`find_tests.py` is not added to the Fast test digest: a PR that adds or
copies a test file always changes the digest, so the job always runs.

Requested in ClickHouse#129298 (comment)
CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129409&sha=latest&name_0=PR&name_1=Fast+test+%28arm_darwin%29
PR: ClickHouse#129409

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 comp-replication ReplicatedMergeTree* + replication log/state transitions, eventual consistency mechanics. pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants