Skip to content

[pinot-server/ proactive-query-killing] (1/2) add initial SPI implementation for supporting query killing based on Scan Cost#18102

Open
anuragrai16 wants to merge 5 commits intoapache:masterfrom
anuragrai16:proactiveQueryKillingSPI
Open

[pinot-server/ proactive-query-killing] (1/2) add initial SPI implementation for supporting query killing based on Scan Cost#18102
anuragrai16 wants to merge 5 commits intoapache:masterfrom
anuragrai16:proactiveQueryKillingSPI

Conversation

@anuragrai16
Copy link
Copy Markdown
Contributor

@anuragrai16 anuragrai16 commented Apr 6, 2026

Implementation for #18043

This PR introduces all core classes for a proactive, scan-cost-based query killing framework. No existing query execution path is modified in this PR. A follow-up PR will wire these into BaseOperator.checkTermination() and the operator instrumentation points.

New classes:

  • QueryScanCostContext (pinot-spi) — LongAdder-based, thread-safe accumulator for numEntriesScannedInFilter, numDocsScanned, and
    numEntriesScannedPostFilter. One instance per query, shared across segment worker threads.
  • QueryKillingStrategy (pinot-core) — Interface for pluggable kill decisions. Includes shouldTerminate(), buildKillReport(),
    getErrorCode(), and forQuery() for table-level threshold overrides.
  • ScanEntriesThresholdStrategy (pinot-core) — Default strategy. Kills queries exceeding maxEntriesScannedInFilter or maxDocsScanned.
    Threshold of Long.MAX_VALUE disables that metric. Includes a nested Factory that validates config at init and logs a warning if no
    thresholds are set.
  • CompositeQueryKillingStrategy (pinot-core) — Combines strategies with AND/OR semantics.
  • QueryKillingStrategyFactory (pinot-core) — Factory interface for config-driven strategy loading. Custom strategies are plugged in by
    setting accounting.scan.based.killing.strategy.factory.class.name to a factory class
  • QueryKillReport (pinot-core) — Immutable snapshot of a kill event. Captures all metrics at creation time
    Produces customer-facing error messages with actionable advice and structured internal log messages.
  • QueryKillingManager (pinot-core) — Singleton manager. Builds strategy once at init via factory, delegates
    shouldTerminate()/buildKillReport() to the strategy.

Table-Level overrides supported
Table-level overrides via QueryConfig. Table config takes precedence over cluster config; null means use cluster default.

Error code: QUERY_SCAN_LIMIT_EXCEEDED (246, HTTP 400) - distinguishes scan kills (client problem) from OOM kills (server problem, 503).

Minimum config to enable

pinot.query.scheduler.accounting.scan.based.killing.enabled=true
pinot.query.scheduler.accounting.scan.based.killing.max.entries.scanned.in.filter=500000000

@anuragrai16 anuragrai16 changed the title [pinot-server/ proactive-query-killing] add initial SPI implementation for supporting query killing based on … [pinot-server/ proactive-query-killing] (1/2) add initial SPI implementation for supporting query killing based on … Apr 6, 2026
@anuragrai16 anuragrai16 changed the title [pinot-server/ proactive-query-killing] (1/2) add initial SPI implementation for supporting query killing based on … [pinot-server/ proactive-query-killing] (1/2) add initial SPI implementation for supporting query killing based on Scan Cost Apr 6, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 85.84071% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.93%. Comparing base (36cdab4) to head (33667ec).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
.../pinot/core/query/killing/QueryKillingManager.java 75.43% 11 Missing and 3 partials ⚠️
...ache/pinot/core/accounting/QueryMonitorConfig.java 76.19% 7 Missing and 3 partials ⚠️
...killing/strategy/ScanEntriesThresholdStrategy.java 90.00% 0 Missing and 4 partials ⚠️
...e/query/killing/CompositeQueryKillingStrategy.java 92.00% 1 Missing and 1 partial ⚠️
...pinot/core/query/killing/QueryKillingStrategy.java 66.66% 1 Missing ⚠️
...org/apache/pinot/spi/config/table/QueryConfig.java 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #18102      +/-   ##
============================================
+ Coverage     63.85%   63.93%   +0.07%     
- Complexity     1573     1594      +21     
============================================
  Files          3167     3184      +17     
  Lines        192092   193690    +1598     
  Branches      29601    29912     +311     
============================================
+ Hits         122666   123835    +1169     
- Misses        59774    60072     +298     
- Partials       9652     9783     +131     
Flag Coverage Δ
custom-integration1 100.00% <ø> (ø)
integration 100.00% <ø> (ø)
integration1 100.00% <ø> (ø)
integration2 0.00% <ø> (ø)
java-11 63.91% <85.84%> (+0.07%) ⬆️
java-21 63.90% <85.84%> (+0.10%) ⬆️
temurin 63.93% <85.84%> (+0.07%) ⬆️
unittests 63.93% <85.84%> (+0.07%) ⬆️
unittests1 55.85% <85.84%> (-0.22%) ⬇️
unittests2 34.32% <4.42%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants