From c243b443bce6b4d82b105d62e7ff75dee833ac50 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 26 Jun 2023 18:13:04 +0300 Subject: [PATCH] [#80] objectwriter: Allow custimize maxChunkLen Signed-off-by: Dmitrii Stepanov --- client/object_put.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/client/object_put.go b/client/object_put.go index 3486907..d56a6fc 100644 --- a/client/object_put.go +++ b/client/object_put.go @@ -22,9 +22,10 @@ import ( // PrmObjectPutInit groups parameters of ObjectPutInit operation. type PrmObjectPutInit struct { - copyNum []uint32 - key *ecdsa.PrivateKey - meta v2session.RequestMetaHeader + copyNum []uint32 + key *ecdsa.PrivateKey + meta v2session.RequestMetaHeader + maxChunkLen int } // SetCopiesNumber sets number of object copies that is enough to consider put successful. @@ -39,6 +40,15 @@ func (x *PrmObjectPutInit) SetCopiesNumberByVectors(copiesNumbers []uint32) { x.copyNum = copiesNumbers } +// SetGRPCPayloadChunkLen sets maximum chunk length value for gRPC Put request. +// Maximum chunk length restricts maximum byte length of the chunk +// transmitted in a single stream message. It depends on +// server settings and other message fields. +// If not specified or negative value set, default value of 3MiB will be used. +func (x *PrmObjectPutInit) SetGRPCPayloadChunkLen(v int) { + x.maxChunkLen = v +} + // ResObjectPut groups the final result values of ObjectPutInit operation. type ResObjectPut struct { statusRes @@ -74,6 +84,8 @@ type ObjectWriter struct { req v2object.PutRequest partInit v2object.PutObjectPartInit partChunk v2object.PutObjectPartChunk + + maxChunkLen int } // UseKey specifies private key to sign the requests. @@ -143,15 +155,8 @@ func (x *ObjectWriter) WritePayloadChunk(chunk []byte) bool { } for ln := len(chunk); ln > 0; ln = len(chunk) { - // maxChunkLen restricts maximum byte length of the chunk - // transmitted in a single stream message. It depends on - // server settings and other message fields, but for now - // we simply assume that 3MB is large enough to reduce the - // number of messages, and not to exceed the limit - // (4MB by default for gRPC servers). - const maxChunkLen = 3 << 20 - if ln > maxChunkLen { - ln = maxChunkLen + if ln > x.maxChunkLen { + ln = x.maxChunkLen } // we deal with size limit overflow above, but there is another case: @@ -263,6 +268,11 @@ func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*Obje w.stream = stream w.partInit.SetCopiesNumber(prm.copyNum) w.req.SetBody(new(v2object.PutRequestBody)) + if prm.maxChunkLen > 0 { + w.maxChunkLen = prm.maxChunkLen + } else { + w.maxChunkLen = 3 << 20 + } c.prepareRequest(&w.req, &prm.meta) return &w, nil