Repository navigation
Fix SYSTEM REFRESH on a stopped RabbitMQ table not consuming the backlog - #111480
alexey-milovidov merged 11 commits into
Conversation
A REFRESH grants exactly one out-of-order streaming cycle. For RabbitMQ that cycle starts the AMQP delivery loop asynchronously, so RabbitMQSource could return zero rows on its first poll (buffer not filled yet) and break before reaching the bounded waitForMessages path, wasting the single permit and leaving the queued messages unconsumed until SYSTEM START. A blocked-REFRESH background cycle now waits once (bounded by the flush interval, cancel-aware) for the first message before returning empty. The wait is a single shot, so an empty queue still returns promptly and the one-REFRESH-one-cycle contract holds. Direct SELECTs and normal polling are unchanged. Fixes the flaky test_storage_rabbitmq/test_system_stop.py REFRESH tests added in ClickHouse#107476. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-0:20260722-190100 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck; delta recheck raised 0 new findings).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-0:20260722-190100 |
|
cc @kssenii - could you review this? It fixes |
|
Workflow [PR], commit [b4cef25] Summary: ✅
AI ReviewSummaryThis PR fixes the stopped- Final Verdict✅ No new inline findings on the current head. |
…locked The first-message wait added for SYSTEM REFRESH on a stopped RabbitMQ table parked the streaming source on the consumer's condition variable. Delivery of that message comes from the RabbitMQLoopingTask, which runs in the same MessageBrokerSchedulePool. While the stream is stopped the looping task may never get a pool worker (a SYSTEM REFRESH ALL BACKGROUND fan-out across more tables than background_message_broker_schedule_pool_size can occupy them all), so the parked cycle only wakes on its timeout with zero rows and the backlog stays queued. With rabbitmq_flush_interval_ms=0 the wait was also unbounded (SANITY_TIMEOUT, 10 min). Have the blocked-REFRESH cycle drive the event loop itself via RabbitMQHandler::iterateLoop() (a no-op when the looping task already owns the loop, since it try_locks the handler startup mutex) on every empty poll, not just the first, so backlog messages after the first are drained too. This removes the dependency on a second pool worker for the whole cycle. Each empty poll is bounded by a fresh per-poll idle budget rather than the shared construction-time stopwatch: with more than one consumer the sources share a single pipeline thread and run serially, so a shared budget would let the first source spend it all and starve the rest. Add a regression test on a node with a single message-broker worker (background_message_broker_schedule_pool_size=1) and two consumers that deterministically strands the backlog without the fix.
Internal second-model review — adjudication log (bot-feedback fixup) (click to expand)Gate B (independent second-model code review) on the fixup commit, two rounds. All findings verified against the code before acting. Round 1 (3 findings)
Round 2 (stateful re-review, 2 findings)
Both-directions verification (integration runner): pre-fix baseline strands the backlog (0 of 20 rows); with the fix it drains completely. |
… empty ones The self-driving blocked-REFRESH cycle (drive_loop_on_worker) skipped the main-loop time-limit check (it was gated by !drive_loop_on_worker) and only consulted the per-source drive budget inside driveLoopUntilMessage, which runs only on an empty poll. So a blocked SYSTEM REFRESH with a steady backlog (every poll returns rows) never re-entered driveLoopUntilMessage and never checked elapsed time, draining up to rabbitmq_max_block_size instead of staying bounded by the flush interval. Start the per-source drive_stopwatch at cycle entry and consult driveBudgetMs() in the main loop for the drive path, so the absolute deadline is enforced on every iteration regardless of poll outcome. Cap the empty-poll wait slice by the remaining budget so the wait honors the same deadline. A large backlog now drains across successive REFRESH cycles, each bounded by the flush interval, matching the non-driving path.
Internal second-model review (Gate B, round 2) — click to expandIndependent review of commit
|
…ycle A blocked SYSTEM REFRESH cycle drives the AMQP event loop itself (the source calls iterateLoop while draining, and acks go through iterateLoop too), so it does not need the background RabbitMQLoopingTask. But streamToViews still started that task (once before executing the pipeline and once at the end of a successful cycle), and with a single message-broker worker (background_message_broker_schedule_pool_size=1) the looping task then spins uv_run on the only worker forever, so the streaming task can never be scheduled again and every later SYSTEM REFRESH or SYSTEM START is stuck. Skip starting the background loop on the self-driving (blocked REFRESH) path. The table is stopped, so no continuous streaming should follow the cycle anyway. Also right-size test_refresh_drains_backlog_with_single_broker_worker: one blocked REFRESH cycle is bounded by each serial source's flush-interval drive budget, and single-worker self-driven delivery is paced, so a 20-message backlog did not fit one cycle and stranded a message. Publish a small backlog (two per consumer) that fits the budget with margin, and extend the test to issue a second REFRESH and a START so it also covers the worker no longer being monopolized. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 Gate B passes, 5 distinct findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-3:20260723-054501 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-3:20260723-054501 |
|
Update: pushed
Both directions validated locally: the test fails at the second |
…self-driving path The self-driving blocked-REFRESH path bounded the whole cycle by driveBudgetMs() (the flush interval, or a 5s default when the flush interval is 0). But an explicit rabbitmq_flush_interval_ms=0 means "no per-cycle timeout" and is preserved as 0 through streamToViews, so the normal streaming path leaves such a cycle unbounded (it drains up to max_block_size). The drive path instead cut a flush=0 stopped table off after 5s, stranding a large or slow backlog until the next REFRESH/START. Make the whole-cycle deadline honor max_execution_time_ms (0 == unlimited) on both paths: the generateImpl time-limit check now uses max_execution_time_ms directly, so flush=0 drains the full backlog up to max_block_size like the normal path. The finite driveBudgetMs() fallback is kept only where it must not spin forever: the per-wait idle window in driveLoopUntilMessage now measures a fresh per-call Stopwatch when flush=0, so an empty queue still releases the REFRESH permit after the default wait while a live backlog (messages always pending) never idles and drains in full. flush>0 behavior is unchanged (cumulative drive_stopwatch vs the flush interval). The single-broker-worker regression test now uses flush_interval_ms=0 with a 20-message backlog per REFRESH: it drains fully only when no finite whole-cycle cap truncates the paced single-worker drain, and it keeps the second-REFRESH assertion so a self-driving cycle must not leave the looping task holding the sole worker. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review log (round 3, commit cb33e54) - click to expandGate B (independent second-model review, engine=codex) on the round-3 delta (flush_interval_ms=0 unlimited-cycle fix). 6 findings, all adjudicated DISAGREE with evidence (4 are re-raises of round-2 findings, re-verified; 1 new, refuted as unreachable + out of scope; 1 stale-contract false positive).
Build-ID cb33e54 = 11c0b7f7a548a801e3c23e3e53e52fd7c6f1cfc1. Session id: cron:clickhouse-maint-slot-9:20260723-072300 |
…ing path too A blocked SYSTEM REFRESH cycle sets drive_loop_on_worker and drives the AMQP event loop from the source as a fallback for a starved MessageBrokerSchedulePool. An earlier commit additionally stopped starting the background RabbitMQLoopingTask on that path. But self-drive alone is paced (one iterateLoop + a short poll per message), so with a finite rabbitmq_flush_interval_ms a single REFRESH drained only the first queued message before the per-cycle budget elapsed: the backlog was left queued and REFRESH looked like it consumed one row instead of the whole snapshot. Start the looping task on the self-driving path again. When a pool worker is free it delivers the whole backlog within the budget (the pre-existing behavior); when the pool is starved the task simply stays queued and the source's own self-drive still makes progress (iterateLoop and startLoop are serialized by the handler's startup_mutex, so uv_run is never driven concurrently). The task is deactivated unconditionally after the cycle and, on the self-driving path, is not restarted afterwards, so a single message-broker worker is not monopolized and later REFRESH/START cycles still run. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed a PR-caused CI regression on the previous head (cb33e54). Two integration tests failed deterministically across all 6 build variants (tsan/asan/msan/coverage/arm): Root cause: Fix (1 file, 4 lines): start the background looping task on the self-driving path again. When a pool worker is free it delivers the whole backlog within the budget (the pre- Local live re-verification is blocked by a host RabbitMQ-container boot flake (broker "Time to start RabbitMQ: 64594 ms" vs the harness window; a standalone probe also did not reach |
Internal second-model review (Gate B) adjudication for the ci-fix deltaDelta reviewed: 4 lines in
|
…h-empty-cycle-permit
…EFRESH `threadFunc` decided the self-driving path with a fresh `stream_control.isBlocked()` read taken after `claimCycle` had already admitted the cycle. A `SYSTEM STOP` or `SYSTEM PAUSE` landing in that window retroactively converted an *ordinary* cycle into the self-driving one, so it would wait up to the flush interval for future deliveries - broadening `PAUSE` from "let the current cycle finish" into "maybe run one implicit refresh", letting rows published after the pause still be consumed. The symmetric case was wrong too: a `SYSTEM START` racing in right after a blocked `REFRESH` permit was claimed would drop the self-driving path and waste the permit, which is the very bug this pull request fixes. `StreamingBackgroundControl::claimCycle` now optionally reports whether the cycle was admitted by consuming a REFRESH permit *while blocked*, sampled together with the claim itself, and `StorageRabbitMQ::threadFunc` drives the loop only on that flag (consumed with `std::exchange`, so the following ordinary iterations of the inner streaming loop keep the fast empty return).
|
@alexey-milovidov branch updated as requested — head 1. Merged
2. Addressed the one remaining unresolved review thread ( Verified locally: all 6 affected translation units ( |
CI finish ledger — bf02829Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The #111772 forwards Session id: cron:our-pr-ci-monitor:20260727-170000 |
…EFRESH permit `StreamingBackgroundControl::claimCycle` read `isBlocked` a second time after `++last_seen_refresh_epoch`, so a `SYSTEM START` landing in that gap reported `claimed_blocked_refresh == false` even though the permit had been consumed on a stopped table - `StorageRabbitMQ::threadFunc` then ran an ordinary cycle and the one out-of-order cycle the `SYSTEM REFRESH` was entitled to was wasted on an empty poll, which is exactly the bug this pull request fixes. Take a single `isBlocked` sample at the top of `claimCycle` and decide both the admission and the out-parameter from it. This closes the race in both directions: a `STOP`/`PAUSE` arriving after an ordinary admission still cannot retroactively turn that cycle into a refresh cycle, and a `START` arriving after a blocked-refresh claim can no longer drop the self-driving path.
…h-empty-cycle-permit
|
Pushed
Built all six translation units that use Note that |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 84/108 (77.78%) · Uncovered code |
CI finish ledger - b4cef25CI has fully finished on this head: 174 check-runs, 0 queued, 0 in progress,
The previous head One thing worth stating so it is not misread as a failure: CIDB shows 20 Session id: cron:our-pr-ci-monitor:20260728-120000 |
|
Backporting to fix CI |
Backport #111480 to 26.7: Fix SYSTEM REFRESH on a stopped RabbitMQ table not consuming the backlog
…abbitMQ table not consuming the backlog
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
SYSTEM REFRESHon a stoppedRabbitMQtable sometimes failing to consume the queued backlog. A REFRESH grants exactly one out-of-order streaming cycle, but that cycle could return immediately with zero rows because the AMQP delivery loop had only just been started asynchronously, wasting the single permit and leaving the messages unconsumed until the nextSYSTEM START.Description
Found by the flaky integration tests
test_storage_rabbitmq/test_system_stop.py::test_refresh_survives_unready_dependenciesand::test_refresh_runs_once_while_start_keeps_consuming, both added by #107476. Reported as a master regression by @alexey-milovidov.Report (rabbitmq, master): https://s3.amazonaws.com/clickhouse-test-reports/REFs/master/d4f24b7eb15117fcbace307be50d8054c786580a/integration_tests_amd_asan_ubsan_db_disk_old_analyzer_6_6/ (
got 1 row, expected 6, passed on retry).Root cause: while a stream is stopped,
SYSTEM REFRESHgrants exactly one out-of-orderstreamToViewscycle. That cycle builds aRabbitMQSourceand starts the AMQP delivery loop asynchronously.RabbitMQSource::generateImplthen checksconsumer->hasPendingMessages()on its first poll; the loop has not delivered anything yet, so the source returns 0 rows and breaks immediately, never reaching the boundedwaitForMessagespath (which only runs after at least one row was read). The single REFRESH permit is spent on an empty cycle and, because the stream is still stopped, the queued messages stay unconsumed.Fix: a blocked-REFRESH background cycle now asks the source to wait once (bounded by the flush interval, cancel-aware, via the existing
waitForMessages) for the first message before returning empty. The wait is a single shot, so a genuinely empty queue still returns promptly and the "one REFRESH == one cycle" contract holds. DirectSELECTs and normal continuous polling are unchanged (they build the source at a separate call site and never set the flag).Scope: RabbitMQ only.
Kafkapolls the broker synchronously andNATSkeeps its cycle open vianats_wait_for_flush_interval, so neither has this async-first-poll gap; CIDB shows RabbitMQ is the only engine whosetest_system_stopREFRESH tests fail on master.Validated locally: the failing test reproduces at about 1/6 without the fix and passes 15/15 with it; the sibling REFRESH test passes 8/8.
Note: the separate
S3Queueserver abort underObjectStorageQueueSource::FileIterator::nextthat @alexey-milovidov saw on #100332 is a pre-existing hash-ring out-of-bounds bug already fixed by #108977, not by this PR.Version info
26.8.1.279-master(included in26.8and later)26.7.22.6