forked from TrueCloudLab/frostfs-node
[#1867] services/control: Interpret empty list of IDs as all shards
In neofs-cli the flag is still required, but `all` can be used to process all shards. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
b632260995
commit
c0199dee93
7 changed files with 30 additions and 11 deletions
|
@ -48,7 +48,8 @@ func initControlEvacuateShardCmd() {
|
|||
flags := evacuateShardCmd.Flags()
|
||||
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
||||
flags.Bool(shardAllFlag, false, "Process all shards")
|
||||
flags.Bool(dumpIgnoreErrorsFlag, false, "Skip invalid/unreadable objects")
|
||||
|
||||
_ = evacuateShardCmd.MarkFlagRequired(shardIDFlag)
|
||||
evacuateShardCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ func initControlFlushCacheCmd() {
|
|||
ff := flushCacheCmd.Flags()
|
||||
ff.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||
ff.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
||||
ff.Bool(shardAllFlag, false, "Process all shards")
|
||||
|
||||
_ = flushCacheCmd.MarkFlagRequired(shardIDFlag)
|
||||
flushCacheCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
|
@ -16,6 +15,7 @@ import (
|
|||
const (
|
||||
shardModeFlag = "mode"
|
||||
shardIDFlag = "id"
|
||||
shardAllFlag = "all"
|
||||
shardClearErrorsFlag = "clear-errors"
|
||||
|
||||
shardModeReadOnly = "read-only"
|
||||
|
@ -38,6 +38,7 @@ func initControlSetShardModeCmd() {
|
|||
|
||||
flags.String(controlRPC, controlRPCDefault, controlRPCUsage)
|
||||
flags.StringSlice(shardIDFlag, nil, "List of shard IDs in base58 encoding")
|
||||
flags.Bool(shardAllFlag, false, "Process all shards")
|
||||
flags.String(shardModeFlag, "",
|
||||
fmt.Sprintf("New shard mode keyword ('%s', '%s', '%s')",
|
||||
shardModeReadWrite,
|
||||
|
@ -46,6 +47,8 @@ func initControlSetShardModeCmd() {
|
|||
),
|
||||
)
|
||||
flags.Bool(shardClearErrorsFlag, false, "Set shard error count to 0")
|
||||
|
||||
setShardModeCmd.MarkFlagsMutuallyExclusive(shardIDFlag, shardAllFlag)
|
||||
}
|
||||
|
||||
func setShardMode(cmd *cobra.Command, _ []string) {
|
||||
|
@ -102,9 +105,14 @@ func getShardID(cmd *cobra.Command) []byte {
|
|||
}
|
||||
|
||||
func getShardIDList(cmd *cobra.Command) [][]byte {
|
||||
all, _ := cmd.Flags().GetBool(shardAllFlag)
|
||||
if all {
|
||||
return nil
|
||||
}
|
||||
|
||||
sidList, _ := cmd.Flags().GetStringSlice(shardIDFlag)
|
||||
if len(sidList) == 0 {
|
||||
common.ExitOnErr(cmd, "", errors.New("no shard IDs were provided"))
|
||||
common.ExitOnErr(cmd, "", fmt.Errorf("either --%s or --%s flag must be provided", shardIDFlag, shardAllFlag))
|
||||
}
|
||||
|
||||
// We can sort the ID list and perform this check without additional allocations,
|
||||
|
|
|
@ -26,7 +26,7 @@ func (s *Server) EvacuateShard(_ context.Context, req *control.EvacuateShardRequ
|
|||
}
|
||||
|
||||
var prm engine.EvacuateShardPrm
|
||||
prm.WithShardIDList(getShardIDList(req.GetBody().GetShard_ID()))
|
||||
prm.WithShardIDList(s.getShardIDList(req.GetBody().GetShard_ID()))
|
||||
prm.WithIgnoreErrors(req.GetBody().GetIgnoreErrors())
|
||||
prm.WithFaultHandler(s.replicate)
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ func (s *Server) FlushCache(_ context.Context, req *control.FlushCacheRequest) (
|
|||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
}
|
||||
|
||||
for _, shardID := range getShardIDList(req.GetBody().GetShard_ID()) {
|
||||
for _, shardID := range s.getShardIDList(req.GetBody().GetShard_ID()) {
|
||||
var prm engine.FlushWriteCachePrm
|
||||
prm.SetShardID(shardID)
|
||||
|
||||
|
|
|
@ -2,10 +2,19 @@ package control
|
|||
|
||||
import "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
||||
|
||||
func getShardIDList(raw [][]byte) []*shard.ID {
|
||||
res := make([]*shard.ID, 0, len(raw))
|
||||
for i := range raw {
|
||||
res = append(res, shard.NewIDFromBytes(raw[i]))
|
||||
func (s *Server) getShardIDList(raw [][]byte) []*shard.ID {
|
||||
if len(raw) != 0 {
|
||||
res := make([]*shard.ID, 0, len(raw))
|
||||
for i := range raw {
|
||||
res = append(res, shard.NewIDFromBytes(raw[i]))
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
info := s.s.DumpInfo()
|
||||
res := make([]*shard.ID, 0, len(info.Shards))
|
||||
for i := range info.Shards {
|
||||
res = append(res, info.Shards[i].ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func (s *Server) SetShardMode(_ context.Context, req *control.SetShardModeReques
|
|||
return nil, status.Error(codes.Internal, fmt.Sprintf("unknown shard mode: %s", requestedMode))
|
||||
}
|
||||
|
||||
for _, shardID := range getShardIDList(req.Body.GetShard_ID()) {
|
||||
for _, shardID := range s.getShardIDList(req.Body.GetShard_ID()) {
|
||||
err = s.s.SetShardMode(shardID, m, false)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
|
|
Loading…
Reference in a new issue