You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "Jackie-Jiang (via GitHub)" <gi...@apache.org> on 2025/08/20 23:22:55 UTC

[PR] Fix LeafOperator thread accountant [pinot]

Jackie-Jiang opened a new pull request, #16651:
URL: https://github.com/apache/pinot/pull/16651

   ## Summary
   
   This PR fixes the thread accountant setup in LeafOperator to properly handle resource accounting for multi-stage query execution.
   
   ## Changes
   
   - Changed from setupWorker() to setupRunner() for thread accountant initialization
   - Added proper cleanup with Tracing.ThreadAccountantOps.clear() in finally blocks
   - Treats LeafOperator threads as SSE runner anchor threads instead of worker threads
   - Ensures consistent thread accounting for both single table and dual table scenarios
   
   ## Technical Details
   
   The fix addresses thread accounting issues by:
   1. Using setupRunner with queryId and workloadName instead of setupWorker with taskId
   2. Adding proper resource cleanup in finally blocks to prevent resource leaks
   3. Ensuring consistent behavior between single-request and multi-request execution paths
   
   ## Files Changed
   
   - pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/LeafOperator.java
   
   ## Testing
   
   - Code compiles successfully
   - Existing tests pass
   - Manual testing of multi-stage queries
   
   This change improves resource management and prevents potential memory/thread accounting issues in multi-stage query execution.


-- 
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] Fix LeafOperator thread accountant [pinot]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #16651:
URL: https://github.com/apache/pinot/pull/16651#discussion_r2289499609


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/LeafOperator.java:
##########
@@ -469,10 +473,9 @@ void execute(ThreadExecutionContext parentContext) {
       CountDownLatch latch = new CountDownLatch(2);
       for (int i = 0; i < 2; i++) {
         ServerQueryRequest request = _requests.get(i);
-        int taskId = i;
         futures[i] = _executorService.submit(() -> {

Review Comment:
   [nitpick] The lambda expression contains a large amount of code (lines 476-514). Consider extracting this logic into a separate method to improve readability and maintainability.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/LeafOperator.java:
##########
@@ -427,37 +427,41 @@ void execute(ThreadExecutionContext parentContext) {
     ServerQueryLogger queryLogger = ServerQueryLogger.getInstance();
     if (_requests.size() == 1) {
       ServerQueryRequest request = _requests.get(0);
-      Tracing.ThreadAccountantOps.setupWorker(1, parentContext);
-
-      InstanceResponseBlock instanceResponseBlock =
-          _queryExecutor.execute(request, _executorService, resultsBlockConsumer);
-      if (queryLogger != null) {
-        queryLogger.logQuery(request, instanceResponseBlock, "MultistageEngine");
-      }
-      // Collect the execution stats
-      mergeExecutionStats(instanceResponseBlock.getResponseMetadata());
-      // TODO: Revisit if we should treat all exceptions as query failure. Currently MERGE_RESPONSE_ERROR and
-      //       SERVER_SEGMENT_MISSING_ERROR are counted as query failure.
-      Map<Integer, String> exceptions = instanceResponseBlock.getExceptions();
-      if (!exceptions.isEmpty()) {
-        setErrorBlock(ErrorMseBlock.fromMap(QueryErrorCode.fromKeyMap(exceptions)));
-      } else {
-        // NOTE: Instance response block might contain data (not metadata only) when all the segments are pruned.
-        //       Add the results block if it contains data.
-        BaseResultsBlock resultsBlock = instanceResponseBlock.getResultsBlock();
-        if (resultsBlock != null && resultsBlock.getNumRows() > 0) {
-          try {
-            addResultsBlock(resultsBlock);
-          } catch (InterruptedException e) {
-            setErrorBlock(CANCELLED_BLOCK);
-          } catch (TimeoutException e) {
-            setErrorBlock(TIMEOUT_BLOCK);
-          } catch (Exception e) {
-            if (!(e instanceof EarlyTerminationException)) {
-              LOGGER.warn("Failed to add results block", e);
+      // NOTE: Treat this as SSE runner (anchor) thread.
+      Tracing.ThreadAccountantOps.setupRunner(parentContext.getQueryId(), parentContext.getWorkloadName());
+      try {

Review Comment:
   [nitpick] The try block wraps a large amount of code (lines 432-462). Consider extracting the execution logic into a separate method to improve readability and reduce the size of the try block.



-- 
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] Fix LeafOperator thread accountant [pinot]

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


-- 
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] Fix LeafOperator thread accountant [pinot]

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

   ## [Codecov](https://app.codecov.io/gh/apache/pinot/pull/16651?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `42.85714%` with `20 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 56.38%. Comparing base ([`5799642`](https://app.codecov.io/gh/apache/pinot/commit/57996423a54184cfb5b6b1b97a5858fb8d813053?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`2001f84`](https://app.codecov.io/gh/apache/pinot/commit/2001f846d57bfc4450ce0da930c3449c62dd095c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 2 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/pinot/pull/16651?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...che/pinot/query/runtime/operator/LeafOperator.java](https://app.codecov.io/gh/apache/pinot/pull/16651?src=pr&el=tree&filepath=pinot-query-runtime%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fpinot%2Fquery%2Fruntime%2Foperator%2FLeafOperator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cGlub3QtcXVlcnktcnVudGltZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvcGlub3QvcXVlcnkvcnVudGltZS9vcGVyYXRvci9MZWFmT3BlcmF0b3IuamF2YQ==) | 42.85% | [16 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/pinot/pull/16651?src=pr&el=tree&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 (5799642) and HEAD (2001f84). Click for more details.
   > 
   > <details><summary>HEAD has 36 uploads less than BASE</summary>
   >
   >| Flag | BASE (5799642) | HEAD (2001f84) |
   >|------|------|------|
   >|java-21|5|1|
   >|unittests1|2|1|
   >|unittests|4|1|
   >|temurin|10|1|
   >|unittests2|2|0|
   >|java-11|5|0|
   >|integration|6|0|
   >|integration1|2|0|
   >|custom-integration1|2|0|
   >|integration2|2|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #16651      +/-   ##
   ============================================
   - Coverage     63.29%   56.38%   -6.92%     
   + Complexity     1379      699     -680     
   ============================================
     Files          3033     2377     -656     
     Lines        176632   131701   -44931     
     Branches      27113    20992    -6121     
   ============================================
   - Hits         111796    74254   -37542     
   + Misses        56241    51273    -4968     
   + Partials       8595     6174    -2421     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [custom-integration1](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [integration](https://app.codecov.io/gh/apache/pinot/pull/16651/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/16651/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/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-11](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [java-21](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.38% <42.85%> (-6.89%)` | :arrow_down: |
   | [temurin](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.38% <42.85%> (-6.92%)` | :arrow_down: |
   | [unittests](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.38% <42.85%> (-6.91%)` | :arrow_down: |
   | [unittests1](https://app.codecov.io/gh/apache/pinot/pull/16651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `56.38% <42.85%> (-0.03%)` | :arrow_down: |
   | [unittests2](https://app.codecov.io/gh/apache/pinot/pull/16651/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 Sentry](https://app.codecov.io/gh/apache/pinot/pull/16651?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