Skip to content

Fix flaky test 05332_autopr_min_bytes_per_replica_events - #126189

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05332-autopr-min-bytes-qcc
Oct 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-05332-autopr-min-bytes-qcc

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120884

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

05332_autopr_min_bytes_per_replica_events (added in #120884) failed in Stateless tests (amd_debug, parallel) on PR #125846: the rejected run built a probe plan again and never reached RejectedByThreshold. 133 reruns with the same settings passed.

The first query (PREWHERE flag = 1) fills the server-wide query condition cache, so the collect run selects 1 of 782 granules and AutoPR stores 128 rows to read. Between collect and rejected, the parallel test 05060_database_max_tables_rename_inner_tables dropped a table of an Ordinary database. That table has no UUID, so MergeTreeData::dropAllData calls Context::clearCaches, which clears the query condition cache too. rejected then selected all 100000 rows, and the job's server log shows Significant difference in total rows from storage detected ... (previously 128, now 100000). Recollecting statistics. The engine is right to recollect. The test depended on a cache that other tests clear.

The test now sets use_query_condition_cache = 0, as other AutoPR tests do (e.g. 03800_autopr_reuse_index_analysis). A Random settings limits clamp would not help: the cache is on by default, and jobs that run without random settings would keep it.

Validation (debug build):

  • Unchanged test with SYSTEM CLEAR QUERY CONDITION CACHE, or an Ordinary table drop, between the two runs: 5/5 fail per trigger with the CI diff. With the fix: 3/3 pass per trigger.
  • 50 runs next to a loop of Ordinary table drops: 40/50 failed before the fix, 0/50 after.
  • 50/50 OK with random settings, 50/50 without.

🤖 Generated with Claude Code


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

Version info

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

The first query (`skipped_early`) runs `PREWHERE flag = 1` and fills the
server-wide query condition cache, so the `collect` run selects 1 of 782
granules and AutoPR stores statistics with 128 rows to read. If a parallel
test drops a table of an `Ordinary` database in between, the table has no
UUID, so `MergeTreeData::dropAllData()` calls `Context::clearCaches()`, which
clears every global cache including the query condition cache. The
`rejected` run then selects all 100000 rows, the drift check sees 128 vs
100000 and recollects statistics instead of deciding, so it reports a probe
plan built and no `RejectedByThreshold`. Seen in the failing CI job: the
neighbour `05060_database_max_tables_rename_inner_tables` dropped a UUID-less
table between the two runs, and the server logged "Significant difference in
total rows from storage detected ... (previously 128, now 100000)".

Disable the query condition cache in the test body. All three queries then
select the same granules whatever runs in parallel, and the early estimate is
the full `payload` column, which is the path the test's comments describe.
A `Random settings limits` clamp is not enough: the setting defaults to true
and jobs that run with `--no-random-settings` (Fast test, azure, coverage,
Bugfix validation) would keep the cache on.

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

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) plus my own review (1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test cannot tell when the use_query_condition_cache = 0 pin is removed: without interference, the reverted test still matches the reference DISAGREE The pin is checked against the interference that causes the flake. A query condition cache clear or an Ordinary table drop between collect and rejected fails 5/5 per trigger before the fix and passes 3/3 after; 50 runs next to an Ordinary drop loop fail 40/50 before and 0/50 after. An assertion that the cache stayed unused would only check this file's own SET. Other AutoPR tests pin the same setting without one.
2 💡 The test comment says an Ordinary drop "clears every cache"; Context::clearCaches keeps the query result cache noted, not blocking The cache this test depends on is cleared, so the mechanism stated is right.

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

Session id: cron:clickhouse-review-slot-8:20261016-031000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SYSTEM CLEAR QUERY CONDITION CACHE, or creating and dropping a MergeTree table in an Ordinary database, between the collect and rejected queries gives the CI row-3 diff 5/5 per trigger.
b Root cause explained? Yes. The first query fills the query condition cache, so collect reads 128 rows. Dropping a UUID-less table calls Context::clearCaches, which empties that cache, so rejected reads 100000 rows. The drift check then recollects statistics instead of deciding.
c Fix matches root cause? Yes. The test no longer uses the server-wide cache, so the three queries always select the same granules. No bound widened, no tag added, no data reduced.
d Test intent preserved / new tests added? Yes. The reference is unchanged and all three events are still asserted. With the cache off, the early estimate is the full column, which is what the test's comments describe. Test-only change.
e Both directions demonstrated? Yes. Before: 5/5 fail per trigger, and 40/50 fail next to a loop of Ordinary drops. After: 3/3 pass per trigger and 0/50 fail.
f Fix is general across code paths? N/A, no engine bug. The other AutoPR tests were checked and none showed failures from this mechanism.
g Fix generalizes across inputs (params/datatypes/wrappers)? 50/50 with random settings and 50/50 without. The body SET also covers jobs that run without random settings, which a clamp would not.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only, no setting or format change.
i Invariants and contracts preserved? Yes. All three queries run after the session SET (query_log shows use_query_condition_cache = 0 on each), and the first query no longer writes a cache entry.

Session id: cron:clickhouse-impl-slot-41:20261016-024900

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9562705]

Summary: ✅


AI Review

Summary

The change sets use_query_condition_cache = 0 in 05332_autopr_min_bytes_per_replica_events, preventing concurrent server-wide cache invalidation from changing the selected granules between statistics collection and threshold rejection. The existing event assertions remain intact. No actionable findings. The affected test passes in the current-head Fast test report.

Missing context / blind spots
  • ⚠️ The debug parallel and flaky-check CI jobs are still pending. Their completion would confirm the fix under those configurations. The author's reported cache-clear and concurrent-drop reproductions were not independently rerun because this checkout has no built ClickHouse binary.
Final Verdict

Status: ✅ Approve.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nickitat, could you review this? The test relied on the server-wide query condition cache staying filled between the collect and rejected runs; a parallel test dropping an Ordinary-database table calls Context::clearCaches, so rejected read 100000 rows instead of 128 and recollected statistics. The test now sets use_query_condition_cache = 0.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 16, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 16, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit a87ecfb Oct 16, 2026
526 of 528 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). 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