diff --git a/native/cpp/CommonCpp/grpc/protos/blob.proto b/native/cpp/CommonCpp/grpc/protos/blob.proto --- a/native/cpp/CommonCpp/grpc/protos/blob.proto +++ b/native/cpp/CommonCpp/grpc/protos/blob.proto @@ -28,6 +28,7 @@ message GetRequest { string holder = 1; + uint32 extraBytesNeeded = 2; } message GetResponse { diff --git a/services/blob/src/Reactors/server/GetReactor.h b/services/blob/src/Reactors/server/GetReactor.h --- a/services/blob/src/Reactors/server/GetReactor.h +++ b/services/blob/src/Reactors/server/GetReactor.h @@ -21,8 +21,8 @@ : public ServerWriteReactorBase { size_t offset = 0; size_t fileSize = 0; - const size_t chunkSize = - GRPC_CHUNK_SIZE_LIMIT - GRPC_METADATA_SIZE_PER_MESSAGE; + size_t extraBytesNeeded = 0; + size_t chunkSize = 0; database::S3Path s3Path; Aws::S3::Model::GetObjectRequest getRequest; @@ -63,6 +63,14 @@ } void initialize() override { + this->extraBytesNeeded = this->request.extrabytesneeded(); + this->chunkSize = GRPC_CHUNK_SIZE_LIMIT - GRPC_METADATA_SIZE_PER_MESSAGE; + if (this->extraBytesNeeded >= this->chunkSize) { + throw std::runtime_error( + "extra bytes needed (" + std::to_string(this->extraBytesNeeded) + + ") cannot exceed the grpc chunk limit (" + std::to_string(this->chunkSize) + ")"); + } + this->chunkSize -= this->extraBytesNeeded; this->s3Path = tools::findS3Path(this->request.holder()); this->fileSize = getBucket(s3Path.getBucketName()).getObjectSize(s3Path.getObjectName()); diff --git a/services/commtest/tests/blob/get.rs b/services/commtest/tests/blob/get.rs --- a/services/commtest/tests/blob/get.rs +++ b/services/commtest/tests/blob/get.rs @@ -18,6 +18,7 @@ let response = client .get(Request::new(GetRequest { holder: cloned_holder, + extra_bytes_needed: 0, })) .await?; let mut inbound = response.into_inner();