|
@@ -30,7 +30,6 @@ import com.google.cloud.storage.Storage;
|
|
|
import com.google.cloud.storage.Storage.BlobListOption;
|
|
|
import com.google.cloud.storage.StorageBatch;
|
|
|
import com.google.cloud.storage.StorageException;
|
|
|
-
|
|
|
import org.elasticsearch.common.SuppressForbidden;
|
|
|
import org.elasticsearch.common.blobstore.BlobContainer;
|
|
|
import org.elasticsearch.common.blobstore.BlobMetaData;
|
|
@@ -50,11 +49,11 @@ import java.nio.channels.ReadableByteChannel;
|
|
|
import java.nio.channels.WritableByteChannel;
|
|
|
import java.nio.file.FileAlreadyExistsException;
|
|
|
import java.nio.file.NoSuchFileException;
|
|
|
-import java.util.Map;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -132,13 +131,15 @@ class GoogleCloudStorageBlobStore implements BlobStore {
|
|
|
Map<String, BlobMetaData> listBlobsByPrefix(String path, String prefix) throws IOException {
|
|
|
final String pathPrefix = buildKey(path, prefix);
|
|
|
final MapBuilder<String, BlobMetaData> mapBuilder = MapBuilder.newMapBuilder();
|
|
|
- SocketAccess.doPrivilegedVoidIOException(() -> {
|
|
|
- client().get(bucketName).list(BlobListOption.prefix(pathPrefix)).iterateAll().forEach(blob -> {
|
|
|
- assert blob.getName().startsWith(path);
|
|
|
- final String suffixName = blob.getName().substring(path.length());
|
|
|
- mapBuilder.put(suffixName, new PlainBlobMetaData(suffixName, blob.getSize()));
|
|
|
- });
|
|
|
- });
|
|
|
+ SocketAccess.doPrivilegedVoidIOException(
|
|
|
+ () -> client().get(bucketName).list(BlobListOption.currentDirectory(), BlobListOption.prefix(pathPrefix)).iterateAll().forEach(
|
|
|
+ blob -> {
|
|
|
+ assert blob.getName().startsWith(path);
|
|
|
+ if (blob.isDirectory() == false) {
|
|
|
+ final String suffixName = blob.getName().substring(path.length());
|
|
|
+ mapBuilder.put(suffixName, new PlainBlobMetaData(suffixName, blob.getSize()));
|
|
|
+ }
|
|
|
+ }));
|
|
|
return mapBuilder.immutableMap();
|
|
|
}
|
|
|
|
|
@@ -150,7 +151,9 @@ class GoogleCloudStorageBlobStore implements BlobStore {
|
|
|
blob -> {
|
|
|
if (blob.isDirectory()) {
|
|
|
assert blob.getName().startsWith(pathStr);
|
|
|
- final String suffixName = blob.getName().substring(pathStr.length());
|
|
|
+ assert blob.getName().endsWith("/");
|
|
|
+ // Strip path prefix and trailing slash
|
|
|
+ final String suffixName = blob.getName().substring(pathStr.length(), blob.getName().length() - 1);
|
|
|
if (suffixName.isEmpty() == false) {
|
|
|
mapBuilder.put(suffixName, new GoogleCloudStorageBlobContainer(path.add(suffixName), this));
|
|
|
}
|
|
@@ -312,11 +315,6 @@ class GoogleCloudStorageBlobStore implements BlobStore {
|
|
|
if (blobNames.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
- // for a single op submit a simple delete instead of a batch of size 1
|
|
|
- if (blobNames.size() == 1) {
|
|
|
- deleteBlob(blobNames.iterator().next());
|
|
|
- return;
|
|
|
- }
|
|
|
final List<BlobId> blobIdsToDelete = blobNames.stream().map(blob -> BlobId.of(bucketName, blob)).collect(Collectors.toList());
|
|
|
final List<BlobId> failedBlobs = Collections.synchronizedList(new ArrayList<>());
|
|
|
final StorageException e = SocketAccess.doPrivilegedIOException(() -> {
|