gavinchou commented on code in PR #47370:
URL: https://github.com/apache/doris/pull/47370#discussion_r1929970147


##########
fe/fe-core/src/main/java/org/apache/doris/job/extensions/mtmv/MTMVTask.java:
##########
@@ -240,6 +247,43 @@ public void run() throws JobException {
         }
     }
 
+    private void executeWithRetry(Set<String> execPartitionNames, Map<TableIf, 
String> tableWithPartKey)
+            throws Exception {
+        int retryCount = 0;
+        int retryTime = Config.max_query_retry_time;
+        retryTime = retryTime <= 0 ? 1 : retryTime + 1;
+        Exception lastException = null;
+        while (retryCount < retryTime) {
+            try {
+                exec(execPartitionNames, tableWithPartKey);
+                break; // Exit loop if execution is successful
+            } catch (Exception e) {
+                if (!(Config.isCloudMode() && 
e.getMessage().contains(FeConstants.CLOUD_RETRY_E230))) {
+                    throw e; // Re-throw if it's not a retryable exception
+                }
+                lastException = e;
+
+                int randomMillis = 10 + (int) (Math.random() * 10);
+                if (retryCount > retryTime / 2) {
+                    randomMillis = 20 + (int) (Math.random() * 10);
+                }
+                if (DebugPointUtil.isEnable("MTMVTask.retry.longtime")) {
+                    randomMillis = 1000;
+                }
+
+                retryCount++;
+                LOG.warn("Retrying execution due to exception: {}. Attempt 
{}/{}, "
+                        + "taskId {} execPartitionNames {} lastQueryId {}, 
randomMillis {}",
+                        e.getMessage(), retryCount, retryTime, getTaskId(),
+                        execPartitionNames, lastQueryId, randomMillis);
+                Thread.sleep(randomMillis);
+            }
+        }
+        if (retryCount == retryTime) {
+            throw new Exception("Max retry attempts reached, original: " + 
lastException);
+        }
+    }
+

Review Comment:
   
   ```suggestion
       private void executeWithRetry(Set<String> execPartitionNames, 
Map<TableIf, String> tableWithPartKey)
               throws Exception {
           int retryCount = 0;
           int retryTime = Config.max_query_retry_time;
           retryTime = retryTime <= 0 ? 1 : retryTime + 1;
           Exception lastException = null;
           while (retryCount < retryTime) {
               try {
                   exec(execPartitionNames, tableWithPartKey);
                   break; // Exit loop if execution is successful
               } catch (Exception e) {
                   if (!(Config.isCloudMode() && 
e.getMessage().contains(FeConstants.CLOUD_RETRY_E230))) {
                       throw e; // Re-throw if it's not a retryable exception
                   }
                   lastException = e;
   
                   int randomMillis = 10 + (int) (Math.random() * 10);
                   if (retryCount > retryTime / 2) {
                       randomMillis = 20 + (int) (Math.random() * 10);
                   }
                   if (DebugPointUtil.isEnable("MTMVTask.retry.longtime")) {
                       randomMillis = 1000;
                   }
   
                   retryCount++;
                   LOG.warn("Retrying execution due to exception: {}. Attempt 
{}/{}, "
                           + "taskId {} execPartitionNames {} lastQueryId {}, 
randomMillis {}",
                           e.getMessage(), retryCount, retryTime, getTaskId(),
                           execPartitionNames, lastQueryId, randomMillis);
                   if (tryCount >= retryTime) {
                       throw new Exception("Max retry attempts reached, 
original: " + lastException);
                   }
                   Thread.sleep(randomMillis);
               }
           }
       }
   
   ```



-- 
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-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to