Removes unnecessary blobExists() check before reading a blob in the
Azure and Google cloud blob containers, as the APIs for both return a 404 in the case of a missing object, which we already handle through a NoSuchFileFoundException.
This commit is contained in:
parent
a6f5e0b0fe
commit
299b8a7a52
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,14 +20,11 @@
|
|||
package org.elasticsearch.common.blobstore.support;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobContainer;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A base abstract blob container that implements higher level container methods.
|
||||
|
|
|
@ -71,10 +71,6 @@ public class AzureBlobContainer extends AbstractBlobContainer {
|
|||
public InputStream readBlob(String blobName) throws IOException {
|
||||
logger.trace("readBlob({})", blobName);
|
||||
|
||||
if (!blobExists(blobName)) {
|
||||
throw new NoSuchFileException("Blob [" + blobName + "] does not exist");
|
||||
}
|
||||
|
||||
try {
|
||||
return blobStore.getInputStream(blobStore.container(), buildKey(blobName));
|
||||
} catch (StorageException e) {
|
||||
|
|
|
@ -21,22 +21,19 @@ package org.elasticsearch.cloud.azure.storage;
|
|||
|
||||
import com.microsoft.azure.storage.LocationMode;
|
||||
import com.microsoft.azure.storage.StorageException;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -82,7 +79,7 @@ public class AzureStorageServiceMock extends AbstractComponent implements AzureS
|
|||
@Override
|
||||
public InputStream getInputStream(String account, LocationMode mode, String container, String blob) throws IOException {
|
||||
if (!blobExists(account, mode, container, blob)) {
|
||||
throw new FileNotFoundException("missing blob [" + blob + "]");
|
||||
throw new NoSuchFileException("missing blob [" + blob + "]");
|
||||
}
|
||||
return new ByteArrayInputStream(blobs.get(blob).toByteArray());
|
||||
}
|
||||
|
|
|
@ -22,11 +22,10 @@ package org.elasticsearch.repositories.azure;
|
|||
import com.microsoft.azure.storage.StorageException;
|
||||
import org.elasticsearch.cloud.azure.blobstore.AzureBlobStore;
|
||||
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceMock;
|
||||
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
|
||||
import org.elasticsearch.repositories.RepositoryName;
|
||||
import org.elasticsearch.repositories.RepositorySettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
@ -35,11 +34,9 @@ public class AzureBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
|
|||
@Override
|
||||
protected BlobStore newBlobStore() throws IOException {
|
||||
try {
|
||||
RepositoryName repositoryName = new RepositoryName("azure", "ittest");
|
||||
RepositorySettings repositorySettings = new RepositorySettings(
|
||||
Settings.EMPTY, Settings.EMPTY);
|
||||
AzureStorageServiceMock client = new AzureStorageServiceMock(Settings.EMPTY);
|
||||
return new AzureBlobStore(repositoryName, Settings.EMPTY, repositorySettings, client);
|
||||
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
|
||||
AzureStorageServiceMock client = new AzureStorageServiceMock();
|
||||
return new AzureBlobStore(repositoryMetaData, Settings.EMPTY, client);
|
||||
} catch (URISyntaxException | StorageException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
|
|
@ -189,9 +189,6 @@ public class GoogleCloudStorageBlobStore extends AbstractComponent implements Bl
|
|||
* @return an InputStream
|
||||
*/
|
||||
InputStream readBlob(String blobName) throws IOException {
|
||||
if (!blobExists(blobName)) {
|
||||
throw new NoSuchFileException("Blob [" + blobName + "] does not exist");
|
||||
}
|
||||
return doPrivileged(() -> {
|
||||
try {
|
||||
Storage.Objects.Get object = client.objects().get(bucket, blobName);
|
||||
|
|
Loading…
Reference in New Issue