From 30bf79f075ec91e216804e972039cf23dd74866d Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 29 Jul 2022 18:42:24 +0300 Subject: [PATCH] [#302] client: Adopt SetCopiesNumber Signed-off-by: Denis Kirillov --- client/object_put.go | 16 +++++++++++----- pool/pool.go | 10 ++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/client/object_put.go b/client/object_put.go index b00cee8a..b7e51241 100644 --- a/client/object_put.go +++ b/client/object_put.go @@ -19,10 +19,14 @@ import ( ) // PrmObjectPutInit groups parameters of ObjectPutInit operation. -// -// At the moment the operation is not parameterized, however, -// the structure is still declared for backward compatibility. -type PrmObjectPutInit struct{} +type PrmObjectPutInit struct { + copyNum uint32 +} + +// SetCopiesNumber sets number of object copies that is enough to consider put successful. +func (x *PrmObjectPutInit) SetCopiesNumber(copiesNumber uint32) { + x.copyNum = copiesNumber +} // ResObjectPut groups the final result values of ObjectPutInit operation. type ResObjectPut struct { @@ -202,7 +206,7 @@ func (x *ObjectWriter) Close() (*ResObjectPut, error) { // Exactly one return value is non-nil. Resulting writer must be finally closed. // // Context is required and must not be nil. It is used for network communication. -func (c *Client) ObjectPutInit(ctx context.Context, _ PrmObjectPutInit) (*ObjectWriter, error) { +func (c *Client) ObjectPutInit(ctx context.Context, prm PrmObjectPutInit) (*ObjectWriter, error) { // check parameters if ctx == nil { panic(panicMsgMissingContext) @@ -216,6 +220,8 @@ func (c *Client) ObjectPutInit(ctx context.Context, _ PrmObjectPutInit) (*Object ctx, w.cancelCtxStream = context.WithCancel(ctx) + w.partInit.SetCopiesNumber(prm.copyNum) + stream, err := rpcapi.PutObject(&c.c, &res.resp, client.WithContext(ctx)) if err != nil { return nil, fmt.Errorf("open stream: %w", err) diff --git a/pool/pool.go b/pool/pool.go index 42af3693..04ccd427 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -477,6 +477,8 @@ func (c *clientWrapper) networkInfo(ctx context.Context, _ prmNetworkInfo) (*net // Exactly one return value is non-nil. func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (*oid.ID, error) { var cliPrm sdkClient.PrmObjectPutInit + cliPrm.SetCopiesNumber(prm.copiesNumber) + start := time.Now() wObj, err := c.client.ObjectPutInit(ctx, cliPrm) c.incRequests(time.Since(start), methodObjectPut) @@ -1016,6 +1018,8 @@ type PrmObjectPut struct { hdr object.Object payload io.Reader + + copiesNumber uint32 } // SetHeader specifies header of the object. @@ -1028,6 +1032,12 @@ func (x *PrmObjectPut) SetPayload(payload io.Reader) { x.payload = payload } +// SetCopiesNumber sets number of object copies that is enough to consider put successful. +// Zero means using default behavior. +func (x *PrmObjectPut) SetCopiesNumber(copiesNumber uint32) { + x.copiesNumber = copiesNumber +} + // PrmObjectDelete groups parameters of DeleteObject operation. type PrmObjectDelete struct { prmCommon