Skip to content

Commit c4f4402

Browse files
Remove Delete Method from BlobStore (#41619) (#42574)
* Remove Delete Method from BlobStore (#41619) * The delete method on the blob store was used almost nowhere and just duplicates the delete method on the blob containers * The fact that it provided for some recursive delete logic (that did not behave the same way on all implementations) was not used and not properly tested either
1 parent bb7e8eb commit c4f4402

File tree

10 files changed

+5
-131
lines changed

10 files changed

+5
-131
lines changed

modules/repository-url/src/main/java/org/elasticsearch/common/blobstore/url/URLBlobStore.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public URLBlobStore(Settings settings, URL path) {
5757
new ByteSizeValue(100, ByteSizeUnit.KB)).getBytes();
5858
}
5959

60-
/**
61-
* {@inheritDoc}
62-
*/
6360
@Override
6461
public String toString() {
6562
return path.toString();
@@ -83,9 +80,6 @@ public int bufferSizeInBytes() {
8380
return this.bufferSizeInBytes;
8481
}
8582

86-
/**
87-
* {@inheritDoc}
88-
*/
8983
@Override
9084
public BlobContainer blobContainer(BlobPath path) {
9185
try {
@@ -95,17 +89,6 @@ public BlobContainer blobContainer(BlobPath path) {
9589
}
9690
}
9791

98-
/**
99-
* This operation is not supported by URL Blob Store
100-
*/
101-
@Override
102-
public void delete(BlobPath path) {
103-
throw new UnsupportedOperationException("URL repository is read only");
104-
}
105-
106-
/**
107-
* {@inheritDoc}
108-
*/
10992
@Override
11093
public void close() {
11194
// nothing to do here...

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import com.microsoft.azure.storage.LocationMode;
2323
import com.microsoft.azure.storage.StorageException;
2424

25-
import org.apache.logging.log4j.LogManager;
26-
import org.apache.logging.log4j.Logger;
2725
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
2826
import org.elasticsearch.common.blobstore.BlobContainer;
2927
import org.elasticsearch.common.blobstore.BlobMetaData;
@@ -40,8 +38,6 @@
4038
import static java.util.Collections.emptyMap;
4139

4240
public class AzureBlobStore implements BlobStore {
43-
44-
private static final Logger logger = LogManager.getLogger(AzureBlobStore.class);
4541

4642
private final AzureStorageService service;
4743

@@ -82,17 +78,6 @@ public BlobContainer blobContainer(BlobPath path) {
8278
return new AzureBlobContainer(path, this);
8379
}
8480

85-
@Override
86-
public void delete(BlobPath path) throws IOException {
87-
final String keyPath = path.buildAsString();
88-
try {
89-
service.deleteFiles(clientName, container, keyPath);
90-
} catch (URISyntaxException | StorageException e) {
91-
logger.warn("cannot access [{}] in container {{}}: {}", keyPath, container, e.getMessage());
92-
throw new IOException(e);
93-
}
94-
}
95-
9681
@Override
9782
public void close() {
9883
}

plugins/repository-gcs/src/main/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStore.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
import java.nio.channels.WritableByteChannel;
5151
import java.nio.file.FileAlreadyExistsException;
5252
import java.nio.file.NoSuchFileException;
53+
import java.util.Map;
5354
import java.util.ArrayList;
5455
import java.util.Collection;
5556
import java.util.Collections;
5657
import java.util.List;
57-
import java.util.Map;
5858
import java.util.concurrent.atomic.AtomicReference;
5959
import java.util.stream.Collectors;
6060

@@ -91,11 +91,6 @@ public BlobContainer blobContainer(BlobPath path) {
9191
return new GoogleCloudStorageBlobContainer(path, this);
9292
}
9393

94-
@Override
95-
public void delete(BlobPath path) throws IOException {
96-
deleteBlobsByPrefix(path.buildAsString());
97-
}
98-
9994
@Override
10095
public void close() {
10196
}
@@ -291,15 +286,6 @@ void deleteBlob(String blobName) throws IOException {
291286
}
292287
}
293288

294-
/**
295-
* Deletes multiple blobs from the specific bucket all of which have prefixed names
296-
*
297-
* @param prefix prefix of the blobs to delete
298-
*/
299-
private void deleteBlobsByPrefix(String prefix) throws IOException {
300-
deleteBlobsIgnoringIfNotExists(listBlobsByPrefix("", prefix).keySet());
301-
}
302-
303289
/**
304290
* Deletes multiple blobs from the specific bucket using a batch request
305291
*

plugins/repository-hdfs/src/main/java/org/elasticsearch/repositories/hdfs/HdfsBlobStore.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,6 @@ private void mkdirs(Path path) throws IOException {
6666
});
6767
}
6868

69-
@Override
70-
public void delete(BlobPath path) throws IOException {
71-
execute((Operation<Void>) fc -> {
72-
fc.delete(translateToHdfsPath(path), true);
73-
return null;
74-
});
75-
}
76-
7769
@Override
7870
public String toString() {
7971
return root.toUri().toString();

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3BlobStore.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
package org.elasticsearch.repositories.s3;
2121

2222
import com.amazonaws.services.s3.model.CannedAccessControlList;
23-
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
24-
import com.amazonaws.services.s3.model.DeleteObjectsRequest.KeyVersion;
25-
import com.amazonaws.services.s3.model.ObjectListing;
26-
import com.amazonaws.services.s3.model.S3ObjectSummary;
2723
import com.amazonaws.services.s3.model.StorageClass;
2824
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
2925
import org.elasticsearch.common.blobstore.BlobContainer;
@@ -33,7 +29,6 @@
3329
import org.elasticsearch.common.unit.ByteSizeValue;
3430

3531
import java.io.IOException;
36-
import java.util.ArrayList;
3732
import java.util.Locale;
3833

3934
class S3BlobStore implements BlobStore {
@@ -90,50 +85,6 @@ public BlobContainer blobContainer(BlobPath path) {
9085
return new S3BlobContainer(path, this);
9186
}
9287

93-
@Override
94-
public void delete(BlobPath path) {
95-
try (AmazonS3Reference clientReference = clientReference()) {
96-
ObjectListing prevListing = null;
97-
// From
98-
// http://docs.amazonwebservices.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingJava.html
99-
// we can do at most 1K objects per delete
100-
// We don't know the bucket name until first object listing
101-
DeleteObjectsRequest multiObjectDeleteRequest = null;
102-
final ArrayList<KeyVersion> keys = new ArrayList<>();
103-
while (true) {
104-
ObjectListing list;
105-
if (prevListing != null) {
106-
final ObjectListing finalPrevListing = prevListing;
107-
list = SocketAccess.doPrivileged(() -> clientReference.client().listNextBatchOfObjects(finalPrevListing));
108-
} else {
109-
list = SocketAccess.doPrivileged(() -> clientReference.client().listObjects(bucket, path.buildAsString()));
110-
multiObjectDeleteRequest = new DeleteObjectsRequest(list.getBucketName());
111-
}
112-
for (final S3ObjectSummary summary : list.getObjectSummaries()) {
113-
keys.add(new KeyVersion(summary.getKey()));
114-
// Every 500 objects batch the delete request
115-
if (keys.size() > 500) {
116-
multiObjectDeleteRequest.setKeys(keys);
117-
final DeleteObjectsRequest finalMultiObjectDeleteRequest = multiObjectDeleteRequest;
118-
SocketAccess.doPrivilegedVoid(() -> clientReference.client().deleteObjects(finalMultiObjectDeleteRequest));
119-
multiObjectDeleteRequest = new DeleteObjectsRequest(list.getBucketName());
120-
keys.clear();
121-
}
122-
}
123-
if (list.isTruncated()) {
124-
prevListing = list;
125-
} else {
126-
break;
127-
}
128-
}
129-
if (!keys.isEmpty()) {
130-
multiObjectDeleteRequest.setKeys(keys);
131-
final DeleteObjectsRequest finalMultiObjectDeleteRequest = multiObjectDeleteRequest;
132-
SocketAccess.doPrivilegedVoid(() -> clientReference.client().deleteObjects(finalMultiObjectDeleteRequest));
133-
}
134-
}
135-
}
136-
13788
@Override
13889
public void close() throws IOException {
13990
this.service.close();

server/src/main/java/org/elasticsearch/common/blobstore/BlobStore.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.elasticsearch.common.blobstore;
2020

2121
import java.io.Closeable;
22-
import java.io.IOException;
2322

2423
/**
2524
* An interface for storing blobs.
@@ -30,10 +29,4 @@ public interface BlobStore extends Closeable {
3029
* Get a blob container instance for storing blobs at the given {@link BlobPath}.
3130
*/
3231
BlobContainer blobContainer(BlobPath path);
33-
34-
/**
35-
* Delete the blob store at the given {@link BlobPath}.
36-
*/
37-
void delete(BlobPath path) throws IOException;
38-
3932
}

server/src/main/java/org/elasticsearch/common/blobstore/fs/FsBlobStore.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.common.blobstore.fs;
2121

22-
import org.elasticsearch.core.internal.io.IOUtils;
2322
import org.elasticsearch.ElasticsearchException;
2423
import org.elasticsearch.common.blobstore.BlobContainer;
2524
import org.elasticsearch.common.blobstore.BlobPath;
@@ -72,16 +71,6 @@ public BlobContainer blobContainer(BlobPath path) {
7271
}
7372
}
7473

75-
@Override
76-
public void delete(BlobPath path) throws IOException {
77-
assert readOnly == false : "should not delete anything from a readonly repository: " + path;
78-
//noinspection ConstantConditions in case assertions are disabled
79-
if (readOnly) {
80-
throw new ElasticsearchException("unexpectedly deleting [" + path + "] from a readonly repository");
81-
}
82-
IOUtils.rm(buildPath(path));
83-
}
84-
8574
@Override
8675
public void close() {
8776
// nothing to do here...

server/src/main/java/org/elasticsearch/repositories/blobstore/BlobStoreRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,10 @@ public String startVerification() {
629629
public void endVerification(String seed) {
630630
if (isReadOnly() == false) {
631631
try {
632-
blobStore().delete(basePath().add(testBlobPrefix(seed)));
632+
final String testPrefix = testBlobPrefix(seed);
633+
final BlobContainer container = blobStore().blobContainer(basePath().add(testPrefix));
634+
container.deleteBlobsIgnoringIfNotExists(new ArrayList<>(container.listBlobs().keySet()));
635+
blobStore().blobContainer(basePath()).deleteBlobIgnoringIfNotExists(testPrefix);
633636
} catch (IOException exp) {
634637
throw new RepositoryVerificationException(metadata.name(), "cannot delete test data at " + basePath(), exp);
635638
}

server/src/test/java/org/elasticsearch/snapshots/mockstore/BlobStoreWrapper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ public BlobContainer blobContainer(BlobPath path) {
3737
return delegate.blobContainer(path);
3838
}
3939

40-
@Override
41-
public void delete(BlobPath path) throws IOException {
42-
delegate.delete(path);
43-
}
44-
4540
@Override
4641
public void close() throws IOException {
4742
delegate.close();

test/framework/src/main/java/org/elasticsearch/repositories/ESBlobStoreTestCase.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public void testContainerCreationAndDeletion() throws IOException {
4949

5050
assertTrue(containerFoo.blobExists("test"));
5151
assertTrue(containerBar.blobExists("test"));
52-
store.delete(new BlobPath());
53-
assertFalse(containerFoo.blobExists("test"));
54-
assertFalse(containerBar.blobExists("test"));
5552
}
5653
}
5754

0 commit comments

Comments
 (0)