From 41aedaa6876d5ef200928aafaec7c9d0b8a8a764 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 23 Aug 2025 11:04:24 -0700 Subject: Shell: support regular expression for collection selection (#7158) * support regular expression for collection selection * refactor * ordering * fix exact match * Update command_volume_balance_test.go * simplify * Update command_volume_balance.go * comment --- weed/shell/command_volume_tier_download.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'weed/shell/command_volume_tier_download.go') diff --git a/weed/shell/command_volume_tier_download.go b/weed/shell/command_volume_tier_download.go index 9cea40eb2..4626bd383 100644 --- a/weed/shell/command_volume_tier_download.go +++ b/weed/shell/command_volume_tier_download.go @@ -33,6 +33,11 @@ func (c *commandVolumeTierDownload) Help() string { volume.tier.download [-collection=""] volume.tier.download [-collection=""] -volumeId= + The -collection parameter supports regular expressions for pattern matching: + - Use exact match: volume.tier.download -collection="^mybucket$" + - Match multiple buckets: volume.tier.download -collection="bucket.*" + - Match all collections: volume.tier.download -collection=".*" + e.g.: volume.tier.download -volumeId=7 @@ -73,7 +78,7 @@ func (c *commandVolumeTierDownload) Do(args []string, commandEnv *CommandEnv, wr // apply to all volumes in the collection // reusing collectVolumeIdsForEcEncode for now - volumeIds := collectRemoteVolumes(topologyInfo, *collection) + volumeIds, err := collectRemoteVolumes(topologyInfo, *collection) if err != nil { return err } @@ -87,13 +92,18 @@ func (c *commandVolumeTierDownload) Do(args []string, commandEnv *CommandEnv, wr return nil } -func collectRemoteVolumes(topoInfo *master_pb.TopologyInfo, selectedCollection string) (vids []needle.VolumeId) { +func collectRemoteVolumes(topoInfo *master_pb.TopologyInfo, collectionPattern string) (vids []needle.VolumeId, err error) { + // compile regex pattern for collection matching + collectionRegex, err := compileCollectionPattern(collectionPattern) + if err != nil { + return nil, fmt.Errorf("invalid collection pattern '%s': %v", collectionPattern, err) + } vidMap := make(map[uint32]bool) eachDataNode(topoInfo, func(dc DataCenterId, rack RackId, dn *master_pb.DataNodeInfo) { for _, diskInfo := range dn.DiskInfos { for _, v := range diskInfo.VolumeInfos { - if v.Collection == selectedCollection && v.RemoteStorageKey != "" && v.RemoteStorageName != "" { + if collectionRegex.MatchString(v.Collection) && v.RemoteStorageKey != "" && v.RemoteStorageName != "" { vidMap[v.Id] = true } } -- cgit v1.2.3