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 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* shell: trim comments on the moved volume record

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-12-02 03:32:44 -08:00
1 parent 2b157f2ef1
commit e10cf7fd85
2 files changed
+69 -1

No files matched your search

+5 -1
View File
@@ -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))
}
@@ -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)
}
}
}