From 1501f11e4dadf0cb9d79e7085ffecb2748a2e24c Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Wed, 17 May 2023 10:58:04 +0300 Subject: [PATCH] [#351] cli: Support copies number parameter in `object put` Signed-off-by: Anton Nikiforov --- CHANGELOG.md | 2 ++ cmd/frostfs-cli/internal/client/client.go | 8 ++++++++ cmd/frostfs-cli/modules/object/put.go | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d75b388..d49e7343c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changelog for FrostFS Node ## [Unreleased] ### Added +- Support copies number parameter in `frostfs-cli object put` (#351) + ### Changed ### Fixed - Copy number was not used for `PUT` requests (#284) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index cbf19eb4b..c892c9e7e 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -329,6 +329,8 @@ func CreateSession(prm CreateSessionPrm) (res CreateSessionRes, err error) { type PutObjectPrm struct { commonObjectPrm + copyNum uint32 + hdr *object.Object rdr io.Reader @@ -352,6 +354,11 @@ func (x *PutObjectPrm) SetHeaderCallback(f func(*object.Object)) { x.headerCallback = f } +// SetCopiesNumber sets number of object copies that is enough to consider put successful. +func (x *PutObjectPrm) SetCopiesNumber(copiesNumbers uint32) { + x.copyNum = copiesNumbers +} + // PutObjectRes groups the resulting values of PutObject operation. type PutObjectRes struct { id oid.ID @@ -381,6 +388,7 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { } putPrm.WithXHeaders(prm.xHeaders...) + putPrm.SetCopiesNumber(prm.copyNum) wrt, err := prm.cli.ObjectPutInit(context.Background(), putPrm) if err != nil { diff --git a/cmd/frostfs-cli/modules/object/put.go b/cmd/frostfs-cli/modules/object/put.go index fe8e9dda9..e7f00a612 100644 --- a/cmd/frostfs-cli/modules/object/put.go +++ b/cmd/frostfs-cli/modules/object/put.go @@ -25,6 +25,7 @@ import ( const ( noProgressFlag = "no-progress" notificationFlag = "notify" + copiesNumberFlag = "copies-number" ) var putExpiredOn uint64 @@ -56,6 +57,8 @@ func initObjectPutCmd() { flags.String(notificationFlag, "", "Object notification in the form of *epoch*:*topic*; '-' topic means using default") flags.Bool(binaryFlag, false, "Deserialize object structure from given file.") + + flags.Uint32(copiesNumberFlag, 0, "Number of copies of the object to store within the RPC call") } func putObject(cmd *cobra.Command, _ []string) { @@ -116,6 +119,12 @@ func putObject(cmd *cobra.Command, _ []string) { } } + copyNum, err := cmd.Flags().GetUint32(copiesNumberFlag) + commonCmd.ExitOnErr(cmd, "can't parse object copies numbers information: %w", err) + if copyNum > 0 { + prm.SetCopiesNumber(copyNum) + } + res, err := internalclient.PutObject(prm) if p != nil { p.Finish()