mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-06-28 15:41:13 +08:00
ec.encode
: Display a warning on EC balancing if no replica placement settings are found. (#6487)
This commit is contained in:
parent
33ba88df9c
commit
7913681297
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -19,7 +20,6 @@ import (
|
|||||||
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
"github.com/seaweedfs/seaweedfs/weed/storage/super_block"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataCenterId string
|
type DataCenterId string
|
||||||
@ -176,20 +176,28 @@ func _getDefaultReplicaPlacement(commandEnv *CommandEnv) (*super_block.ReplicaPl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseReplicaPlacementArg(commandEnv *CommandEnv, replicaStr string) (*super_block.ReplicaPlacement, error) {
|
func parseReplicaPlacementArg(commandEnv *CommandEnv, replicaStr string) (*super_block.ReplicaPlacement, error) {
|
||||||
if replicaStr != "" {
|
var rp *super_block.ReplicaPlacement
|
||||||
rp, err := super_block.NewReplicaPlacementFromString(replicaStr)
|
var err error
|
||||||
if err == nil {
|
|
||||||
fmt.Printf("using replica placement %q for EC volumes\n", rp.String())
|
|
||||||
}
|
|
||||||
return rp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// No replica placement argument provided, resolve from master default settings.
|
if replicaStr != "" {
|
||||||
rp, err := getDefaultReplicaPlacement(commandEnv)
|
rp, err = super_block.NewReplicaPlacementFromString(replicaStr)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
|
return rp, err
|
||||||
|
}
|
||||||
|
fmt.Printf("using replica placement %q for EC volumes\n", rp.String())
|
||||||
|
} else {
|
||||||
|
// No replica placement argument provided, resolve from master default settings.
|
||||||
|
rp, err = getDefaultReplicaPlacement(commandEnv)
|
||||||
|
if err != nil {
|
||||||
|
return rp, err
|
||||||
|
}
|
||||||
fmt.Printf("using master default replica placement %q for EC volumes\n", rp.String())
|
fmt.Printf("using master default replica placement %q for EC volumes\n", rp.String())
|
||||||
}
|
}
|
||||||
return rp, err
|
|
||||||
|
if !rp.HasReplication() {
|
||||||
|
fmt.Printf("WARNING: replica placement type %q is empty!", rp.String())
|
||||||
|
}
|
||||||
|
return rp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectTopologyInfo(commandEnv *CommandEnv, delayBeforeCollecting time.Duration) (topoInfo *master_pb.TopologyInfo, volumeSizeLimitMb uint64, err error) {
|
func collectTopologyInfo(commandEnv *CommandEnv, delayBeforeCollecting time.Duration) (topoInfo *master_pb.TopologyInfo, volumeSizeLimitMb uint64, err error) {
|
||||||
|
@ -45,6 +45,10 @@ func NewReplicaPlacementFromByte(b byte) (*ReplicaPlacement, error) {
|
|||||||
return NewReplicaPlacementFromString(fmt.Sprintf("%03d", b))
|
return NewReplicaPlacementFromString(fmt.Sprintf("%03d", b))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rp *ReplicaPlacement) HasReplication() bool {
|
||||||
|
return rp.DiffDataCenterCount != 0 || rp.DiffRackCount != 0 || rp.SameRackCount != 0
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ReplicaPlacement) Equals(b *ReplicaPlacement) bool {
|
func (a *ReplicaPlacement) Equals(b *ReplicaPlacement) bool {
|
||||||
if a == nil || b == nil {
|
if a == nil || b == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -12,3 +12,32 @@ func TestReplicaPlacementSerialDeserial(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReplicaPlacementHasReplication(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
replicaPlacement string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"empty replica placement", "", false},
|
||||||
|
{"no replication", "000", false},
|
||||||
|
{"same rack replication", "100", true},
|
||||||
|
{"diff rack replication", "020", true},
|
||||||
|
{"DC replication", "003", true},
|
||||||
|
{"full replication", "155", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
rp, err := NewReplicaPlacementFromString(tc.replicaPlacement)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to initialize ReplicaPlacement: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if got, want := rp.HasReplication(), tc.want; got != want {
|
||||||
|
t.Errorf("expected %v, got %v", want, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user