forked from TrueCloudLab/frostfs-sdk-go
[#302] client: Adopt SetCopiesNumber
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
7a99cc916c
commit
30bf79f075
2 changed files with 21 additions and 5 deletions
|
@ -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)
|
||||
|
|
10
pool/pool.go
10
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
|
||||
|
|
Loading…
Reference in a new issue