yashmayya commented on code in PR #20440:
URL: https://github.com/apache/pinot/pull/20440#discussion_r4759802780


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/service/dispatch/streaming/StreamingQuerySession.java:
##########
@@ -164,6 +171,8 @@ public void recordOpChainComplete(Worker.OpChainComplete 
message) {
         if (!_peerErrorObserved) {
           _peerErrorObserved = true;
           shouldFanOutCancel = true;
+          _fanOutCause = new OpChainFailure(stageId, message.getWorkerId(), 
serverId, message.getErrorCode(),

Review Comment:
   Agreed, fixed in b0b1e02e9f. The session now notes when the broker starts a 
cancel itself: `fanOutCancel()`, or a user cancel through 
`QueryDispatcher.cancel(requestId)`, which now marks the session. After that, 
no failure becomes the cause. Added tests for both paths.



##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/service/dispatch/QueryDispatcher.java:
##########
@@ -498,10 +498,35 @@ private QueryResult 
mergeSessionStatsIntoResult(QueryResult brokerResult, Stream
       // Stage 0 is broker-local and not tracked by the session; leave its 
entry null.
       stageCoverage.add(expected == 0 ? null : new 
QueryResult.StageCoverage(responded, mergeFailed, missing));
     }
-    return new QueryResult(brokerResult.getResultTable(), 
brokerResult.getProcessingException(), merged,
+    QueryProcessingException processingException =
+        resolveStreamModeError(brokerResult.getProcessingException(), 
session.getFanOutCause());
+    return new QueryResult(brokerResult.getResultTable(), processingException, 
merged,
         brokerResult.getBrokerReduceTimeMs(), stageCoverage, accumulator);
   }
 
+  /// Returns the error to report for a stream-mode query that failed with 
`error`.
+  ///
+  /// In stream mode the broker cancels every opchain as soon as one of them 
fails (see
+  /// [StreamingQuerySession#recordOpChainComplete]). The servers then end 
their opchains with `QUERY_CANCELLATION`
+  /// ("Cancelled on: <server>"), and these errors race the real error through 
the mailboxes. When the real error waits
+  /// behind a blocking operator, for example a hash join that still builds 
from its other input, a cancellation error
+  /// can reach stage 0 first. That cancellation only hides the failure that 
caused it, so this method returns that
+  /// failure instead. It keeps `error` when the cause is itself a 
cancellation, or when the server did not send an
+  /// error code (servers older than `OpChainComplete.error_code`).
+  @VisibleForTesting
+  @Nullable
+  static QueryProcessingException resolveStreamModeError(@Nullable 
QueryProcessingException error,
+      @Nullable StreamingQuerySession.OpChainFailure fanOutCause) {
+    int cancellation = QueryErrorCode.QUERY_CANCELLATION.getId();
+    if (error == null || error.getErrorCode() != cancellation || fanOutCause 
== null || fanOutCause.errorCode() <= 0
+        || fanOutCause.errorCode() == cancellation) {
+      return error;
+    }
+    return new QueryProcessingException(fanOutCause.errorCode(),
+        "Stage " + fanOutCause.stageId() + " worker " + fanOutCause.workerId() 
+ " failed on " + fanOutCause.serverId()

Review Comment:
   Agreed, fixed in b0b1e02e9f. The broker now uses the server message as is. 
Server messages already name the server (error blocks also name the stage and 
worker), so I removed the stage, worker and server fields from `OpChainFailure`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to