Skip to content

Fix flaky test 05401_quota_on_profile_events_query_result_cache with parallel replicas - #129672

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05401-quota-parallel-replicas
Nov 6, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05401-quota-parallel-replicas

Conversation

@groeneai

@groeneai groeneai commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117004

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):

Fix flaky test 05401_quota_on_profile_events_query_result_cache: the reads of its quota user no longer use parallel replicas.

Description

The test (added in #117004) fails only in the ParallelReplicas job, 3 of 26 runs in 30 days: 2 0 instead of 1 0 after populating the cache, then SelectQuery = 2/1 (QUOTA_EXCEEDED) on the cache hit, or 4 1 instead of 2 1 after count().

Root cause: that job enables parallel replicas in the server default profile, which the test's SQL-created user inherits. When the coordinator gives the table's only mark to a remote replica, that replica's interpreter reports SelectQuery = 1 back, and remote ProfileEvents are charged to the initiating user by design (the remote() quota tests assert this). So the populating query costs 2 against MAX SelectQuery = 1. Whether a remote replica reads is a race.

Change: the two MergeTree reads of the quota user (the cached query and the count()) set enable_parallel_replicas = 0. The .reference is unchanged.

Validation on a master binary with the job's server config emulated locally: with parallel_replicas_local_plan = 0 the unchanged test failed 10/10 with the CI output; with the job's parallel_replicas_local_plan = 1 it failed 13/50, and 18/20 with optimize_trivial_count_query = 0. The fixed test passed 10/10, 50/50 and 20/20 in the same runs, with no secondary query of the quota user in query_log, and 50/50 randomized without parallel replicas. The other 21 tests of the profile-event quota family passed 20/20 each in the same setup, so they are left as is.

🤖 Generated with Claude Code


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

Version info

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

…parallel replicas

The ParallelReplicas CI job enables parallel replicas in the server `default`
profile, which the test's SQL-created quota user inherits. When the coordinator
hands the table's only mark to a remote replica, that replica's interpreter
reports `SelectQuery = 1` back, and remote `ProfileEvents` are charged to the
initiating user (the designed behaviour of ClickHouse#117004, asserted by the `remote()`
quota tests). The populating query then costs `SelectQuery = 2` against
`MAX SelectQuery = 1`, the next cache hit is rejected, and the reference shifts;
with `optimize_trivial_count_query = 0` the `count()` fans out the same way.

Pin `enable_parallel_replicas = 0` on the two `MergeTree` reads of the quota
user. The `.reference` is unchanged.

Locally, with the job's server config emulated: unchanged test 10/10 red with
`parallel_replicas_local_plan = 0`, 13/50 with `= 1`, 18/20 with
`optimize_trivial_count_query = 0`; fixed test 10/10, 50/50, 20/20 green, plus
50/50 randomized without parallel replicas.

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

groeneai commented Nov 6, 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) plus my own cold review (0 blocker/major).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not itself assert that the pinned reads avoided parallel replicas, so a revert can still pass DISAGREE A pin in a flaky test, not a product fix: the unchanged test fails 13/50 in the job's shape and 10/10 with parallel_replicas_local_plan = 0, the fixed one passes 50/50 and 10/10 with 0 secondary queries of the quota user. Asserting ParallelReplicasQueryCount = 0 would test the pin, not the quota contract.

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

Session id: cron:clickhouse-review-slot-9:20261106-034600

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Master binary (358b8300e8bb) with the ParallelReplicas job's server profile and default_parallel_replicas cluster emulated locally, runner flags of the job, --client-option parallel_replicas_local_plan=0: the unchanged test failed 10/10 with the CI stdout byte for byte (2 0 / 2 0 / 3 0, SelectQuery = 2/1).
b Root cause explained? The job enables parallel replicas in the server default profile, which the test's SQL-created quota user inherits. A remote replica that reads the only mark reports SelectQuery = 1, and remote ProfileEvents are charged to the initiating user by design (#117004), so the populating query costs 2 against MAX SelectQuery = 1 and the next cached read is rejected.
c Fix matches root cause? Yes. The two reads whose exact SelectQuery count is asserted set enable_parallel_replicas = 0 in their SETTINGS; no bound widened, no tag, no data change.
d Test intent preserved / new tests added? Yes. .reference unchanged: populate 1 0, cache hit 1 1, count() 2 1, rejected hit, Write 1 / Read 1 are all still asserted. Test-only change.
e Both directions demonstrated? Yes, same binary and server: local_plan=0 10/10 red vs 10/10 green; job shape local_plan=1 13/50 red vs 50/50 green; with optimize_trivial_count_query=0 18/20 red (the 4 1 CI signature) vs 20/20 green; quota-user secondaries in query_log 57/127/99 before, 0 after. Fixed test 50/50 randomized on a server without parallel replicas.
f Fix is general across code paths? The other 21 tests of the profile-event quota family ran 20/20 each in the same emulation, unchanged; none asserts an exact count of a fanned-out read. Engine charging is intended and asserted by the remote() quota tests, so it is not changed.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (setting pin in a flaky test). Both parallel_replicas_local_plan values and optimize_trivial_count_query = 0 were exercised.
h Backward compatible? (maintainer-approved exception only) N/A: test-only, no setting or format change.
i Invariants and contracts preserved? The populate, hit and rejected read still share one query string, so they keep one query cache key. No engine code touched.

Session id: cron:clickhouse-impl-slot-5:20261106-032500

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @pufit, could you review this and add the can be tested label so CI runs? In the ParallelReplicas job the quota user inherits parallel replicas from the server profile, and a remote replica that reads the only mark charges its own SelectQuery to that user, so the test now sets enable_parallel_replicas = 0 on the two reads whose quota count it asserts.

@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6db074e]

Summary: ✅


AI Review

Summary

This test-only change disables parallel replicas on the quota user's two MergeTree reads, removing nondeterministic remote SelectQuery charges while preserving the cache-hit, quota-exhaustion, and query-log assertions. Reviewed the full diff, surrounding code, and all prior discussion. The reported before/after reproduction and 50 independently confirmed passing CI repetitions support the fix. No actionable findings.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). labels Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - cee5e91

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) infra, not from this PR (test-only change): at about 05:07Z GitHub reported "The self-hosted runner lost communication with the server" for this job and the four below at once, on five different runners, in the middle of the run (Run step cancelled). They published no result, so CIDB has no row for them, and a job lost this way is not re-run automatically a fix task is created (fixing-PR link to follow here)
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) same runner event, no result published a fix task is created (the same task as the first row)
Stateless tests (arm_asan_ubsan, azure, parallel) same runner event, no result published a fix task is created (the same task as the first row)
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) same runner event, no result published a fix task is created (the same task as the first row)
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 2/2) same runner event, no result published a fix task is created (the same task as the first row)
Fast test (arm_darwin) same runner event: the job had already finished green (no failed result among its 18541 CIDB rows) and was cut off while uploading its report a fix task is created (the same task as the first row)
Mergeable Check praktika rollup of the six rows above (Failed: 0, Dropped: 6) a fix task is created (the same task as the first row)
PR praktika rollup of the six rows above a fix task is created (the same task as the first row)

CIDB has no FAIL or ERROR row on this head except the Config Workflow / Pre Hooks row from the first attempt, before the can be tested label, which this run supersedes. The changed test passed 50 of 50 runs in each of the five flaky check jobs.

Session id: cron:our-pr-ci-monitor:20261106-060004

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-rbac Authorization: roles, grants, quotas, row-level security, access checks. 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