You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "yashmayya (via GitHub)" <gi...@apache.org> on 2026/09/29 22:35:48 UTC

[PR] Stop multi-stage query planning when its thread is interrupted [pinot]

yashmayya opened a new pull request, #19709:
URL: https://github.com/apache/pinot/pull/19709

   ## The bug
   
   If planning of a multi-stage query takes longer than the query timeout, the broker returns `BrokerTimeoutError: Timed out while planning query`. It also calls `Future.cancel(true)`, which interrupts the planning thread. But Calcite ignores interrupts, so the thread keeps planning to the end. When the query is terminated (`QueryExecutionContext.terminate`), the same thing happens, because this call also interrupts the thread.
   
   Each of these planning threads is one of the `availableProcessors / 2` threads of the broker compile executor. A small number of slow queries can use all of them. Then new multi-stage queries wait in the queue and also fail with `BrokerTimeoutError`.
   
   Example: a query with 300 `UNION ALL` branches (`SELECT col1, col3 + <i> FROM a WHERE col3 > <i> AND col2 = '<i>'`) plans for about 16 s. With `SET timeoutMs=1000`, `MultiStageBrokerRequestHandler` returned the timeout error after 1.2 s, and its compile thread planned for 17.6 s more.
   
   ## The fix
   
   Calcite stops planning only if the `CancelFlag` of the planner `Context` is set. It reads this flag in `RelOptPlanner.checkCancel()`, before it fires each rule. Now, if the thread is interrupted, `LogicalPlanner` also throws `EarlyTerminationException` from `checkCancel()`. `LogicalPlanner` is the `HepPlanner` that runs the Pinot rule programs.
   
   A `CancelFlag` alone does not correct this. The code that cancels planning (the broker timeout and `QueryExecutionContext.terminate`) interrupts the thread, and it has no access to a flag. With this change, the thread in the example stopped 1 ms after the timeout.
   
   The broker startup warmup (`warmupCompile`) waits 5 s for a `SELECT 1` compile. After the wait, it called `shutdownNow()`, but Calcite ignored this interrupt, so a slow warmup continued in the background. Now the warmup calls `shutdown()`, so a slow warmup continues to its end as before.
   
   ## Limits
   
   Planning stops only before the next rule of a `LogicalPlanner` program fires. These steps still run to their end after an interrupt:
   
   - A single slow rule.
   - Validation, SQL-to-rel conversion, decorrelation (Calcite creates plain `HepPlanner`s for it) and field trimming. For example, the conversion of a very large `IN` list inside a `CASE` is slow.
   - The Pinot planning steps after Calcite: the v2 physical optimizer, `planQuery` and `explain`.
   
   ## Testing
   
   - `QueryPlanningCancellationTest` plans a query with an added test rule. The rule blocks on its first firing and ignores interrupts, as Calcite code does. The test cancels the planning task (as the broker does on timeout), or terminates the query. Then it makes sure that no other rule fires and that planning fails. Without this change, both tests fail: the rule fires 3 times and planning succeeds.
   - `LogicalPlannerTest` covers `checkCancel()` with an interrupted thread and with a set `CancelFlag`.
   - The new tests passed in 200 repeated runs.
   - All 1953 `pinot-query-planner` tests and all 511 `pinot-broker` tests pass. `spotless`, `checkstyle` and `license` are clean.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Stop multi-stage query planning when its thread is interrupted [pinot]

Posted by "yashmayya (via GitHub)" <gi...@apache.org>.
yashmayya merged PR #19709:
URL: https://github.com/apache/pinot/pull/19709


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Re: [PR] Stop multi-stage query planning when its thread is interrupted [pinot]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #19709:
URL: https://github.com/apache/pinot/pull/19709#issuecomment-5900861789

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/19709?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 58.07%. Comparing base ([`0f1c98d`](https://app.codecov.io/gh/apache/pinot/commit/0f1c98d9e147d1f2067add74af10227eff3c4372?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`70becc6`](https://app.codecov.io/gh/apache/pinot/commit/70becc6655532aca2149205b98c588bc2a5e3af2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   > :exclamation:  There is a different number of reports uploaded between BASE (0f1c98d) and HEAD (70becc6). Click for more details.
   > 
   > <details><summary>HEAD has 24 uploads less than BASE</summary>
   >
   >| Flag | BASE (0f1c98d) | HEAD (70becc6) |
   >|------|------|------|
   >|lane-a|2|0|
   >|integration|4|0|
   >|java-25|6|1|
   >|integration1|2|0|
   >|temurin|6|1|
   >|lane-b|2|0|
   >|unittests|2|1|
   >|unittests2|1|0|
   >|integration2|2|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #19709      +/-   ##
   ============================================
   - Coverage     68.05%   58.07%   -9.98%     
   + Complexity     1450        1    -1449     
   ============================================
     Files          3518     2707     -811     
     Lines        228478   167100   -61378     
     Branches      36201    27272    -8929     
   ============================================
   - Hits         155492    97050   -58442     
   - Misses        60778    61888    +1110     
   + Partials      12208     8162    -4046     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [integration](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration1](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration2](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-25](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.07% <100.00%> (-9.98%)` | :arrow_down: |
   | [lane-a](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [lane-b](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.07% <100.00%> (-9.98%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.07% <100.00%> (-9.98%)` | :arrow_down: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `58.07% <100.00%> (+<0.01%)` | :arrow_up: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/19709/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/pinot/pull/19709?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org