mcvsubbu commented on a change in pull request #5169: Table level timeout 
implementation
URL: https://github.com/apache/incubator-pinot/pull/5169#discussion_r396731102
 
 

 ##########
 File path: 
pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseBrokerRequestHandler.java
 ##########
 @@ -312,8 +312,58 @@ public BrokerResponse handleRequest(JsonNode request, 
@Nullable RequesterIdentit
     long routingEndTimeNs = System.nanoTime();
     _brokerMetrics.addPhaseTiming(rawTableName, 
BrokerQueryPhase.QUERY_ROUTING, routingEndTimeNs - routingStartTimeNs);
 
+    // Set timeout in the requests
+    long timeSpentMs = TimeUnit.NANOSECONDS.toMillis(routingEndTimeNs - 
compilationStartTimeNs);
+    // Get the per-query timeout from the broker request query options if 
exists
+    long queryTimeoutMs = 
QueryOptions.getTimeoutMs(brokerRequest.getQueryOptions());
+    // Remaining time in milliseconds for the server query execution
+    // Use the max of offline table remaining time and realtime table 
remaining time for hybrid use case
+    long remainingTimeMs = 0;
+    // NOTE: Use query-level timeout if exists, or use table-level timeout if 
exists, or use instance-level timeout
+    if (offlineBrokerRequest != null) {
+      long offlineTimeoutMs;
+      if (queryTimeoutMs > 0) {
+        offlineTimeoutMs = queryTimeoutMs;
+      } else {
+        Long tableTimeoutMs = _routingManager.getTimeoutMs(offlineTableName);
+        offlineTimeoutMs = tableTimeoutMs != null ? tableTimeoutMs : 
_brokerTimeoutMs;
+      }
+      long offlineRemainingTimeMs = offlineTimeoutMs - timeSpentMs;
+      if (offlineRemainingTimeMs <= 0) {
+        LOGGER.info("Offline table timed out (time spent: {}ms, timeout: {}) 
before scattering the request {}: {}",
+            timeSpentMs, offlineTimeoutMs, requestId, query);
+        _brokerMetrics.addMeteredTableValue(rawTableName, 
BrokerMeter.REQUEST_TIMEOUT_BEFORE_SCATTERED_EXCEPTIONS, 1);
+        return new 
BrokerResponseNative(QueryException.getException(QueryException.BROKER_TIMEOUT_ERROR,
 String
+            .format("Offline table timed out (time spent: %dms, timeout: %dms) 
before scattering the request",
+                timeSpentMs, offlineTimeoutMs)));
+      }
+      offlineBrokerRequest.getQueryOptions()
+          .put(Broker.Request.QueryOptionKey.TIMEOUT_MS, 
Long.toString(offlineRemainingTimeMs));
+      remainingTimeMs = offlineRemainingTimeMs;
+    }
+    if (realtimeBrokerRequest != null) {
+      long realtimeTimeoutMs;
+      if (queryTimeoutMs > 0) {
+        realtimeTimeoutMs = queryTimeoutMs;
+      } else {
+        Long tableTimeoutMs = _routingManager.getTimeoutMs(realtimeTableName);
+        realtimeTimeoutMs = tableTimeoutMs != null ? tableTimeoutMs : 
_brokerTimeoutMs;
+      }
+      long realtimeRemainingTimeMs = realtimeTimeoutMs - timeSpentMs;
+      if (realtimeRemainingTimeMs <= 0) {
+        LOGGER.info("Realtime table timed out (time spent: {}ms, timeout: {}) 
before scattering the request {}: {}",
+            timeSpentMs, realtimeTimeoutMs, requestId, query);
+        _brokerMetrics.addMeteredTableValue(rawTableName, 
BrokerMeter.REQUEST_TIMEOUT_BEFORE_SCATTERED_EXCEPTIONS, 1);
+        return new 
BrokerResponseNative(QueryException.getException(QueryException.BROKER_TIMEOUT_ERROR,
 String
+            .format("Realtime table timed out (time spent: %dms, timeout: 
%dms) before scattering the request",
+                timeSpentMs, realtimeTimeoutMs)));
+      }
+      realtimeBrokerRequest.getQueryOptions()
+          .put(Broker.Request.QueryOptionKey.TIMEOUT_MS, 
Long.toString(realtimeRemainingTimeMs));
+      remainingTimeMs = Math.max(remainingTimeMs, realtimeRemainingTimeMs);
 
 Review comment:
   Math.min? Should we not take the stricter time to be the timeout value? 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to