Repository navigation
Add STREAM BOUNDED modifier - #110653
Add STREAM BOUNDED modifier#110653
Conversation
|
Workflow [PR], commit [073090f] Summary: ❌
AI ReviewSummaryThis PR adds Findings❌ Blockers
Tests
Final VerdictChanges requested. No new inline review was posted because the remaining blocker is already tracked on an open review thread. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 218/226 (96.46%) · Uncovered code |
|
I'm not sure if I understand, what is the purpose of a streaming query that doesn't subscribe? Is this expected to be passed some previous cursor argument in a polling loop? |
|
@EmeraldShift |
There was a problem hiding this comment.
Pull request overview
Adds a new STREAM BOUNDED modifier to ClickHouse streaming reads so a streaming query can read exactly the first fully-determined snapshot and then terminate (instead of staying subscribed for future updates). This integrates the new syntax through parsing/formatting and the analyzer, and adds bounded-specific subscription/enrichment semantics in the MergeTree streaming pipeline.
Changes:
- Extend SQL syntax/AST/analyzer plumbing to support and preserve
STREAM BOUNDED(including format round-trips and query tree hash/equality). - Implement bounded-stream behavior in MergeTree streaming sources by waiting for an atomically “determined” snapshot, reading it once, then finishing.
- Add coverage via a new stateless query test and additional gtests for bounded subscription/enrichment behavior.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04545_streaming_bounded.sql | Adds a functional query test validating bounded streams terminate on empty and read the initial snapshot when populated. |
| tests/queries/0_stateless/04545_streaming_bounded.reference | Expected output for the new bounded streaming stateless test. |
| src/Storages/MergeTree/Streaming/tests/gtest_bounds_subscription.cpp | Expands unit tests to cover bounded subscription waking and “determined snapshot” semantics plus enrichment pending behavior. |
| src/Storages/MergeTree/Streaming/SubscriptionEnrichment.h | Changes enrichment API to return a richer result (enriched + pending). |
| src/Storages/MergeTree/Streaming/SubscriptionEnrichment.cpp | Implements the richer enrichment result including “pending” detection when promotion is blocked by gaps. |
| src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSequentialSource.h | Tracks whether the first bounded snapshot has been processed to stop after the initial read. |
| src/Storages/MergeTree/Streaming/MergeTreeCommitOrderSequentialSource.cpp | Implements bounded behavior: wait for determined snapshot, read once, then finish; ensure atomic snapshot reads for bounded. |
| src/Storages/MergeTree/Streaming/MergeTreeBoundsSubscription.h | Adds bounded mode, round lifecycle hooks, and atomic snapshotIfDetermined. |
| src/Storages/MergeTree/Streaming/MergeTreeBoundsSubscription.cpp | Implements bounded wakeup rules and “determined snapshot” tracking. |
| src/Storages/MergeTree/MergeTreeData.cpp | Wraps per-subscription enrichment in begin/end round calls and consumes the new enrichment result. |
| src/Processors/QueryPlan/ReadFromMergeTree.cpp | Propagates bounded from parsed stream settings into MergeTreeBoundsSubscription. |
| src/Parsers/tests/gtest_stream_settings.cpp | Adds parser/formatter tests for STREAM BOUNDED (with and without CURSOR). |
| src/Parsers/ParserStreamSettings.cpp | Parses optional BOUNDED before optional CURSOR. |
| src/Parsers/CommonParsers.h | Registers BOUNDED as a keyword token. |
| src/Parsers/ASTTablesInSelectQuery.cpp | Ensures formatting prints stream settings when bounded is set even without a cursor. |
| src/Parsers/ASTStreamSettings.h | Adds bounded to stream settings AST structure. |
| src/Parsers/ASTStreamSettings.cpp | Formats BOUNDED (and preserves spacing when combined with CURSOR). |
| src/Analyzer/Utils.cpp | Propagates bounded when converting analyzer stream settings into AST. |
| src/Analyzer/TableExpressionModifiers.h | Adds bounded to analyzer-level StreamSettings and includes it in equality. |
| src/Analyzer/TableExpressionModifiers.cpp | Includes bounded in dumps, hashes, and error-message formatting. |
| src/Analyzer/QueryTreeBuilder.cpp | Propagates bounded from AST into analyzer stream settings. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 289/319 (90.60%) · Uncovered code |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 21 out of 21 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Core/Streaming/Settings.h:26
- The comment for
subscribe_for_updatesdescribes the inverted behavior (it says "If true" for bounded behavior, but the code usessubscribe_for_updates == falseto mean bounded). This is likely to confuse future readers and can lead to incorrect usage.
/// If true, read only the first snapshot and then finish (do not subscribe for updates).
Michicosun
left a comment
There was a problem hiding this comment.
Overall looks great!
Left a couple of non-critical comments.
| if (subscription->isDisabled()) | ||
| return; | ||
|
|
||
| const auto safe_block_numbers = subscription->snapshot(); |
There was a problem hiding this comment.
STREAM BOUNDED still is not latched to a specific enrichment round here. WakeupFd is unversioned, so a stale wake from round N can be drained after round N+1 has already advanced safe_block_numbers; this line then snapshots the newer map and the bounded query emits data that was not part of the first completed enrichment, or a mixed-round subset if N+1 is still in flight.
Concrete trace: round N notifies at cursor 3, round N+1 advances the same partition to 5 before the source runs, this line reads 5, and the new finish condition at lines 403-409 stops after emitting [0,5]. That breaks the STREAM BOUNDED contract even under the redesign to “first enrichment”.
This needs a round/epoch on the wake, or an atomic publication of {updatesCount, safe_block_numbers} so work can build the snapshot for the same round it was woken for. Please add a regression where two enrichments happen before the first wake is drained.
Build profile diff (arm_release)No arm_release build profile data for commit 073090f - the build was skipped, reused from cache, or predates profile upload. |
|
Unrelated fails : |
`MergeTreeData::scheduleStreamingJob` read the visible parts *before* it iterated the registered subscriptions. A subscription registered in that window was credited with an enrichment round computed from a parts snapshot taken before it existed. For a subscribing stream that is harmless — the next round fixes the cursor. For a bounded stream it is not: `handleBoundedReconfiguration` treats the first completed round as authoritative, so an empty stale round makes the source finish immediately and the query silently returns fewer rows (usually none) than were committed before it started. This is what `04545_streaming_queries_bounded` hit on master: the first query in the test (`SELECT ... FROM t_streaming_bounded STREAM BOUNDED` on the empty table) triggers the background streaming job, the job snapshots an empty part set, and by the time it reaches `executeOnEachSubscription` the two `INSERT`s and the second query have already run, so the second query's subscription gets that empty round and returns `all 0 0 0` instead of `all 10 45 450`. Collect the subscriptions first and read the parts only afterwards. Everything in the collected list was registered before the collect, so the parts snapshot is at least as fresh as every subscription served from it. A subscription registered after the collect is simply picked up by the next round: its own `triggerStreamingSubscriptionEnrichment` re-schedules the job even while the job is running (`BackgroundSchedulePoolTaskInfo::execute` re-queues a task that was scheduled during execution). `executeOnEachSubscription` is replaced by `collectSubscriptions`, which returns strong pointers under the shared lock, because the callback form invited exactly this ordering mistake. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8d5be603139a198bdfd2ea225d2e998554316178&name_0=MasterCI&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 Caused by: ClickHouse#110653
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add STREAM BOUNDED modifier, which read only the first snapshot of a streaming query, then finish instead of subscribing for updates.
cc @alesapin @Michicosun
Version info
26.8.1.1314(included in26.8and later)