diff --git a/weed/shell/command_volume_balance.go b/weed/shell/command_volume_balance.go index 4c7d4294f3..11c622f898 100644 --- a/weed/shell/command_volume_balance.go +++ b/weed/shell/command_volume_balance.go @@ -25,6 +25,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" "github.com/seaweedfs/seaweedfs/weed/storage/needle" + "google.golang.org/protobuf/proto" ) const thresholdVolumeSize = 1.01 @@ -939,7 +940,10 @@ func adjustAfterMove(v *master_pb.VolumeInformationMessage, volumeReplicas map[u addDiskFreeBytes(fullDisk, int64(v.Size)) } if emptyDisk, found := emptyNode.info.DiskInfos[v.DiskType]; found { - emptyDisk.VolumeInfos = append(emptyDisk.VolumeInfos, v) + // the target server picks its own disk + moved := proto.Clone(v).(*master_pb.VolumeInformationMessage) + moved.DiskId = 0 + emptyDisk.VolumeInfos = append(emptyDisk.VolumeInfos, moved) addVolumeCount(emptyDisk, 1) addDiskFreeBytes(emptyDisk, -int64(v.Size)) } diff --git a/weed/shell/command_volume_server_evacuate_disk_id_test.go b/weed/shell/command_volume_server_evacuate_disk_id_test.go new file mode 100644 index 0000000000..8cbd3d30ae --- /dev/null +++ b/weed/shell/command_volume_server_evacuate_disk_id_test.go @@ -0,0 +1,64 @@ +package shell + +import ( + "io" + "testing" + + "github.com/seaweedfs/seaweedfs/weed/ec" + "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" + "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding" + "github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding/ecbalancer" +) + +func TestVolumeServerEvacuateEcAfterNormalMovesTargetsExistingDisks(t *testing.T) { + si := erasure_coding.NewShardsInfo() + for _, id := range []erasure_coding.ShardId{0, 1, 2} { + si.Set(erasure_coding.NewShardInfo(id, 0)) + } + moved := &master_pb.VolumeInformationMessage{Id: 6, Size: 1024, DiskId: 3} + source := &master_pb.DataNodeInfo{Id: "src:8080", DiskInfos: map[string]*master_pb.DiskInfo{ + "": { + MaxVolumeCount: 40, + VolumeCount: 2, + VolumeInfos: []*master_pb.VolumeInformationMessage{{Id: 5, Size: 1024, DiskId: 1}, moved}, + EcShardInfos: []*master_pb.VolumeEcShardInformationMessage{ + {Id: 4, Collection: "c", EcIndexBits: si.Bitmap(), ShardSizes: si.SizesInt64(), DiskId: 2}, + }, + }, + }} + target := &master_pb.DataNodeInfo{Id: "dst:8080", DiskInfos: map[string]*master_pb.DiskInfo{ + "": {MaxVolumeCount: 10}, + }} + + c := newEvacuateCommandForTest(0) + c.topologyInfo = &master_pb.TopologyInfo{DataCenterInfos: []*master_pb.DataCenterInfo{{ + Id: "dc1", + RackInfos: []*master_pb.RackInfo{ + {Id: "r1", DataNodeInfos: []*master_pb.DataNodeInfo{source}}, + {Id: "r2", DataNodeInfos: []*master_pb.DataNodeInfo{target}}, + }, + }}} + if err := c.evacuateNormalVolumes(nil, "src:8080", false, false, io.Discard); err != nil { + t.Fatalf("evacuate normal volumes: %v", err) + } + if moved.DiskId != 3 { + t.Fatalf("the source's volume record was changed: DiskId %d", moved.DiskId) + } + + var ran []ecbalancer.Move + c.moveEcShards = func(moves []ecbalancer.Move, stopOnError bool) (ec.EcShardMovesResult, error) { + ran = append(ran, moves...) + return ec.EcShardMovesResult{Moved: len(moves)}, nil + } + if err := c.evacuateEcVolumes(nil, "src:8080", false, true, io.Discard); err != nil { + t.Fatalf("evacuate ec volumes: %v", err) + } + if len(ran) != 3 { + t.Fatalf("expected 3 ec shard moves, got %d", len(ran)) + } + for _, m := range ran { + if m.TargetNode != "dst:8080" || m.TargetDisk != 0 { + t.Errorf("ec shard %d.%d sent to %s disk %d, which the target does not have", m.VolumeID, m.ShardID, m.TargetNode, m.TargetDisk) + } + } +}