Permalink
Browse files

no need for objectCount, we can use keys

  • Loading branch information...
kimchy committed Mar 7, 2012
1 parent bb222f0 commit b9368e2fc2684e515485f216fe85925cdeca8800
Showing with 2 additions and 5 deletions.
  1. +2 −5 src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java
@@ -100,7 +100,6 @@ public void delete(BlobPath path) {
ObjectListing prevListing = null;
//From http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingJava.html
//we can do at most 1K objects per delete
int objectCount = 0;
//We don't know the bucket name until first object listing
DeleteObjectsRequest multiObjectDeleteRequest = null;
ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>();
@@ -113,15 +112,13 @@ public void delete(BlobPath path) {
multiObjectDeleteRequest = new DeleteObjectsRequest(list.getBucketName());
}
for (S3ObjectSummary summary : list.getObjectSummaries()) {
objectCount++;
keys.add(new KeyVersion(summary.getKey()));
//Every 500 objects batch the delete request
if (objectCount > 500) {
if (keys.size() > 500) {
multiObjectDeleteRequest.setKeys(keys);
client.deleteObjects(multiObjectDeleteRequest);
multiObjectDeleteRequest = new DeleteObjectsRequest(list.getBucketName());
keys.clear();
objectCount = 0;
}
}
if (list.isTruncated()) {
@@ -130,7 +127,7 @@ public void delete(BlobPath path) {
break;
}
}
if (objectCount > 0) {
if (!keys.isEmpty()) {
multiObjectDeleteRequest.setKeys(keys);
client.deleteObjects(multiObjectDeleteRequest);
}

0 comments on commit b9368e2

Please sign in to comment.