2022-09-13 10:33:14 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
2023-03-07 13:38:26 +00:00
|
|
|
"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"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
2022-09-13 10:33:14 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2023-04-14 06:38:29 +00:00
|
|
|
const ignoreErrorsFlag = "no-errors"
|
|
|
|
|
2022-09-13 10:33:14 +00:00
|
|
|
var evacuateShardCmd = &cobra.Command{
|
2023-05-05 07:57:07 +00:00
|
|
|
Use: "evacuate",
|
|
|
|
Short: "Evacuate objects from shard",
|
|
|
|
Long: "Evacuate objects from shard to other shards",
|
|
|
|
Run: evacuateShard,
|
|
|
|
Deprecated: "use frostfs-cli control shards evacuation start",
|
2022-09-13 10:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func evacuateShard(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.Get(cmd)
|
|
|
|
|
|
|
|
req := &control.EvacuateShardRequest{Body: new(control.EvacuateShardRequest_Body)}
|
2022-10-10 17:58:28 +00:00
|
|
|
req.Body.Shard_ID = getShardIDList(cmd)
|
2023-04-14 06:38:29 +00:00
|
|
|
req.Body.IgnoreErrors, _ = cmd.Flags().GetBool(ignoreErrorsFlag)
|
2022-09-13 10:33:14 +00:00
|
|
|
|
|
|
|
signRequest(cmd, pk, req)
|
|
|
|
|
|
|
|
cli := getClient(cmd, pk)
|
|
|
|
|
|
|
|
var resp *control.EvacuateShardResponse
|
|
|
|
var err error
|
|
|
|
err = cli.ExecRaw(func(client *client.Client) error {
|
|
|
|
resp, err = control.EvacuateShard(client, req)
|
|
|
|
return err
|
|
|
|
})
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-09-13 10:33:14 +00:00
|
|
|
|
|
|
|
cmd.Printf("Objects moved: %d\n", resp.GetBody().GetCount())
|
|
|
|
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
|
|
|
|
cmd.Println("Shard has successfully been evacuated.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlEvacuateShardCmd() {
|
2022-10-17 15:37:15 +00:00
|
|
|
initControlFlags(evacuateShardCmd)
|
2022-09-13 10:33:14 +00:00
|
|
|
|
|
|
|
flags := evacuateShardCmd.Flags()
|
2022-10-10 17:58:28 +00:00
|
|
|
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
2022-10-10 18:14:12 +00:00
|
|
|
flags.Bool(shardAllFlag, false, "Process all shards")
|
2023-04-14 06:38:29 +00:00
|
|
|
flags.Bool(ignoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
2022-09-13 10:33:14 +00:00
|
|
|
|
2022-10-10 18:14:12 +00:00
|
|
|
evacuateShardCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
2022-09-13 10:33:14 +00:00
|
|
|
}
|