Skip to content

Poll all materialized views with one query in test_rabbitmq_mv_combo - #113972

Merged
PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-rabbitmq-mv-combo-poll-overhead
Aug 9, 2026
Merged

PedroTadim merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-rabbitmq-mv-combo-poll-overhead

Conversation

@groeneai

@groeneai groeneai commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109909
Related: #110224

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

This does not touch the 180 second deadline or its failure message. It removes work from inside
that deadline, which is what #110224 asked for when it reverted my earlier timeout change.

In the failing report the test is neither stalled nor far behind: consumption is monotonic across
all 37 observations and reaches 940800 / 1000000 (94.08%), needing about 20 more seconds at its
own late rate. The budget goes to the polling loop. Each iteration ran one
SELECT count() per materialized view, and every instance.query() spawns a
clickhouse-client in the container, so much of the wall clock is client start-up; under msan
that cost is the same whatever the query.

Polling all five targets with one merge() count cuts the spawns. Measured on one box in one
session, single worker: 5.14 spawns per poll to 1.02, and polling overhead 19.8s of a 53.8s poll
span (36.8%) to 7.8s of 54.8s (14.2%). With three pytest workers, the shard condition in the
failing job, overhead goes from about 38.7% to about 13.4%. Reverting only the merged query
restores every number.

The load, the deadline, the sleep(1), the failure message and the final assertion are unchanged,
and the merged count was verified equal to the previous per-table sum both while rows were arriving
and once settled. The pattern is anchored on purpose: unanchored, combo_[0-9]+
also matches the five combo_N_mv views, and reading a view goes to its target combo_N, so
every row would be counted twice and the loop would exit at half the real progress.

This may not eliminate the failure. Since #110224 the test fails about twice in 24 days over
roughly 47000 runs and never on master, so the claim is the measured overhead reduction rather
than a rate change. 21 repeat runs with three workers passed.

Version info

  • Merged into: 26.8.1.1011 (included in 26.8 and later)

test_rabbitmq_mv_combo fails on Integration tests (amd_msan) with "Time limit of 180 seconds
reached". In the failing report the test is neither stalled nor far behind: consumption is
monotonic across all 37 observations and reaches 940800 / 1000000 (94.08%), needing about 20
more seconds at its own late rate. The budget goes to the polling loop itself.

Each poll iteration issued one SELECT count() per materialized view, and every
instance.query() spawns a clickhouse-client process inside the instance container, so the
actual poll interval in CI was about 5.0s rather than the ~1s the code asks for. Under msan
the cost is process start-up, not query work: every statement in that job shows the same
per-query floor regardless of shape. On a shard running three pytest workers, that leaves too
little margin to absorb ordinary cross-worker contention.

Counting all five targets with a single merge() query removes four of the five spawns per
poll. Measured on one box in one session, single worker: 5.14 spawns per poll to 1.02, and
polling overhead 19.8s of a 53.8s poll span (36.8%) to 7.8s of 54.8s (14.2%). With three
concurrent workers, overhead goes from about 38.7% to about 13.4%. Poll cadence improves from
about 1.56s to about 1.15s, so progress is observed more finely as well. Reverting only the
merged query returns every number to its previous value.

This deliberately does not touch the 180 second deadline, its failure message, the sleep(1),
the load or the final assertion, which is what ClickHouse#110224 asked for when it reverted my earlier
attempt at loosening the timeout. The merged count was verified equal to the previous
per-table sum, both while rows were arriving and once settled, and the anchored pattern was
verified to resolve to exactly the five target tables. The anchor is load-bearing: unanchored,
combo_[0-9]+ also matches the five combo_N_mv views, and a read of a materialized view goes to
its target table, so every row would be counted twice and the loop would exit at half the real
progress. Verified on a probe database with distinct per-table counts: anchored 11111 (the five
targets, once each), unanchored 22222.

Whole-module runs before and after give identical failure sets, and 21 repeat runs with three
workers passed. This is not claimed to eliminate the failure: since ClickHouse#110224 the test fails
about twice in 24 days over roughly 47000 runs and never on master, a rate no feasible local
run count could measure.

Related: ClickHouse#109909
Related: ClickHouse#110224
@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Before opening this PR I reviewed the change myself and had a second model review it
independently against the same diff. Findings and what I did with each:

