harveyyue commented on code in PR #3148:
URL: 
https://github.com/apache/incubator-seatunnel/pull/3148#discussion_r1001663022


##########
seatunnel-common/src/main/java/org/apache/seatunnel/common/utils/RetryUtils.java:
##########
@@ -17,7 +17,13 @@
 
 package org.apache.seatunnel.common.utils;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.TimeUnit;
+
 public class RetryUtils {
+    private static final Logger LOG = 
LoggerFactory.getLogger(RetryUtils.class);

Review Comment:
   done.



##########
seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/sink/ElasticsearchSinkWriter.java:
##########
@@ -99,29 +105,27 @@ public Optional<ElasticsearchCommitInfo> prepareCommit() {
     public void abortPrepare() {
     }
 
-    public void bulkEsWithRetry(EsRestClient esRestClient, List<String> 
requestEsList, int maxRetry) {
-        for (int tryCnt = 1; tryCnt <= maxRetry; tryCnt++) {
-            if (requestEsList.size() > 0) {
-                String requestBody = String.join("\n", requestEsList) + "\n";
-                try {
+    public void bulkEsWithRetry(EsRestClient esRestClient, List<String> 
requestEsList) {
+        try {
+            RetryUtils.retryWithException(() -> {
+                if (requestEsList.size() > 0) {
+                    String requestBody = String.join("\n", requestEsList) + 
"\n";
                     BulkResponse bulkResponse = esRestClient.bulk(requestBody);
-                    if (!bulkResponse.isErrors()) {
-                        break;
+                    if (bulkResponse.isErrors()) {
+                        throw new BulkElasticsearchException("bulk es error: " 
+ bulkResponse.getResponse());
                     }
-                } catch (Exception ex) {
-                    if (tryCnt == maxRetry) {
-                        throw new BulkElasticsearchException("bulk es 
error,try count=%d", ex);
-                    }
-                    log.warn(String.format("bulk es error,try count=%d", 
tryCnt), ex);
+                    return bulkResponse;
                 }
-
-            }
+                return null;
+            }, retryMaterial);
+        } catch (Exception e) {
+            throw new RuntimeException("ElasticSearch execute batch statement 
error", e);

Review Comment:
   done.



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