Skip to content

Commit

Permalink
Refactor storage batches to use StorageBatchRequest and BatchResult (#…
Browse files Browse the repository at this point in the history
…952)

* Refactor storage batches to use StorageBatchRequest and BatchResult

* Limit batch size (storage performs better if the batches are split)
  • Loading branch information
mziccard committed May 20, 2016
1 parent 4c0332e commit e921bbe
Show file tree
Hide file tree
Showing 18 changed files with 1,192 additions and 1,090 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
import com.google.cloud.storage.Storage.BucketTargetOption;
import com.google.cloud.storage.spi.StorageRpc;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -609,19 +608,28 @@ public Blob get(String blob, BlobGetOption... options) {
* @throws StorageException upon failure
*/
public List<Blob> get(String blobName1, String blobName2, String... blobNames) {
BatchRequest.Builder batch = BatchRequest.builder();
batch.get(name(), blobName1);
batch.get(name(), blobName2);
for (String name : blobNames) {
batch.get(name(), name);
}
List<Blob> blobs = new ArrayList<>(blobNames.length);
BatchResponse response = storage.submit(batch.build());
for (BatchResponse.Result<Blob> result : response.gets()) {
BlobInfo blobInfo = result.get();
blobs.add(blobInfo != null ? new Blob(storage, new BlobInfo.BuilderImpl(blobInfo)) : null);
}
return Collections.unmodifiableList(blobs);
List<BlobId> blobIds = Lists.newArrayListWithCapacity(blobNames.length + 2);
blobIds.add(BlobId.of(name(), blobName1));
blobIds.add(BlobId.of(name(), blobName2));
for (String blobName : blobNames) {
blobIds.add(BlobId.of(name(), blobName));
}
return storage.get(blobIds);
}

/**
* Returns a list of requested blobs in this bucket. Blobs that do not exist are null.
*
* @param blobNames blobs to get
* @return an immutable list of {@code Blob} objects
* @throws StorageException upon failure
*/
public List<Blob> get(Iterable<String> blobNames) {
ImmutableList.Builder<BlobId> builder = ImmutableList.builder();
for (String blobName : blobNames) {
builder.add(BlobId.of(name(), blobName));
}
return storage.get(builder.build());
}

/**
Expand Down
Loading

0 comments on commit e921bbe

Please sign in to comment.