❌ The anchor comment stated the wrong reason (fixed). Both reviews landed on this
independently. The comment, and my first draft of this description, said an unanchored pattern
would match the rabbitmq engine table and consume messages. That is wrong twice: combo never
appears in that table's name (only in its rabbitmq_exchange_name / rabbitmq_queue_base
values), and StorageRabbitMQ::read refuses a direct read outright while materialized views are
attached. The real reason the anchor matters is the five combo_N_mv views: a read of a view goes
to its target combo_N, so unanchored combo_[0-9]+ would count every row twice and the loop
would exit at half the real progress. I had measured exactly that (probe database with distinct
per-table counts: anchored 11111, unanchored 22222) and then wrote down the wrong mechanism next
to it. Comment and commit message now say the real one.

⚠️ Asked for an in-test oracle proving one query per poll instead of five; I disagree.
#110224 rewrote this same polling loop for the same performance reason and added no timing or
invocation assertion, and #107928 ("Speed up two slow integration tests") adds none either - its
time.monotonic() change bounds a wait rather than asserting a speedup. A wall-clock or
spawn-count assertion inside a shared integration test would fail on a loaded runner for reasons
unrelated to what it tests, which is a new flake introduced inside a flaky-test fix. The
measurements are in the description instead, with a mutation arm that returns every number to its
previous value. The test's correctness oracle is untouched: same expected value, same equality
break, same failure message, same final assertion, and the counted set is provably the same five
tables.

⚠️ The Related: links were inside the template's HTML comment (fixed). They would not have
rendered and would have created no relationship. Moved above the first header.

💡 Comments in the new lines do not use inline code (noted, not changed). The repo asks for
literal names in comments to be wrapped in backticks, and my two added comment lines have none.
It changes nothing about the test and the enforced style check (ruff) is clean, so I left the
lines as they are rather than respin for formatting; happy to fix on request. The same review also
asked me to write instance.query without parentheses, which I did not do: the instruction is to
drop them when naming a function itself, and here the sentence is about the call happening on every
poll.

💡 Noted, not changed: the polling loop at test.py:548 issues three queries per iteration
with the same shape, but each returns a full result set compared against a different reference, so
it cannot collapse into one count. It is not on the failing path and I left it alone.

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for what this changes. The instrument cost is reproducible on demand (-n 3 --dist=each over test_rabbitmq_mv_combo, timestamped worker log, 8 runs, tight spread). The 2-in-24-days red itself is NOT locally reproducible and I am not claiming it is: the test passes locally, in CI it passed a solo -n 1 retry in 121.88s on the same commit and runner.
b Root cause explained? Yes. Each poll iteration issued 5 instance.query() calls, one per materialized view, and each spawns a clickhouse-client process in the container, so under msan the poll interval was ~5.0s in CI instead of the ~1s the code asks for. In the failing report consumption was monotonic across all 37 observations and reached 940800 / 1000000 (94.08%), needing about 20 more seconds at its own late rate. The deadline is lost to the instrument, not to a stall.
c Fix matches root cause? Yes. It removes 4 of the 5 client spawns per poll from the critical path. Not a band-aid: the 180s deadline, the failure message, the sleep(1), the load (messages_num, threads_num, NUM_MV) and the final assertion are byte-identical. This follows #110224's own reasoning when it reverted my earlier timeout change: fix the slowdown, do not loosen the timeout.
d Test intent preserved / new tests added? Preserved. Same load, same deadline, same expected value, same pytest.fail text, so the CIDB signature stays comparable. No new test: the changed test is the subject. The assertion is not weakened, because the merged count was verified equal to the previous per-table sum (see f).
e Both directions demonstrated? Yes, same box and session. Single worker: 5.14 spawns per poll and 36.8% instrument overhead before, 1.02 and 14.2% after. Three workers: about 38.7% before, about 13.4% after. Reverting only the merged query returns the numbers to 5.16 / 35.1%, so the measurement tracks the change rather than reporting a constant.
f Fix is general across code paths? Scoped deliberately, one concern per PR. test_rabbitmq_many_materialized_views (4 queries per poll), test_rabbitmq_many_inserts, test_rabbitmq_overloaded_insert and test_rabbitmq_flush_by_time (2 each) all run light loads well inside their budgets and have no failures since #110224, so the instrument is a negligible fraction there. The other polling sites already issue one query per poll.
g Fix generalizes across inputs? N/A for type wrappers: test-only change, no source path. The input dimension that matters is the table set the pattern resolves over. Verified in a probe database with the same name shapes and distinct row counts 10^N: merge(db, '^combo_[0-9]+$') gives exactly combo_0..4 totalling 11111, while the unanchored merge(db, 'combo') gives 22222 and merge(db, '.') reaches the rabbitmq table. Against the real pipeline, 21 live samples were bracketed by two merged reads and the settled counts matched exactly (5 x 100000).
h Backward compatible? Yes, trivially. No source change, no setting, no serialization, so no SettingsChangesHistory.cpp entry.
i Invariants and contracts preserved? Yes. result remains the total across all NUM_MV targets, proven equal to the previous per-table sum, so the final assertion keeps its meaning; the break and else: pytest.fail control flow is untouched. No atomicity claim is made or relied on: ReadFromMerge builds each child snapshot separately (src/Storages/StorageMerge.cpp:796), and the loop only needs a monotonic lower bound, which it had before as well.

