diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-08-23 11:04:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-23 11:04:24 -0700 |
| commit | 41aedaa6876d5ef200928aafaec7c9d0b8a8a764 (patch) | |
| tree | e194f1666b7d467dc17bd045ab79c735ad1cdc05 /weed/shell/command_volume_tier_download.go | |
| parent | a367c39967cc41179b72ea0674b663cefd95ec0b (diff) | |
| download | seaweedfs-41aedaa6876d5ef200928aafaec7c9d0b8a8a764.tar.xz seaweedfs-41aedaa6876d5ef200928aafaec7c9d0b8a8a764.zip | |
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
Diffstat (limited to 'weed/shell/command_volume_tier_download.go')
| -rw-r--r-- | weed/shell/command_volume_tier_download.go | 16 |
1 files changed, 13 insertions, 3 deletions
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=<volume_id> + 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 } } |
