diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-11-20 01:12:25 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-11-20 01:12:25 -0800 |
| commit | 7385103057abe3901890c9106f3f5e5c5e496281 (patch) | |
| tree | 24947cf47d71c51c9262cc83d9adbbd0c65e0693 | |
| parent | da04bb3d1bb60d92fdacfb2edd8c8bdba2643038 (diff) | |
| download | seaweedfs-7385103057abe3901890c9106f3f5e5c5e496281.tar.xz seaweedfs-7385103057abe3901890c9106f3f5e5c5e496281.zip | |
fix volume placement validating
fix https://github.com/chrislusf/seaweedfs/issues/1626
| -rw-r--r-- | weed/shell/command_volume_balance.go | 6 | ||||
| -rw-r--r-- | weed/shell/command_volume_balance_test.go | 16 |
2 files changed, 19 insertions, 3 deletions
diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 53222ca29..928dec02a 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -306,16 +306,16 @@ func isGoodMove(placement *super_block.ReplicaPlacement, existingReplicas []*Vol dcs[targetNode.dc] = true racks[fmt.Sprintf("%s %s", targetNode.dc, targetNode.rack)]++ - if len(dcs) > placement.DiffDataCenterCount+1 { + if len(dcs) != placement.DiffDataCenterCount+1 { return false } - if len(racks) > placement.DiffRackCount+placement.DiffDataCenterCount+1 { + if len(racks) != placement.DiffRackCount+placement.DiffDataCenterCount+1 { return false } for _, sameRackCount := range racks { - if sameRackCount > placement.SameRackCount+1 { + if sameRackCount != placement.SameRackCount+1 { return false } } diff --git a/weed/shell/command_volume_balance_test.go b/weed/shell/command_volume_balance_test.go index 9e154dc00..696bc7fac 100644 --- a/weed/shell/command_volume_balance_test.go +++ b/weed/shell/command_volume_balance_test.go @@ -21,6 +21,22 @@ func TestIsGoodMove(t *testing.T) { var tests = []testMoveCase{ { + name: "test 100 move to wrong data centers", + replication: "100", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + }, + sourceLocation: location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + targetLocation: location{"dc2", "r3", &master_pb.DataNodeInfo{Id: "dn3"}}, + expected: false, + }, + + { name: "test 100 move to spread into proper data centers", replication: "100", replicas: []*VolumeReplica{ |
