From b9368e2fc2684e515485f216fe85925cdeca8800 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Wed, 7 Mar 2012 22:08:58 +0200 Subject: [PATCH] no need for objectCount, we can use keys --- .../org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java b/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java index c6af86cef87..6bf8cf149ed 100644 --- a/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java +++ b/src/main/java/org/elasticsearch/cloud/aws/blobstore/S3BlobStore.java @@ -100,7 +100,6 @@ public class S3BlobStore extends AbstractComponent implements BlobStore { 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 keys = new ArrayList(); @@ -113,15 +112,13 @@ public class S3BlobStore extends AbstractComponent implements BlobStore { 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 class S3BlobStore extends AbstractComponent implements BlobStore { break; } } - if (objectCount > 0) { + if (!keys.isEmpty()) { multiObjectDeleteRequest.setKeys(keys); client.deleteObjects(multiObjectDeleteRequest); }