Skip to content

Commit 4b8fd4e

Browse files
Remove blobExists Method from BlobContainer (#44472)
* We only use this method in one place in production code and can replace that with a read -> remove it to simplify the interface * Keep it as an implementation detail in the Azure repository
1 parent 2b65489 commit 4b8fd4e

18 files changed

Lines changed: 32 additions & 90 deletions

File tree

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ public void delete() {
101101
throw new UnsupportedOperationException("URL repository is read only");
102102
}
103103

104-
/**
105-
* This operation is not supported by URLBlobContainer
106-
*/
107-
@Override
108-
public boolean blobExists(String blobName) {
109-
throw new UnsupportedOperationException("URL repository doesn't support this operation");
110-
}
111-
112104
@Override
113105
public InputStream readBlob(String name) throws IOException {
114106
try {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public class AzureBlobContainer extends AbstractBlobContainer {
5757
this.threadPool = threadPool;
5858
}
5959

60-
@Override
61-
public boolean blobExists(String blobName) {
60+
private boolean blobExists(String blobName) {
6261
logger.trace("blobExists({})", blobName);
6362
try {
6463
return blobStore.blobExists(buildKey(blobName));

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.common.blobstore.BlobContainer;
2323
import org.elasticsearch.common.blobstore.BlobMetaData;
2424
import org.elasticsearch.common.blobstore.BlobPath;
25-
import org.elasticsearch.common.blobstore.BlobStoreException;
2625
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
2726

2827
import java.io.IOException;
@@ -42,15 +41,6 @@ class GoogleCloudStorageBlobContainer extends AbstractBlobContainer {
4241
this.path = path.buildAsString();
4342
}
4443

45-
@Override
46-
public boolean blobExists(String blobName) {
47-
try {
48-
return blobStore.blobExists(buildKey(blobName));
49-
} catch (Exception e) {
50-
throw new BlobStoreException("Failed to check if blob [" + blobName + "] exists", e);
51-
}
52-
}
53-
5444
@Override
5545
public Map<String, BlobMetaData> listBlobs() throws IOException {
5646
return blobStore.listBlobs(path);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,6 @@ Map<String, BlobContainer> listChildren(BlobPath path) throws IOException {
163163
return mapBuilder.immutableMap();
164164
}
165165

166-
/**
167-
* Returns true if the blob exists in the specific bucket
168-
*
169-
* @param blobName name of the blob
170-
* @return true iff the blob exists
171-
*/
172-
boolean blobExists(String blobName) throws IOException {
173-
final BlobId blobId = BlobId.of(bucketName, blobName);
174-
final Blob blob = SocketAccess.doPrivilegedIOException(() -> client().get(blobId));
175-
return blob != null;
176-
}
177-
178166
/**
179167
* Returns an {@link java.io.InputStream} for the given blob name
180168
*

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ final class HdfsBlobContainer extends AbstractBlobContainer {
5858
this.bufferSize = bufferSize;
5959
}
6060

61-
@Override
62-
public boolean blobExists(String blobName) {
63-
try {
64-
return store.execute(fileContext -> fileContext.util().exists(new Path(path, blobName)));
65-
} catch (Exception e) {
66-
return false;
67-
}
68-
}
69-
7061
@Override
7162
public void deleteBlob(String blobName) throws IOException {
7263
try {

plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsBlobStoreContainerTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.common.blobstore.BlobStore;
3232
import org.elasticsearch.common.bytes.BytesArray;
3333
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
34+
import org.elasticsearch.repositories.blobstore.BlobStoreTestUtil;
3435

3536
import javax.security.auth.Subject;
3637
import java.io.IOException;
@@ -137,6 +138,6 @@ public void testReadOnly() throws Exception {
137138
byte[] data = randomBytes(randomIntBetween(10, scaledRandomIntBetween(1024, 1 << 16)));
138139
writeBlob(container, "foo", new BytesArray(data), randomBoolean());
139140
assertArrayEquals(readBlobFully(container, "foo", data.length), data);
140-
assertTrue(container.blobExists("foo"));
141+
assertTrue(BlobStoreTestUtil.blobExists(container, "foo"));
141142
}
142143
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.elasticsearch.common.blobstore.BlobContainer;
4343
import org.elasticsearch.common.blobstore.BlobMetaData;
4444
import org.elasticsearch.common.blobstore.BlobPath;
45-
import org.elasticsearch.common.blobstore.BlobStoreException;
4645
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
4746
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
4847
import org.elasticsearch.common.collect.Tuple;
@@ -79,15 +78,6 @@ class S3BlobContainer extends AbstractBlobContainer {
7978
this.keyPath = path.buildAsString();
8079
}
8180

82-
@Override
83-
public boolean blobExists(String blobName) {
84-
try (AmazonS3Reference clientReference = blobStore.clientReference()) {
85-
return SocketAccess.doPrivileged(() -> clientReference.client().doesObjectExist(blobStore.bucket(), buildKey(blobName)));
86-
} catch (final Exception e) {
87-
throw new BlobStoreException("Failed to check if blob [" + blobName +"] exists", e);
88-
}
89-
}
90-
9181
@Override
9282
public InputStream readBlob(String blobName) throws IOException {
9383
try (AmazonS3Reference clientReference = blobStore.clientReference()) {

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ public interface BlobContainer {
3838
*/
3939
BlobPath path();
4040

41-
/**
42-
* Tests whether a blob with the given blob name exists in the container.
43-
*
44-
* @param blobName
45-
* The name of the blob whose existence is to be determined.
46-
* @return {@code true} if a blob exists in the {@link BlobContainer} with the given name, and {@code false} otherwise.
47-
*/
48-
boolean blobExists(String blobName);
49-
5041
/**
5142
* Creates a new {@link InputStream} for the given blob name.
5243
*

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ public void delete() throws IOException {
127127
IOUtils.rm(path);
128128
}
129129

130-
@Override
131-
public boolean blobExists(String blobName) {
132-
return Files.exists(path.resolve(blobName));
133-
}
134-
135130
@Override
136131
public InputStream readBlob(String name) throws IOException {
137132
final Path resolvedPath = path.resolve(name);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ public void verify(String seed, DiscoveryNode localNode) {
10331033
}
10341034
} else {
10351035
BlobContainer testBlobContainer = blobStore().blobContainer(basePath().add(testBlobPrefix(seed)));
1036-
if (testBlobContainer.blobExists("master.dat")) {
1036+
try (InputStream ignored = testBlobContainer.readBlob("master.dat")) {
10371037
try {
10381038
BytesArray bytes = new BytesArray(seed);
10391039
try (InputStream stream = bytes.streamInput()) {
@@ -1043,11 +1043,13 @@ public void verify(String seed, DiscoveryNode localNode) {
10431043
throw new RepositoryVerificationException(metadata.name(), "store location [" + blobStore() +
10441044
"] is not accessible on the node [" + localNode + "]", exp);
10451045
}
1046-
} else {
1046+
} catch (NoSuchFileException e) {
10471047
throw new RepositoryVerificationException(metadata.name(), "a file written by master to the store [" + blobStore() +
10481048
"] cannot be accessed on the node [" + localNode + "]. " +
10491049
"This might indicate that the store [" + blobStore() + "] is not shared between this node and the master node or " +
1050-
"that permissions on the store don't allow reading files written by the master node");
1050+
"that permissions on the store don't allow reading files written by the master node", e);
1051+
} catch (IOException e) {
1052+
throw new RepositoryVerificationException(metadata.name(), "Failed to verify repository", e);
10511053
}
10521054
}
10531055
}

0 commit comments

Comments
 (0)