Merge pull request #245 from andrewgaul/deleta-all-keys-cleanup

Clean up DeleteAllKeysInList.execute
This commit is contained in:
Adrian Cole 2011-12-14 14:09:27 -08:00
commit 81d9a0afcd
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) {
break;
} }
if (exceptions.size() > 0) { if (!exceptions.isEmpty()) {
toDelete = Iterables.concat(exceptions.keySet(), toDelete);
retryHandler.imposeBackoffExponentialDelay(i + 1, message); retryHandler.imposeBackoffExponentialDelay(i + 1, message);
} }
} }
} if (!exceptions.isEmpty())
if (exceptions.size() > 0)
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);
} }