diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobContainer.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobContainer.java index b4322119dafa7..64f984c208d01 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobContainer.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobContainer.java @@ -53,7 +53,7 @@ public boolean blobExists(String blobName) { logger.trace("blobExists({})", blobName); try { return blobStore.blobExists(buildKey(blobName)); - } catch (URISyntaxException | StorageException e) { + } catch (URISyntaxException | StorageException | IOException e) { logger.warn("can not access [{}] in container {{}}: {}", blobName, blobStore, e.getMessage()); } return false; @@ -88,7 +88,6 @@ public InputStream readBlob(String blobName) throws IOException { @Override public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException { logger.trace("writeBlob({}, stream, {})", buildKey(blobName), blobSize); - try { blobStore.writeBlob(buildKey(blobName), inputStream, blobSize, failIfAlreadyExists); } catch (URISyntaxException|StorageException e) { diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java index 57b3003e069c7..98092f62985e2 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java @@ -20,7 +20,6 @@ package org.elasticsearch.repositories.azure; import com.microsoft.azure.storage.LocationMode; - import com.microsoft.azure.storage.StorageException; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.blobstore.BlobContainer; @@ -28,14 +27,13 @@ import org.elasticsearch.common.blobstore.BlobPath; import org.elasticsearch.common.blobstore.BlobStore; import org.elasticsearch.common.component.AbstractComponent; + import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; -import java.nio.file.FileAlreadyExistsException; import java.util.Map; import static java.util.Collections.emptyMap; - import static org.elasticsearch.repositories.azure.AzureRepository.Repository; public class AzureBlobStore extends AbstractComponent implements BlobStore { @@ -94,11 +92,11 @@ public void delete(BlobPath path) throws IOException { public void close() { } - public boolean blobExists(String blob) throws URISyntaxException, StorageException { + public boolean blobExists(String blob) throws URISyntaxException, StorageException, IOException { return service.blobExists(clientName, container, blob); } - public void deleteBlob(String blob) throws URISyntaxException, StorageException { + public void deleteBlob(String blob) throws URISyntaxException, StorageException, IOException { service.deleteBlob(clientName, container, blob); } @@ -107,12 +105,12 @@ public InputStream getInputStream(String blob) throws URISyntaxException, Storag } public Map listBlobsByPrefix(String keyPath, String prefix) - throws URISyntaxException, StorageException { + throws URISyntaxException, StorageException, IOException { return service.listBlobsByPrefix(clientName, container, keyPath, prefix); } public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) - throws URISyntaxException, StorageException, FileAlreadyExistsException { + throws URISyntaxException, StorageException, IOException { service.writeBlob(this.clientName, container, blobName, inputStream, blobSize, failIfAlreadyExists); } } diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java index 49ff50aef9048..821f6ab76c011 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java @@ -206,7 +206,7 @@ public InputStream getInputStream(String account, String container, String blob) } public Map listBlobsByPrefix(String account, String container, String keyPath, String prefix) - throws URISyntaxException, StorageException { + throws URISyntaxException, StorageException, IOException { // NOTE: this should be here: if (prefix == null) prefix = ""; // however, this is really inefficient since deleteBlobsByPrefix enumerates everything and // then does a prefix match on the result; it should just call listBlobsByPrefix with the prefix! @@ -233,8 +233,9 @@ public Map listBlobsByPrefix(String account, String contai } public void writeBlob(String account, String container, String blobName, InputStream inputStream, long blobSize, - boolean failIfAlreadyExists) - throws URISyntaxException, StorageException, FileAlreadyExistsException { + boolean failIfAlreadyExists) throws URISyntaxException, StorageException, IOException { + assert inputStream.markSupported() + : "Should not be used with non-mark supporting streams as their retry handling in the SDK is broken"; logger.trace(() -> new ParameterizedMessage("writeBlob({}, stream, {})", blobName, blobSize)); final Tuple> client = client(account); final CloudBlobContainer blobContainer = client.v1().getContainerReference(container); diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/SocketAccess.java b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/SocketAccess.java index da8b85430067c..6cb1f216d5f48 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/SocketAccess.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/SocketAccess.java @@ -20,6 +20,7 @@ package org.elasticsearch.repositories.azure; import com.microsoft.azure.storage.StorageException; +import org.apache.logging.log4j.core.util.Throwables; import org.elasticsearch.SpecialPermission; import java.io.IOException; @@ -44,7 +45,9 @@ public static T doPrivilegedIOException(PrivilegedExceptionAction operati try { return AccessController.doPrivileged(operation); } catch (PrivilegedActionException e) { - throw (IOException) e.getCause(); + Throwables.rethrow(e.getCause()); + assert false : "always throws"; + return null; } } @@ -53,7 +56,9 @@ public static T doPrivilegedException(PrivilegedExceptionAction operation try { return AccessController.doPrivileged(operation); } catch (PrivilegedActionException e) { - throw (StorageException) e.getCause(); + Throwables.rethrow(e.getCause()); + assert false : "always throws"; + return null; } } @@ -65,12 +70,7 @@ public static void doPrivilegedVoidException(StorageRunnable action) throws Stor return null; }); } catch (PrivilegedActionException e) { - Throwable cause = e.getCause(); - if (cause instanceof StorageException) { - throw (StorageException) cause; - } else { - throw (URISyntaxException) cause; - } + Throwables.rethrow(e.getCause()); } }