Copilot commented on code in PR #9179:
URL: https://github.com/apache/seatunnel/pull/9179#discussion_r2048035404


##########
seatunnel-e2e/seatunnel-connector-v2-e2e/connector-doris-e2e/src/test/java/org/apache/seatunnel/e2e/connector/doris/AbstractDorisIT.java:
##########
@@ -123,25 +123,47 @@ protected void initializeJdbcConnection()
     // The Host of the official image [apache/doris:doris-all-in-one-2.1.0] BE 
is 127.0.0.1, causing
     // cross-container access failure. Delete the BE and add it again
     private void initializeBE() {
-        try (Statement statement = jdbcConnection.createStatement()) {
-            ResultSet beResultSet = statement.executeQuery(SHOW_BE);
-            List<String> beList = new ArrayList<>();
-            while (beResultSet.next()) {
-                beList.add(beResultSet.getString("Host"));
-            }
-            if (beList.stream().anyMatch("127.0.0.1"::equals)) {
-                ResultSet resultSet = statement.executeQuery(SHOW_FE);
-                String feIp = null;
-                while (resultSet.next()) {
-                    feIp = resultSet.getString("Host");
+        int maxRetries = 5;
+        int retryIntervalSeconds = 10;
+        int attempt = 0;
+
+        while (attempt < maxRetries) {
+            try (Statement statement = jdbcConnection.createStatement()) {
+                ResultSet beResultSet = statement.executeQuery(SHOW_BE);
+                List<String> beList = new ArrayList<>();
+                while (beResultSet.next()) {
+                    beList.add(beResultSet.getString("Host"));
+                }
+                if (beList.stream().anyMatch("127.0.0.1"::equals)) {
+                    ResultSet resultSet = statement.executeQuery(SHOW_FE);
+                    String feIp = null;
+                    while (resultSet.next()) {
+                        feIp = resultSet.getString("Host");
+                    }
+                    statement.execute(DROP_BE);
+                    statement.execute(String.format(ADD_BE, feIp));
+                    log.info("doris BE initialized");
+                }
+                return;
+            } catch (SQLException e) {
+                log.warn(
+                        "Failed to initialize BE, attempt {}/{}. Retrying in 
{} seconds...",
+                        attempt + 1,
+                        maxRetries,
+                        retryIntervalSeconds,
+                        e);
+                attempt++;
+                try {
+                    TimeUnit.SECONDS.sleep(retryIntervalSeconds);
+                } catch (InterruptedException interruptedException) {
+                    Thread.currentThread().interrupt();
+                    throw new RuntimeException(
+                            "Thread interrupted during BE initialization 
retry",
+                            interruptedException);
                 }
-                statement.execute(DROP_BE);
-                statement.execute(String.format(ADD_BE, feIp));
-                log.info("doris BE initialized");
             }
-        } catch (SQLException e) {
-            throw new RuntimeException(e);
         }
+        throw new RuntimeException("Failed to initialize BE after " + 
maxRetries + " attempts");

Review Comment:
   Consider capturing the last SQLException thrown during the retry loop and 
include it as the cause of the final RuntimeException for enhanced debugging 
information.
   ```suggestion
           throw new RuntimeException("Failed to initialize BE after " + 
maxRetries + " attempts", lastException);
   ```



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

Reply via email to