From e10cf7fd852cb699b65e508f9fc6b3934bd177e0 Mon Sep 17 00:00:00 2001 From: Andrey Andronov <11226311+andreyhammer@users.noreply.github.com> Date: Wed, 2 Dec 2026 06:32:44 -0500 Subject: [PATCH] shell: a moved volume does not keep its source disk id in the model (#13275) * shell: a moved volume does not keep its source disk id in the model adjustAfterMove added the moved volume to the target's VolumeInfos with the source's DiskId. volumeServer.evacuate moves the normal volumes first and then plans the EC shards on the same topology, where the disk ids of a node come from its volume and shard records. A volume moved off disk 3 of a four-disk server therefore gave its one-disk target a disk 3, the planner sent EC shards there, and the target refused every such move with "invalid disk_id 3: only have 1 disks". The target server picks the disk for a moved volume, so record it with disk id 0 (unknown) on a copy, leaving the source's record as it is. Co-Authored-By: Claude Opus 5.5 * shell: test the EC phase of evacuate on the model the volume phase left Drive evacuateNormalVolumes and then evacuateEcVolumes, the two phases the command runs on one topology, instead of calling adjustAfterMove directly, and check the disk each planned shard move names. Co-Authored-By: Claude Opus 5.5 * shell: trim comments on the moved volume record Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: Chris Lu --- weed/shell/command_volume_balance.go | 6 +- ...and_volume_server_evacuate_disk_id_test.go | 64 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 weed/shell/command_volume_server_evacuate_disk_id_test.go 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) + } + } +}