From 4c7637bcac6e8b31b16f1af603cee82818325b13 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Wed, 14 Dec 2011 13:40:58 -0800 Subject: [PATCH] Clean up DeleteAllKeysInList.execute Simplify control flow and execute getResourcesToDelete after imposeBackoffExponentialDelay. Impose backoff only on unexceptional path. Do not concatenate exceptions with toDelete since getResourcesToDelete will pick these up. Prefer isEmpty over size. --- .../internal/DeleteAllKeysInList.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java index 86470b5685..c7a5881354 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java @@ -91,8 +91,13 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr if (options.isRecursive()) message = message + " recursively"; Map exceptions = Maps.newHashMap(); - Iterable toDelete = getResourcesToDelete(containerName, options); + Iterable toDelete; for (int i = 0; i < 3; i++) { // TODO parameterize + toDelete = getResourcesToDelete(containerName, options); + if (Iterables.isEmpty(toDelete)) { + break; + } + Map> responses = Maps.newHashMap(); try { for (final StorageMetadata md : toDelete) { @@ -120,19 +125,15 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr } } finally { exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, message); - toDelete = getResourcesToDelete(containerName, options); - if (Iterables.size(toDelete) == 0) { - break; - } - if (exceptions.size() > 0) { - toDelete = Iterables.concat(exceptions.keySet(), toDelete); - retryHandler.imposeBackoffExponentialDelay(i + 1, message); - } + } + if (!exceptions.isEmpty()) { + retryHandler.imposeBackoffExponentialDelay(i + 1, message); } } - if (exceptions.size() > 0) + if (!exceptions.isEmpty()) throw new BlobRuntimeException(String.format("error %s: %s", message, exceptions)); - assert Iterables.size(toDelete) == 0 : String.format("items remaining %s: %s", message, + toDelete = getResourcesToDelete(containerName, options); + assert Iterables.isEmpty(toDelete) : String.format("items remaining %s: %s", message, toDelete); } @@ -163,4 +164,4 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr return toDelete; } -} \ No newline at end of file +}