mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-12 14:58:44 +01:00
fix(shell): use exact match for volume.balance -racks/-nodes filter (#9279)
* fix(shell): correct volume.list -writable filter unit and comparison * fix(shell): correct volume.list -writable filter unit and comparison * chore(shell): fix typo in EC shard helper param names * fix(shell): use exact match for volume.balance -racks/-nodes filter The old strings.Contains-based filter quietly included any id that was a substring of the user-supplied flag value (e.g. -racks=rack10 also matched rack1). Replace it with an exact-match set parsed from the comma-separated flag value, and add regression tests for both -racks and -nodes paths. Also fix a small typo in the "remote storage" error returned by maybeMoveOneVolume. * fix(shell): use exact match for volume.balance -racks/-nodes filter The old strings.Contains-based filter quietly included any id that was a substring of the user-supplied flag value (e.g. -racks=rack10 also matched rack1). Replace it with an exact-match set parsed from the comma-separated flag value, and add regression tests for both -racks and -nodes paths. Also fix a small typo in the "remote storage" error returned by maybeMoveOneVolume. * refactor(shell): drop nil sentinel in splitCSVSet, use len() in callers
This commit is contained in:
1 parent
1da091f798
commit
60c76120fc
2 files changed
+102
-3
No files matched your search
@@ -215,17 +215,32 @@ func (c *commandVolumeBalance) balanceVolumeServersByDiskType(diskType types.Dis
|
||||
return nil
|
||||
}
|
||||
|
||||
// splitCSVSet parses a comma-separated list into a set for exact-match filtering.
|
||||
// Whitespace around items is trimmed and empty items are skipped, so callers
|
||||
// can use len(set) > 0 to test whether any filter was specified.
|
||||
func splitCSVSet(csv string) map[string]bool {
|
||||
set := make(map[string]bool)
|
||||
for _, item := range strings.Split(csv, ",") {
|
||||
if item = strings.TrimSpace(item); item != "" {
|
||||
set[item] = true
|
||||
}
|
||||
}
|
||||
return set
|
||||
}
|
||||
|
||||
func collectVolumeServersByDcRackNode(t *master_pb.TopologyInfo, selectedDataCenter string, selectedRacks string, selectedNodes string) (nodes []*Node) {
|
||||
rackSet := splitCSVSet(selectedRacks)
|
||||
nodeSet := splitCSVSet(selectedNodes)
|
||||
for _, dc := range t.DataCenterInfos {
|
||||
if selectedDataCenter != "" && dc.Id != selectedDataCenter {
|
||||
continue
|
||||
}
|
||||
for _, r := range dc.RackInfos {
|
||||
if selectedRacks != "" && !strings.Contains(selectedRacks, r.Id) {
|
||||
if len(rackSet) > 0 && !rackSet[r.Id] {
|
||||
continue
|
||||
}
|
||||
for _, dn := range r.DataNodeInfos {
|
||||
if selectedNodes != "" && !strings.Contains(selectedNodes, dn.Id) {
|
||||
if len(nodeSet) > 0 && !nodeSet[dn.Id] {
|
||||
continue
|
||||
}
|
||||
nodes = append(nodes, &Node{
|
||||
@@ -488,7 +503,7 @@ func maybeMoveOneVolume(commandEnv *CommandEnv, volumeReplicas map[uint32][]*Vol
|
||||
}
|
||||
|
||||
if candidateVolume.RemoteStorageName != "" {
|
||||
return false, fmt.Errorf("does not move volume in remove storage")
|
||||
return false, fmt.Errorf("does not move volume in remote storage")
|
||||
}
|
||||
|
||||
if candidateVolume.ReplicaPlacement > 0 {
|
||||
|
||||
Reference in new issue
Block a user