Skip to content

Fix flaky 00443_optimize_final_vertical_merge under parallel replicas - #123977

Merged
murphy-4o merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-00443-parallel-replicas-order
Oct 6, 2026
Merged

murphy-4o merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-00443-parallel-replicas-order

Conversation

@groeneai

@groeneai groeneai commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #115004

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

00443_optimize_final_vertical_merge failed once in Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel): the last line was -4768086322359309556 instead of 0, while the row count and per-row column checks matched.

The test compared cityHash64(groupArray(ki)) over the table with the hash of 0..149999, so it depended on the order in which rows reach groupArray. Under parallel replicas that is the order in which the initiator merges the replicas' partial states, and --parallel_replicas_local_plan=1 does not stop a remote replica from getting a range. In the failing run the coordinator gave marks 0..7 to a remote replica and 8..18 to the local one, and of all arrangements of those ranges only range(65536, 150000) followed by range(0, 65536) hashes to the observed value. The part was correct; only the concatenation order differed.

The check now asserts the physical order directly with SELECT count() FROM $name WHERE ki != _part_offset, which does not depend on the read order and keeps the parallel replicas coverage. Together with count() = 150000 it still detects an unsorted part, a lost row or a duplicate. The --max_threads=1 --parallel_replicas_local_plan=1 workaround is removed.

Validation on a 3-replica parallel replicas setup: with ranges forced to split between replicas (1M rows, index_granularity = 8), the old checksum mismatched in 60/60 runs and the new check returned 0 in 120/120 runs, 61 of them with rows read by more than one replica. A reversed part gives 150000, a missing row 148999, a duplicate 1. The test passed 300/300 with randomized settings, at parallel_replicas_local_plan 0, 1 and random, and without parallel replicas.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1675-master (included in 26.10 and later)

The test compared cityHash64(groupArray(ki)) over the merged table with the
hash of 0..149999, which depends on the order rows reach groupArray. Under
parallel replicas that order is the order in which the initiator merges the
replicas' partial states, and --parallel_replicas_local_plan=1 does not stop
a remote replica from being assigned ranges. In the failing CI run (PR
ClickHouse#115004, Stateless tests (arm_binary, ParallelReplicas, s3 storage,
parallel)) the coordinator gave marks 0..7 to a remote replica and 8..18 to
the local one, and only range(65536, 150000) ++ range(0, 65536) hashes to the
observed value: the part was correct, only the concatenation order differed.

Check the physical order directly with count() ... WHERE ki != _part_offset.
It does not depend on the read order, keeps parallel replicas coverage, and
together with count() = 150000 still detects an unsorted part, a lost row or
a duplicate. _part_offset is computed per read range, so it stays correct
when replicas split the part. The max_threads=1 / local plan workaround is no
longer needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 5, 2026
@groeneai

groeneai commented Oct 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; 1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test can pass without a vertical merge, because the runner randomizes the merge algorithm settings DISAGREE The table uses the deprecated engine-argument syntax, and the client injects randomized MergeTree settings only into extended storage definitions (ClientBase::addMergeTreeSettings, src/Client/ClientBase.cpp:4157), so the merge algorithm is chosen from fixed server defaults. This PR does not change it.

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

Session id: cron:clickhouse-review-slot-8:20261005-085000

@groeneai

groeneai commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the mechanism: on a 3-replica parallel replicas setup, on a 1M-row index_granularity = 8 table, the old cityHash64(groupArray(ki)) check mismatched in 60/60 runs. Of 12 arrangements of the CI run's mark ranges, only remote 0..7 merged after local 8..18 gives the observed hash. The test itself fails about once in 10000 runs and could not be forced on its 19-mark table locally.
b Root cause explained? The checksum depends on the order rows reach groupArray. Under parallel replicas that is the order the initiator merges the replicas' partial states; parallel_replicas_local_plan=1 does not stop remote replicas from getting ranges. The data was correct, only the concatenation order differed.
c Fix matches root cause? Yes. The order-dependent oracle is replaced by an order-independent check of the same invariant (ki = _part_offset on every row). No setting pin, no tag.
d Test intent preserved / new tests added? Yes. It still asserts that the merged part holds 0..149999 in sort key order; with count() = 150000 it detects an unsorted part (150000), a lost row (148999), a duplicate (1). Mutating the check to _part_offset + 1 makes the test fail.
e Both directions demonstrated? Same split reads: old check red 60/60, new check 0 in 120/120 (61 runs with rows read by more than one replica). Test 300/300 OK with randomized settings, parallel_replicas_local_plan 0/1/random, -j 8, and without parallel replicas.
f Fix is general across code paths? Test-only. The other tests pinning parallel_replicas_local_plan=1 pin it for plan shape, not result order.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only).
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? The check relies on the one-part precondition the test already establishes (merge loop plus OPTIMIZE FINAL). _part_offset is computed per read range, so it stays correct when replicas split the part.

Session id: cron:clickhouse-impl-slot-4:20261005-080301

@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ccd87c8]

Summary: ✅


AI Review

Summary

This PR makes 00443_optimize_final_vertical_merge stop asserting on the read order of groupArray, which is inherently unstable under parallel replicas, and instead checks the invariant the test actually cares about: after the final merge, the single merged part still contains ki = 0..149999 in physical order via ki = _part_offset. Given the existing row-count and per-column consistency checks that remain in the test, this is a tighter and less flaky oracle. I did not find any correctness, coverage, or PR-metadata issues in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 5, 2026
@murphy-4o
murphy-4o added this pull request to the merge queue Oct 6, 2026
Merged via the queue into ClickHouse:master with commit 2424f62 Oct 6, 2026
149 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 Oct 6, 2026
@clickhouse-gh clickhouse-gh Bot added comp-merges Merges of data parts: choosing what to merge (merge selectors, merge predicates, part collectors)... and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-merges Merges of data parts: choosing what to merge (merge selectors, merge predicates, part collectors)... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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