Whole-module runs before and after this change give identical failure sets (1 failed, 56 passed both times; the one failure is a local TLS mount gap on the secure=1 parametrization, not related to this change).

Session id: cron:clickhouse-impl-slot-4:20260808-151700

@groeneai

groeneai commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @kssenii, could you review this? It is a test-only change to test_rabbitmq_mv_combo: the poll loop ran one SELECT count() per materialized view and each instance.query spawns a clickhouse-client, so under msan the poll interval was about 5s instead of 1s and most of the 180s deadline went to the instrument rather than to consumption; one anchored merge count replaces the five queries, leaving the deadline, the load and the assertions unchanged.

@PedroTadim PedroTadim self-assigned this Aug 8, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [948666c]

Summary: ✅


AI Review

Summary

This PR changes test_rabbitmq_mv_combo to poll the five combo_N targets with one merge() count instead of five separate instance.query calls. In the current head diff, the anchored regexp ^combo_[0-9]+$ excludes the combo_N_mv materialized views, so the loop still checks the same aggregate row-count invariant while removing avoidable client-spawn overhead from the 180-second deadline.

Final Verdict

✅ No actionable review findings in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 8, 2026
@groeneai

groeneai commented Aug 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 948666c

CI is fully finished on this head. One failure, owned, not PR-caused.

Check / test Reason Owner / fixing PR
Build (arm_release) / Post Hooks non-gating build-profile telemetry upload rejected by the shared CI logs cluster (Code: 241 ... would use 426.11 GiB, maximum: 29.80 GiB), all 8 retries exhausted. The Build (arm_release) check-run itself is green a fix task owns it (investigating at full effort; the analysis is public on #113408, and the fixing-PR link will be posted here)

Gate detail: (a) 0 of 175 check-runs queued or in_progress (fully paginated); (b) Finish Workflow = success at 2026-08-08T21:12:43Z; (c) 29 minutes since the last completion, past the 20-minute CIDB ingestion buffer; (d) the one line has an owner. No CH Inc sync row on this head.

On attribution: this diff is a single integration test file (tests/integration/test_storage_rabbitmq/test.py, +3/-5), so it cannot reach a build post-hook. The failure is in ci/jobs/scripts/log_cluster.py telemetry, fleet-wide today (Build (arm_release) Post Hooks reddened on 9 to 16 distinct PRs per hour over the last 24 hours). #113409 merged 2026-08-06T00:05:00Z and is deliberately not linked, per ledger rule 3d: this build provably ran post-fix code (the multi-line do_query(query, data=data_fd, retries=8, timeout=50) form is present at this head, and the 8 LogCluster query failed with code 500 warnings are that loop's exhausted-retry signature, which pre-fix code cannot emit) and it still failed. #113592 addresses a different mode (the un-retried is_ready probe, which reports No connection to LogCluster and never enters the retry loop; this row has 0 such lines and 8 warnings), so it is not this row's owner either.

The whole test_rabbitmq_mv_combo matrix is green on this head: Integration tests (amd_msan, 6/8) 112.5s, (amd_tsan, 6/6) 104.6s, (arm_binary, distributed plan, 1/4) 34.1s, plus the flaky and old-analyzer shards - all under the unchanged 180s deadline.

Note this failure is invisible to the check-runs API: only the per-test CIDB row is FAIL.

On the owner cell: the fix task for this mode has completed its investigation and its write-up is posted on #113408 (@alexey-milovidov's own report of this fleet-wide failure). It concluded the remaining variable is server-side rather than in the repository, so the task is currently waiting on that decision rather than on more analysis from me. The fixing-PR link is still owed on this PR and will be posted here.

Session id: cron:our-pr-ci-monitor:20260808-213000

@PedroTadim
PedroTadim added this pull request to the merge queue Aug 9, 2026
Merged via the queue into ClickHouse:master with commit 458a0d2 Aug 9, 2026
180 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 9, 2026
@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 19, 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 groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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