Files
seaweedfs/weed/shell/command_volume_tier_move_test.go
Chris Lu 42030381ae shell: volume.tier.move can move volumes between data centers (#9925)
* shell: volume.tier.move can move volumes between data centers

-fromDataCenter scopes volume selection to volumes with a replica in
that data center. -toDataCenter constrains move destinations and
replication fulfillment. With identical disk types both flags are
required, moving full volumes between data centers on the same tier.

* shell: assert node identity in data center filter test

* shell: tier move resumes when the volume is already on the target

A replica already on the target tier and data center, typically left by
an interrupted earlier run, anchors the move: skip the copy and only
complete replication fulfillment and old replica cleanup. Previously
such volumes hit the no-destination path and the stale source replicas
were never removed.
2026-06-11 10:46:34 -07:00

37 lines
1.2 KiB
Go

package shell
import (
"testing"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
"github.com/stretchr/testify/assert"
)
func TestVolumeSelectionByDataCenter(t *testing.T) {
topologyInfo := parseOutput(topoData)
vids, err := collectVolumeIdsForTierChange(topologyInfo, 1000, types.ToDiskType(types.HddType), "dc2", "", 20.0, 0)
assert.NoError(t, err)
assert.Equal(t, 83, len(vids))
vids, err = collectVolumeIdsForTierChange(topologyInfo, 1000, types.ToDiskType(types.HddType), "dc1", "", 20.0, 0)
assert.NoError(t, err)
assert.Equal(t, 0, len(vids))
}
func TestFilterLocationsByDataCenter(t *testing.T) {
_, allLocations := collectVolumeReplicaLocations(parseOutput(topoData))
assert.Equal(t, 5, len(allLocations))
assert.ElementsMatch(t, []string{"192.168.1.4:8080", "192.168.1.2:8080"}, locationNodeIds(filterLocationsByDataCenter(allLocations, "dc2")))
assert.ElementsMatch(t, []string{"192.168.1.6:8080"}, locationNodeIds(filterLocationsByDataCenter(allLocations, "dc3")))
assert.Empty(t, filterLocationsByDataCenter(allLocations, "dc9"))
}
func locationNodeIds(locations []location) (ids []string) {
for _, loc := range locations {
ids = append(ids, loc.dataNode.Id)
}
return
}