Ngone51 commented on code in PR #46805:
URL: https://github.com/apache/spark/pull/46805#discussion_r1644073133


##########
common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/BlockStoreClient.java:
##########
@@ -190,6 +217,52 @@ public void onFailure(Throwable t) {
     }
   }
 
+  private <T> void retry(
+      final int retryCountValue,
+      final int saslRetryCountValue,
+      final int maxRetries,
+      final boolean enableSaslRetries,
+      int delayMs,
+      Supplier<CompletableFuture<T>> action,
+      CompletableFuture<T> future) {
+    action.get()
+            .thenAccept(future::complete)
+            .exceptionally(e -> {
+              int retryCount = retryCountValue;
+              int saslRetryCount = saslRetryCountValue;
+              boolean isIOException = e instanceof IOException
+                      || (e.getCause() != null && e.getCause() instanceof 
IOException);
+              boolean isSaslTimeout = enableSaslRetries && e instanceof 
SaslTimeoutException;
+              if (!isSaslTimeout && saslRetryCount > 0) {
+                Preconditions.checkState(retryCount >= saslRetryCount,
+                        "retryCount must be greater than or equal to 
saslRetryCount");
+                retryCount -= saslRetryCount;
+                saslRetryCount = 0;
+              }
+              boolean hasRemainingRetries = retryCount < maxRetries;
+              boolean shouldRetry = (isSaslTimeout || isIOException) &&
+                      hasRemainingRetries;
+              if (!shouldRetry) {
+                future.completeExceptionally(e);
+              } else {
+                if (enableSaslRetries && e instanceof SaslTimeoutException) {
+                  saslRetryCount += 1;
+                }
+                retryCount += 1;
+                int finalRetryCount = retryCount;
+                int finalSaslRetryCount = saslRetryCount;
+                logger.info("Retrying ({}/{}) for getting host local dirs 
after {} ms",
+                        MDC.of(LogKeys.NUM_RETRY$.MODULE$, finalRetryCount),
+                        MDC.of(LogKeys.MAX_ATTEMPTS$.MODULE$, maxRetries),
+                        MDC.of(LogKeys.RETRY_WAIT_TIME$.MODULE$, delayMs));

Review Comment:
   Could you also log the error together?



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