Skip to content

[Enhancement] Eventize the spillable aggregation operators#74588

Open
eshishki wants to merge 1 commit into
StarRocks:mainfrom
alifcapital:enhance/spill-event-agg
Open

[Enhancement] Eventize the spillable aggregation operators#74588
eshishki wants to merge 1 commit into
StarRocks:mainfrom
alifcapital:enhance/spill-event-agg

Conversation

@eshishki

@eshishki eshishki commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

Spillable aggregation blocks on spill IO but subscribes to no wakeup, so the busy-poller spin-polls it (the cost is in #74586, the shared base in #74587). This PR opts the aggregation family into the event scheduler.

What I'm doing:

Stacked on #74587 (base).

Each spillable aggregation operator subscribes its parked driver to the spiller's event lists in prepare() and returns a typed BlockReason, so a spill IO completion wakes exactly that driver instead of the poller finding it on a spin:

  • Sinks — blocking, distinct, partitionwise agg, partitionwise distinct — park OUTPUT_FULL on a full writer (WAIT_FLUSH) or a busy spill-process channel (WAIT_CHANNEL); they subscribe to the spiller's sink list and share SpillableFlatSinkMixin. Woken by the flush-completion defer and the channel handshake.
  • Blocking / distinct sources park INPUT_EMPTY on restore IO (WAIT_RESTORE) and subscribe to the spiller's source list via SpillableSimpleRestoreSourceMixin. Woken by restore completion.
  • Partitionwise sources park on two axes via SpillablePartitionWiseSourceMixin: WAIT_FLUSH while the sink drains its final flush, WAIT_RESTORE while a per-partition restore is in flight. Every transient per-partition reader completes on the one parent spiller, so a single source-list subscription covers them all.

Gated on enable_spill_agg_events (default false, mutable): off, the agg fragment runs on the poller as before; on, the agg drivers are woken by spill events instead of polled. Query results are unchanged.

Part of #74586

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5

@eshishki eshishki requested review from a team as code owners June 9, 2026 17:38
@github-actions github-actions Bot added the documentation Documentation changes label Jun 9, 2026
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

No new undocumented parameters detected by the param-drift check.

@github-actions github-actions Bot requested a review from stdpain June 9, 2026 17:40

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d2c2763ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

CLEANUP {
function: update_be_config("enable_spill_agg_events", "false")
} END CLEANUP
select count(*), sum(sl), max(sl), min(sl) from (select c0, sum(c1) sl from t0 group by c0) tb;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Enable spill agg events in the recorded SQL test

In validate mode the SQL framework executes the R/ file, not the matching T/ file (ChooseCase.get_cases selects self.r when not recording), so this first “ON” query currently runs without the preceding function: update_be_config("enable_spill_agg_events", "true") that exists only in T/test_spill_agg_events. As a result this test exercises the default false path for both query groups and would not catch regressions in the new event-scheduler path; add the missing update call before this first query in the recorded file.

Useful? React with 👍 / 👎.

Comment thread be/src/compute_env/spill/spiller.hpp Outdated
Comment on lines +223 to +227
RETURN_IF(!guard.scoped_begin(), Status::Cancelled("cancelled"));
DEFER_GUARD_END(guard);
// Completion body, then guard.scoped_end(). It is cancelled on a yield-resubmit (the task lives on
// and keeps its in-flight increment), so the completion fires exactly once, when the task truly
// finishes, while scoped_end still balances this invocation's scoped_begin.
auto guarded = GuardedCompletion(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Ensure IO completion runs when scoped_begin fails

When a queued spill IO task starts after the query has been cancelled and guard.scoped_begin() returns false, this completion guard is never constructed, even though _spiller->increase_in_flight_io() and _running_flush_tasks++ have already happened before submit. That leaves the new _in_flight_io counter permanently positive, so the new pending_finish() paths that wait on has_running_io_tasks() can keep the driver in pending finish forever; the restore and partitioned-flush task bodies repeat the same pattern, so the failed-scoped_begin path needs the same completion/compensation as normal task exit.

Useful? React with 👍 / 👎.

_remote_disk_bytes_used.get());

_notify_count_total = std::make_unique<IntCounter>(MetricUnit::OPERATIONS);
registry->register_metric("spill_notify_count_total", _notify_count_total.get());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Document the newly exposed spill metrics

This registers new user-visible BE metrics, but the repo-wide AGENTS.md invariant requires user-facing config or metric changes to update matching public docs in docs/en/ and docs/zh/ when applicable. I searched for spill_notify_count_total, spill_notify_duration_ns_total, and spill_parked_with_uncovered_reason_total under docs/ and found no entries, so operators will see these metrics without documentation for their meaning or alertability.

Useful? React with 👍 / 👎.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🌎 Translation Required?

All translation files are up to date.
Great job! No translation actions are required for this PR.

🕒 Last updated: Mon, 22 Jun 2026 08:24:14 GMT

@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions github-actions Bot added the docs-maintainer Picked up by the weekly docs triage workflow label Jun 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16eb38d4fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +55 to +58
## `spill_parked_with_uncovered_reason_total`

- Unit: Count
- Description: Number of times a pipeline driver was parked on a spill wait whose declared reason is not covered by any wakeup subscription. Always 0 in a healthy system; a non-zero value means a parked driver had nobody to wake it (a wakeup-table bug; the query may stall until it is cancelled) and is worth alerting on. Each occurrence also emits a rate-limited WARNING in the BE log.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add the Japanese metric entry

This adds the new spill_parked_with_uncovered_reason_total metric to the English and Chinese metric reference pages, but docs/ja/administration/management/monitoring/metric_details/s.md exists and was not updated. The docs guide requires corresponding pages in all language directories to stay in sync when editing docs, so Japanese users will not see this new metric in the reference.

Useful? React with 👍 / 👎.

@eshishki eshishki force-pushed the enhance/spill-event-agg branch 10 times, most recently from 4426f3a to 9efd7cc Compare June 11, 2026 08:24
@eshishki eshishki force-pushed the enhance/spill-event-agg branch 10 times, most recently from 13fc73f to bd8424c Compare June 16, 2026 12:42
Move the spillable aggregation operators (blocking, distinct-blocking, and the
partition-wise agg/distinct variants) onto the pipeline event scheduler from the
base change. Each operator's factory opts into the scheduler when
enable_spill_agg_events is set; with the flag off (default) they stay on the
poller, unchanged from upstream.

- Sink edges fold need_input()/block_reason()/pending_finish() through the shared
  SpillableFlatSinkMixin; the simple blocking/distinct sources through the new
  SpillableSimpleRestoreSourceMixin; the two partition-wise sources through the
  new two-axis SpillablePartitionWiseSourceMixin.
- block_reason() reasons (WAIT_FLUSH / WAIT_RESTORE / WAIT_CHANNEL) route through
  the named<> compile guard against each operator's covered_wakeups() mask.
- Tests: agg event subscription/gating, observer fan-out wakeups, a lockstep
  oracle binding has_output() to block_reason() per agg family, and the agg
  wakeup table + mask coverage (block_reason_agg_test); plus force-spill ON/OFF
  result-parity e2e.
- Documents enable_spill_agg_events (en/zh/ja).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Evgeniy Shishkin <eshishki@gmail.com>
@eshishki eshishki force-pushed the enhance/spill-event-agg branch from bd8424c to c6e74aa Compare June 22, 2026 08:16
@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c6e74aa719

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

fail : 0 / 156 (00.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_distinct_blocking_operator.h 0 4 00.00% [55, 122, 160, 210]
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_blocking_source_operator.cpp 0 15 00.00% [34, 38, 46, 47, 49, 50, 52, 53, 54, 58, 61, 62, 76, 77, 82]
🔵 be/src/exec/pipeline/aggregate/spillable_partitionwise_aggregate_operator.cpp 0 22 00.00% [28, 29, 32, 33, 37, 40, 41, 112, 132, 408, 409, 416, 420, 421, 424, 425, 428, 429, 445, 446, 449, 450]
🔵 be/src/exec/pipeline/aggregate/spillable_partitionwise_aggregate_operator.h 0 7 00.00% [70, 71, 76, 78, 132, 165, 262]
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_blocking_sink_operator.h 0 4 00.00% [55, 92, 93, 144]
🔵 be/src/exec/pipeline/primitives/spillable_partitionwise_source_mixin.h 0 40 00.00% [49, 50, 51, 56, 59, 60, 64, 68, 72, 77, 78, 79, 82, 92, 93, 94, 98, 99, 105, 106, 112, 113, 116, 117, 120, 121, 124, 125, 126, 129, 130, 136, 142, 143, 148, 149, 150, 153, 154, 156]
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_blocking_source_operator.h 0 2 00.00% [51, 100]
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_blocking_sink_operator.cpp 0 4 00.00% [41, 44, 45, 132]
🔵 be/src/exec/pipeline/aggregate/spillable_partitionwise_distinct_operator.h 0 7 00.00% [70, 71, 76, 78, 132, 165, 250]
🔵 be/src/exec/pipeline/aggregate/spillable_partitionwise_distinct_operator.cpp 0 22 00.00% [28, 29, 32, 33, 37, 40, 41, 108, 124, 251, 252, 259, 263, 264, 267, 268, 271, 272, 289, 290, 293, 294]
🔵 be/src/exec/pipeline/primitives/spillable_simple_source_mixin.h 0 2 00.00% [46, 47]
🔵 be/src/exec/pipeline/aggregate/spillable_aggregate_distinct_blocking_operator.cpp 0 27 00.00% [28, 29, 32, 33, 37, 40, 41, 108, 212, 216, 226, 227, 229, 230, 235, 236, 238, 239, 241, 242, 244, 245, 247, 248, 252, 255, 256]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-maintainer Picked up by the weekly docs triage workflow documentation Documentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants