You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2019/05/13 12:38:13 UTC

[james-project] 04/07: JAMES-2725 add retry on exception for s3 upload

This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8e73a1d2429fd4ffb2bda0dfa697bed49213189b
Author: RĂ©mi Kowalski <rk...@linagora.com>
AuthorDate: Tue May 7 13:40:47 2019 +0200

    JAMES-2725 add retry on exception for s3 upload
---
 .../blob/objectstorage/aws/AwsS3ObjectStorage.java     | 18 +++++++++++++++---
 .../org/apache/james/MailsShouldBeWellReceived.java    |  1 -
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
index 56d58a3..f00be8b 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/aws/AwsS3ObjectStorage.java
@@ -61,8 +61,9 @@ public class AwsS3ObjectStorage {
     public static final int MAX_THREADS = 5;
     private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(MAX_THREADS, NamedThreadFactory.withClassName(AwsS3ObjectStorage.class));
     private static final boolean DO_NOT_SHUTDOWN_THREAD_POOL = false;
-    public static final int MAX_UPLOAD_THREADS = 5;
     private static final int MAX_ERROR_RETRY = 5;
+    private static final int FIRST_TRY = 0;
+    private static final int MAX_RETRY_ON_EXCEPTION = 3;
     public static Size MULTIPART_UPLOAD_THRESHOLD;
 
     static {
@@ -83,8 +84,7 @@ public class AwsS3ObjectStorage {
             try {
                 file = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
                 FileUtils.copyToFile(blob.getPayload().openStream(), file);
-
-                put(blobIdFactory, containerName, configuration, blob, file);
+                putWithRetry(blobIdFactory, containerName, configuration, blob, file, FIRST_TRY);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             } finally {
@@ -95,6 +95,18 @@ public class AwsS3ObjectStorage {
         });
     }
 
+    private static void putWithRetry(BlobId.Factory blobIdFactory, ContainerName containerName, AwsS3AuthConfiguration configuration, Blob blob, File file, int tried) {
+        try {
+            put(blobIdFactory, containerName, configuration, blob, file);
+        } catch (RuntimeException e) {
+            if (tried < MAX_RETRY_ON_EXCEPTION) {
+                putWithRetry(blobIdFactory, containerName, configuration, blob, file, tried + 1);
+            } else {
+                throw e;
+            }
+        }
+    }
+
     private static void put(BlobId.Factory blobIdFactory, ContainerName containerName, AwsS3AuthConfiguration configuration, Blob blob, File file) {
         try {
             PutObjectRequest request = new PutObjectRequest(containerName.value(),
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/MailsShouldBeWellReceived.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/MailsShouldBeWellReceived.java
index 16d3f54..9c8adbf 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/MailsShouldBeWellReceived.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/MailsShouldBeWellReceived.java
@@ -43,7 +43,6 @@ interface MailsShouldBeWellReceived {
         .and().pollDelay(ONE_HUNDRED_MILLISECONDS)
         .await();
 
-
     @Test
     default void mailsShouldBeWellReceived(GuiceJamesServer server) throws Exception {
         server.getProbe(DataProbeImpl.class).fluent()


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org