diff --git a/src/main/java/com/instaclustr/esop/impl/backup/UploadTracker.java b/src/main/java/com/instaclustr/esop/impl/backup/UploadTracker.java index 533d368..ec0fda2 100644 --- a/src/main/java/com/instaclustr/esop/impl/backup/UploadTracker.java +++ b/src/main/java/com/instaclustr/esop/impl/backup/UploadTracker.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.nio.file.Path; import java.util.Collection; +import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; @@ -116,36 +117,41 @@ public Void call() { final RemoteObjectReference ref = getRemoteObjectReference(manifestEntry.objectKey); - if (manifestEntry.type != MANIFEST_FILE) { - if (getRetrier(backuper.request.retry).submit(() -> backuper.freshenRemoteObject(manifestEntry, ref) == FRESHENED)) { - logger.info(format("%sskipping the upload of already uploaded file %s", - snapshotTag != null ? "Snapshot " + snapshotTag + " - " : "", - ref.canonicalPath)); - - state = State.FINISHED; - return null; + // try to refresh object / decide if it is required to upload it + Callable condition = () -> { + try { + return backuper.freshenRemoteObject(manifestEntry, ref) == FRESHENED; + } catch (final Exception ex) { + throw new RetriableException("Failed to refresh remote object" + ref.objectKey, ex); } + }; + + if (manifestEntry.type != MANIFEST_FILE && getRetrier(backuper.request.retry).submit(condition)) { + logger.info("{}skipping the upload of alredy uploaded file {}", + snapshotTag != null ? "Snapshot " + snapshotTag + " - " : "", + ref.canonicalPath); + + state = State.FINISHED; + return null; } - getRetrier(backuper.request.retry).submit(new Runnable() { - @Override - public void run() { - try (final InputStream fileStream = new BufferedInputStream(new FileInputStream(manifestEntry.localFile.toFile()))) { - final InputStream rateLimitedStream = getUploadingInputStreamFunction(backuper.request).apply(fileStream); - - logger.debug(format("%suploading file '%s' (%s).", - snapshotTag != null ? "Snapshot " + snapshotTag + " - " : "", - manifestEntry.objectKey, - DataSize.bytesToHumanReadable(manifestEntry.size))); - // never encrypt manifest - if (manifestEntry.type == MANIFEST_FILE) { - backuper.uploadFile(manifestEntry, rateLimitedStream, ref); - } else { - backuper.uploadEncryptedFile(manifestEntry, rateLimitedStream, ref); - } - } catch (final Exception ex) { - throw new RetriableException(String.format("Retrying upload of %s", manifestEntry.objectKey), ex); + // do the upload + getRetrier(backuper.request.retry).submit(() -> { + try (final InputStream fileStream = new BufferedInputStream(new FileInputStream(manifestEntry.localFile.toFile()))) { + final InputStream rateLimitedStream = getUploadingInputStreamFunction(backuper.request).apply(fileStream); + + logger.debug(format("%suploading file '%s' (%s).", + snapshotTag != null ? "Snapshot " + snapshotTag + " - " : "", + manifestEntry.objectKey, + DataSize.bytesToHumanReadable(manifestEntry.size))); + // never encrypt manifest + if (manifestEntry.type == MANIFEST_FILE) { + backuper.uploadFile(manifestEntry, rateLimitedStream, ref); + } else { + backuper.uploadEncryptedFile(manifestEntry, rateLimitedStream, ref); } + } catch (final Exception ex) { + throw new RetriableException(String.format("Retrying upload of %s", manifestEntry.objectKey), ex); } }); diff --git a/src/main/java/com/instaclustr/esop/impl/retry/Retrier.java b/src/main/java/com/instaclustr/esop/impl/retry/Retrier.java index e4fbb04..386be08 100644 --- a/src/main/java/com/instaclustr/esop/impl/retry/Retrier.java +++ b/src/main/java/com/instaclustr/esop/impl/retry/Retrier.java @@ -46,7 +46,7 @@ public T submit(final Callable c) throws Exception { if (attempts > maxAttempts) { throw ex; } - logger.error("This operation will be retried: " + ex.getMessage(), ex); + logger.error("This operation will be retried: " + ex.getMessage()); sleeper.sleep(); } else { throw ex; @@ -70,7 +70,7 @@ public void submit(final Runnable r) { if (attempts > maxAttempts) { throw ex; } - logger.error("This operation will be retried: " + ex.getMessage(), ex); + logger.error("This operation will be retried: " + ex.getMessage()); sleeper.sleep(); } else { throw ex; diff --git a/src/main/java/com/instaclustr/esop/s3/v2/BaseS3Backuper.java b/src/main/java/com/instaclustr/esop/s3/v2/BaseS3Backuper.java index 5340687..c4e3d73 100644 --- a/src/main/java/com/instaclustr/esop/s3/v2/BaseS3Backuper.java +++ b/src/main/java/com/instaclustr/esop/s3/v2/BaseS3Backuper.java @@ -43,6 +43,7 @@ import software.amazon.awssdk.services.s3.model.NoSuchUploadException; import software.amazon.awssdk.services.s3.model.ObjectAttributes; import software.amazon.awssdk.services.s3.model.PutObjectRequest; +import software.amazon.awssdk.services.s3.model.S3Exception; import software.amazon.awssdk.services.s3.model.SdkPartType; import software.amazon.awssdk.services.s3.model.StorageClass; import software.amazon.awssdk.services.s3.model.Tag; @@ -107,7 +108,7 @@ public FreshenResult freshenRemoteObject(ManifestEntry manifestEntry, RemoteObje .key(object.canonicalPath) .build()).tagSet(); } - catch (NoSuchKeyException ex) { + catch (S3Exception ex) { return FreshenResult.UPLOAD_REQUIRED; }