cli: Support copies number parameter in object put #350

Merged
fyrchik merged 1 commit from acid-ant/frostfs-node:feature/cli-obj-put-copies-num into master 2023-05-16 08:22:58 +00:00
3 changed files with 25 additions and 0 deletions
Showing only changes of commit 0f10899ba4 - Show all commits

View file

@ -7,6 +7,7 @@ Changelog for FrostFS Node
- Support impersonate bearer token (#229) - Support impersonate bearer token (#229)
- Change log level on SIGHUP for ir (#125) - Change log level on SIGHUP for ir (#125)
- Reload pprof and metrics on SIGHUP for ir (#125) - Reload pprof and metrics on SIGHUP for ir (#125)
- Support copies number parameter in `frostfs-cli object put` (#351)
### Changed ### Changed
- `frostfs-cli util locode generate` is now much faster (#309) - `frostfs-cli util locode generate` is now much faster (#309)

View file

@ -329,6 +329,8 @@ func CreateSession(prm CreateSessionPrm) (res CreateSessionRes, err error) {
type PutObjectPrm struct { type PutObjectPrm struct {
commonObjectPrm commonObjectPrm
copyNum []uint32
hdr *object.Object hdr *object.Object
rdr io.Reader rdr io.Reader
@ -352,6 +354,12 @@ func (x *PutObjectPrm) SetHeaderCallback(f func(*object.Object)) {
x.headerCallback = f x.headerCallback = f
} }
// SetCopiesNumberByVectors sets ordered list of minimal required object copies numbers
// per placement vector.
func (x *PutObjectPrm) SetCopiesNumberByVectors(copiesNumbers []uint32) {
x.copyNum = copiesNumbers
}
// PutObjectRes groups the resulting values of PutObject operation. // PutObjectRes groups the resulting values of PutObject operation.
type PutObjectRes struct { type PutObjectRes struct {
id oid.ID id oid.ID
@ -381,6 +389,7 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
} }
putPrm.WithXHeaders(prm.xHeaders...) putPrm.WithXHeaders(prm.xHeaders...)
putPrm.SetCopiesNumberByVectors(prm.copyNum)
wrt, err := prm.cli.ObjectPutInit(context.Background(), putPrm) wrt, err := prm.cli.ObjectPutInit(context.Background(), putPrm)
if err != nil { if err != nil {

View file

@ -25,6 +25,7 @@ import (
const ( const (
noProgressFlag = "no-progress" noProgressFlag = "no-progress"
notificationFlag = "notify" notificationFlag = "notify"
copiesNumberFlag = "copies-number"
) )
var putExpiredOn uint64 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.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.Bool(binaryFlag, false, "Deserialize object structure from given file.")
flags.String(copiesNumberFlag, "", "Number of copies of the object to store within the RPC call")

I believe UintSlice allows following usage: --copies-number 1 --copies-number 2.
It should be a bug, it is really and atomic vector and not an arbitrary-sized slice.
What about using String and split it by ,?

I believe `UintSlice` allows following usage: `--copies-number 1 --copies-number 2`. It should be a bug, it is really and _atomic_ vector and not an arbitrary-sized slice. What about using `String` and split it by `,`?

Surprised, will use string instead of uint slice.

Surprised, will use string instead of uint slice.

Done, please review.

Done, please review.
} }
func putObject(cmd *cobra.Command, _ []string) { func putObject(cmd *cobra.Command, _ []string) {
@ -116,6 +119,18 @@ func putObject(cmd *cobra.Command, _ []string) {
} }
} }
copyNum, err := cmd.Flags().GetString(copiesNumberFlag)
commonCmd.ExitOnErr(cmd, "can't parse object copies numbers information: %w", err)
if len(copyNum) > 0 {
var cn []uint32
for _, num := range strings.Split(copyNum, ",") {
val, err := strconv.ParseUint(num, 10, 32)
commonCmd.ExitOnErr(cmd, "can't parse object copies numbers information: %w", err)
cn = append(cn, uint32(val))
}
prm.SetCopiesNumberByVectors(cn)
}
res, err := internalclient.PutObject(prm) res, err := internalclient.PutObject(prm)
if p != nil { if p != nil {
p.Finish() p.Finish()