use of com.google.storage.v2.StorageGrpc.StorageBlockingStub in project hadoop-connectors by GoogleCloudDataproc.
the class GoogleCloudStorageGrpcReadChannel method requestObjectMedia.
private Iterator<ReadObjectResponse> requestObjectMedia(String objectName, long objectGeneration, long offset, OptionalLong bytesToRead) throws StatusRuntimeException {
ReadObjectRequest.Builder requestBuilder = ReadObjectRequest.newBuilder().setBucket(GrpcChannelUtils.toV2BucketName(resourceId.getBucketName())).setObject(objectName).setGeneration(objectGeneration).setReadOffset(offset);
bytesToRead.ifPresent(requestBuilder::setReadLimit);
ReadObjectRequest request = requestBuilder.build();
requestContext = Context.current().withCancellation();
Context toReattach = requestContext.attach();
StorageBlockingStub blockingStub = stub.withDeadlineAfter(readOptions.getGrpcReadTimeoutMillis(), MILLISECONDS);
Iterator<ReadObjectResponse> readObjectResponseIterator;
try {
if (useZeroCopyMarshaller) {
Iterator<ReadObjectResponse> responseIterator = ClientCalls.blockingServerStreamingCall(blockingStub.getChannel(), getObjectMediaMethod, blockingStub.getCallOptions(), request);
readObjectResponseIterator = watchdog.watch(requestContext, responseIterator, Duration.ofMillis(this.gRPCReadMessageTimeout));
} else {
readObjectResponseIterator = watchdog.watch(requestContext, blockingStub.readObject(request), Duration.ofMillis(this.gRPCReadMessageTimeout));
}
} finally {
requestContext.detach(toReattach);
}
return readObjectResponseIterator;
}
use of com.google.storage.v2.StorageGrpc.StorageBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.
the class GrpcClient method makeRandomReadRequest.
private void makeRandomReadRequest(ManagedChannel channel, ResultTable results, int threadId) {
StorageBlockingStub blockingStub = StorageGrpc.newBlockingStub(channel);
if (creds != null) {
blockingStub = blockingStub.withCallCredentials(MoreCallCredentials.from(creds));
}
String object = objectResolver.Resolve(threadId, /*objectId=*/
0);
ReadObjectRequest.Builder reqBuilder = ReadObjectRequest.newBuilder().setBucket(toV2BucketName(args.bkt)).setObject(object);
Random r = new Random();
long buffSize = args.buffSize * 1024;
byte[] scratch = new byte[4 * 1024 * 1024];
for (int i = 0; i < args.calls; i++) {
long offset = (long) r.nextInt(args.size - args.buffSize) * 1024;
reqBuilder.setReadOffset(offset);
reqBuilder.setReadLimit(buffSize);
ReadObjectRequest req = reqBuilder.build();
long start = System.currentTimeMillis();
Iterator<ReadObjectResponse> resIterator = blockingStub.readObject(req);
while (resIterator.hasNext()) {
ReadObjectResponse res = resIterator.next();
ByteString content = res.getChecksummedData().getContent();
content.copyTo(scratch, 0);
}
long dur = System.currentTimeMillis() - start;
results.reportResult(args.bkt, object, buffSize, dur);
}
}
Aggregations