From 12a8f5294d2479fada6988b2639c1f75f02c1ab2 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 11 Sep 2020 01:21:17 -0700 Subject: [PATCH] test for multi dc replication --- weed/shell/command_volume_balance.go | 2 +- weed/shell/command_volume_balance_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 4f96c3e08..3e36c7fd5 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -299,7 +299,7 @@ func isGoodMove(placement *super_block.ReplicaPlacement, existingReplicas []*Vol return false } - if len(racks) > placement.DiffRackCount+1 { + if len(racks) > placement.DiffRackCount+placement.DiffDataCenterCount+1 { return false } diff --git a/weed/shell/command_volume_balance_test.go b/weed/shell/command_volume_balance_test.go index 7919d60c0..4f46648c0 100644 --- a/weed/shell/command_volume_balance_test.go +++ b/weed/shell/command_volume_balance_test.go @@ -19,6 +19,24 @@ type testMoveCase struct { func TestIsGoodMove(t *testing.T) { var tests = []testMoveCase{ + + + { + name: "test 100 move to spread into proper data centers", + replication: "100", + replicas: []*VolumeReplica{ + { + location: &location{"dc1", "r1", &master_pb.DataNodeInfo{Id: "dn1"}}, + }, + { + location: &location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + }, + }, + sourceLocation: location{"dc1", "r2", &master_pb.DataNodeInfo{Id: "dn2"}}, + targetLocation: location{"dc2", "r2", &master_pb.DataNodeInfo{Id: "dn3"}}, + expected: true, + }, + { name: "test move to the same node", replication: "001",