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.
This commit is contained in:
Andrew Gaul 2011-12-14 13:40:58 -08:00
parent 993cd08bbc
commit 4c7637bcac
1 changed files with 13 additions and 12 deletions

View File

@ -91,8 +91,13 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
if (options.isRecursive()) if (options.isRecursive())
message = message + " recursively"; message = message + " recursively";
Map<StorageMetadata, Exception> exceptions = Maps.newHashMap(); Map<StorageMetadata, Exception> exceptions = Maps.newHashMap();
Iterable<? extends StorageMetadata> toDelete = getResourcesToDelete(containerName, options); Iterable<? extends StorageMetadata> toDelete;
for (int i = 0; i < 3; i++) { // TODO parameterize for (int i = 0; i < 3; i++) { // TODO parameterize
toDelete = getResourcesToDelete(containerName, options);
if (Iterables.isEmpty(toDelete)) {
break;
}
Map<StorageMetadata, Future<?>> responses = Maps.newHashMap(); Map<StorageMetadata, Future<?>> responses = Maps.newHashMap();
try { try {
for (final StorageMetadata md : toDelete) { for (final StorageMetadata md : toDelete) {
@ -120,19 +125,15 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr
} }
} finally { } finally {
exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, message); exceptions = awaitCompletion(responses, userExecutor, maxTime, logger, message);
toDelete = getResourcesToDelete(containerName, options); }
if (Iterables.size(toDelete) == 0) { if (!exceptions.isEmpty()) {
break; retryHandler.imposeBackoffExponentialDelay(i + 1, message);
}
if (exceptions.size() > 0) {
toDelete = Iterables.concat(exceptions.keySet(), toDelete);
retryHandler.imposeBackoffExponentialDelay(i + 1, message);
}
} }
} }
if (exceptions.size() > 0) if (!exceptions.isEmpty())
throw new BlobRuntimeException(String.format("error %s: %s", message, exceptions)); 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); toDelete);
} }