Fix flaky test_insert_select_from_cluster_with_partition_pruning - #105525
Conversation
The cluster INSERT path (distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage) sends the SELECT to a remote replica, which writes the part there and replicates via ZooKeeper. The INSERT pipeline returns to the client as soon as the remote query completes, before the LOCAL replica on the coordinator has fetched the part. If the test runs SELECT immediately after INSERT (timing under ~10ms on slow CI shards), the part is still PreActive locally and the SELECT returns 0 rows. The first INSERT in the test happened to pass because the SYSTEM FLUSH LOGS ON CLUSTER between INSERT and SELECT acted as an accidental barrier. The second INSERT lacked any synchronization, so it fails about 30% of the time on slower configs (arm_binary, ASan, MSan, db disk, llvm_coverage). Add explicit SYSTEM SYNC REPLICA after each INSERT to ensure the local replica has fetched any new parts before reading. Related: ClickHouse#100752 Signed-off-by: Groene AI <270696204+groeneai@users.noreply.github.com>
Pre-PR validation gatea) Deterministic repro? Partial. The race is timing-dependent (interval between INSERT pipeline return and the start of b) Root cause explained? Yes. The cluster INSERT path in c) Fix matches root cause? Yes. d) Test intent preserved? Yes. The fix adds synchronization without weakening any assertions or pinning settings:
e) Demonstrated in both directions? Partial. Without the fix: CIDB shows 30+ failures with f) Fix is general? Yes. Both INSERTs in the test exhibit the same race; both are fixed. The "happens to work" first INSERT (with Note: the same race is observable for user-written Session: cron:clickhouse-ci-task-worker:20260521-124500 |
|
cc @scanhex12 — could you review this? You wrote this test in #101299 / #101634; the second INSERT block is missing a |
|
Workflow [PR], commit [f527000] Summary: ✅ AI ReviewSummaryThis PR hardens Final Verdict
|
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 458 line(s), 14 function(s) across 133 file(s) · Details Top files
|
CI finish ledger — e4d6870CI fully finished (Finish Workflow pass). This PR does not touch MySQL protocol code; the sole failure is a chronic integration flaky.
Session id: cron:our-pr-ci-monitor:20260703-053000 |
CI finish ledger (update) — e4d6870Correcting the prior placeholder: the sole failure is NOT flaky, NOT chronic, and NOT caused by this PR. It is a fixed test bug, and a fixing PR exists.
Session id: cron:clickhouse-worker-slot-4:20260703-060700 |
…ect_cluster_partition_pruning
CI finish ledger - f527000CI is fully finished on this head and there is nothing to own: 174/174 check-runs completed, 34 success, 140 skipped, 0 failures.
Verified from the paginated check-runs API rather than the status rollup, which truncates on this repo. I am not re-pinging reviewers. Session id: cron:our-pr-ci-monitor:20260803-163000 |
Backport #105525 to 26.7: Fix flaky test_insert_select_from_cluster_with_partition_pruning
Backport #105525 to 26.5: Fix flaky test_insert_select_from_cluster_with_partition_pruning
Backport #105525 to 26.3: Fix flaky test_insert_select_from_cluster_with_partition_pruning
The cluster INSERT path (
distributedWriteIntoReplicatedMergeTreeOrDataLakeFromClusterStorage, added in #101299) sends the SELECT to a remote replica, which writes the part there and replicates via ZooKeeper. The INSERT pipeline returns as soon as the remote query completes, before the local replica on the coordinator has fetched the part. If SELECT runs immediately after, it sees 0 rows.The first INSERT in the test happened to pass because
SYSTEM FLUSH LOGS ON CLUSTERbetween INSERT and SELECT acted as an accidental barrier. The second INSERT had no synchronization and failed across many unrelated PRs (#100185, #101446, #101757, #102115, #103525, #105249, etc.) on slower configs (arm_binary, ASan, MSan,db disk,llvm_coverage), plus one master hit on 2026-05-12. Reported by @alexey-milovidov on #100752.Fix: add
SYSTEM SYNC REPLICAafter each INSERT so the local replica has fetched any new parts before reading.Closes #109936
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix flaky
test_insert_select_from_cluster_with_partition_pruning.Documentation entry for user-facing changes
Version info
26.8.1.824(included in26.8and later)26.7.4.13,26.5.7.23,26.3.18.12