From 0fd7222d65d58f81d08712702b4d5604a85ca92a Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 5 Oct 2023 11:13:48 -0700 Subject: default to skip if less than 4 nodes --- weed/shell/command_ec_encode.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'weed/shell/command_ec_encode.go') diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.go index 9fe7ad8e4..8864265a7 100644 --- a/weed/shell/command_ec_encode.go +++ b/weed/shell/command_ec_encode.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/pb" "io" "math/rand" @@ -62,6 +63,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Wr fullPercentage := encodeCommand.Float64("fullPercent", 95, "the volume reaches the percentage of max volume size") quietPeriod := encodeCommand.Duration("quietFor", time.Hour, "select volumes without no writes for this period") parallelCopy := encodeCommand.Bool("parallelCopy", true, "copy shards in parallel") + forceChanges := encodeCommand.Bool("force", false, "force the encoding even if the cluster has less than recommended 4 nodes") if err = encodeCommand.Parse(args); err != nil { return nil } @@ -70,6 +72,23 @@ func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Wr return } + // collect topology information + topologyInfo, _, err := collectTopologyInfo(commandEnv, 0) + if err != nil { + return err + } + + if !*forceChanges { + var nodeCount int + eachDataNode(topologyInfo, func(dc string, rack RackId, dn *master_pb.DataNodeInfo) { + nodeCount++ + }) + if nodeCount < erasure_coding.ParityShardsCount { + glog.V(0).Infof("skip erasure coding with %d nodes, less than recommended %d nodes", nodeCount, erasure_coding.ParityShardsCount) + return nil + } + } + vid := needle.VolumeId(*volumeId) // volumeId is provided -- cgit v1.2.3