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


##########
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:
   Nit: the server message already starts with `Error block from stage X worker 
Y on S. Msg: ...`, so the client ends up seeing `Stage 3 worker 1 failed on 
Server_1: Error block from stage 3 worker 1 on Server_1. Msg: {...}`, with the 
location twice. Maybe just use `fanOutCause.errorMessage()` as is, or drop one 
of the two prefixes.



##########
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:
   Minor: this records the first failed opchain, which is not always the 
failure that triggered the fan-out. A user cancel through 
`QueryDispatcher.cancel(requestId)` goes over the unary RPC and never touches 
the session, and the dispatcher's own `session.fanOutCancel()` after a reducer 
error does not set `_peerErrorObserved` either. So if a user cancels and some 
opchain then fails during termination with a non-cancellation code (for example 
`QUERY_EXECUTION` from a closed mailbox, or `UNKNOWN`), 
`resolveStreamModeError` would replace the user's cancellation with that error. 
It's a rare case. A cheap fix would be to mark the session when the broker 
starts a cancel itself and skip recording a cause after that. If you'd rather 
keep it as is, could you reword the javadoc of `getFanOutCause` to say it is 
the first opchain failure?



-- 
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