From b689027d573c7ea973786d320853b51173c96522 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 7 Apr 2023 14:36:00 +0300 Subject: [PATCH] [#191] cli: Add `control shards doctor` command Signed-off-by: Evgenii Stratonikov --- cmd/frostfs-cli/modules/control/doctor.go | 53 +++++++++++++++++++++++ cmd/frostfs-cli/modules/control/shards.go | 2 + 2 files changed, 55 insertions(+) create mode 100644 cmd/frostfs-cli/modules/control/doctor.go diff --git a/cmd/frostfs-cli/modules/control/doctor.go b/cmd/frostfs-cli/modules/control/doctor.go new file mode 100644 index 000000000..13bb81a0a --- /dev/null +++ b/cmd/frostfs-cli/modules/control/doctor.go @@ -0,0 +1,53 @@ +package control + +import ( + "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" + commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" + "github.com/spf13/cobra" +) + +const ( + concurrencyFlag = "concurrency" + removeDuplicatesFlag = "remove-duplicates" +) + +var doctorCmd = &cobra.Command{ + Use: "doctor", + Short: "Restructure node's storage", + Long: "Restructure node's storage", + Run: doctor, +} + +func doctor(cmd *cobra.Command, _ []string) { + pk := key.Get(cmd) + + req := &control.DoctorRequest{Body: new(control.DoctorRequest_Body)} + req.Body.Concurrency, _ = cmd.Flags().GetUint32(concurrencyFlag) + req.Body.RemoveDuplicates, _ = cmd.Flags().GetBool(removeDuplicatesFlag) + + signRequest(cmd, pk, req) + + cli := getClient(cmd, pk) + + var resp *control.DoctorResponse + var err error + err = cli.ExecRaw(func(client *client.Client) error { + resp, err = control.Doctor(client, req) + return err + }) + commonCmd.ExitOnErr(cmd, "rpc error: %w", err) + + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + + cmd.Println("Operation has finished.") +} + +func initControlDoctorCmd() { + initControlFlags(doctorCmd) + + ff := doctorCmd.Flags() + ff.Uint32(concurrencyFlag, 0, "Number of parallel threads to use") + ff.Bool(removeDuplicatesFlag, false, "Remove duplicate objects") +} diff --git a/cmd/frostfs-cli/modules/control/shards.go b/cmd/frostfs-cli/modules/control/shards.go index 6719a4acf..9d3eb5c01 100644 --- a/cmd/frostfs-cli/modules/control/shards.go +++ b/cmd/frostfs-cli/modules/control/shards.go @@ -17,6 +17,7 @@ func initControlShardsCmd() { shardsCmd.AddCommand(restoreShardCmd) shardsCmd.AddCommand(evacuateShardCmd) shardsCmd.AddCommand(flushCacheCmd) + shardsCmd.AddCommand(doctorCmd) initControlShardsListCmd() initControlSetShardModeCmd() @@ -24,4 +25,5 @@ func initControlShardsCmd() { initControlRestoreShardCmd() initControlEvacuateShardCmd() initControlFlushCacheCmd() + initControlDoctorCmd() }