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_ec_decode.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'weed/shell/command_ec_decode.go') diff --git a/weed/shell/command_ec_decode.go b/weed/shell/command_ec_decode.go index 673a9a4f2..f1f3bf133 100644 --- a/weed/shell/command_ec_decode.go +++ b/weed/shell/command_ec_decode.go @@ -34,6 +34,11 @@ func (c *commandEcDecode) Help() string { ec.decode [-collection=""] [-volumeId=] + The -collection parameter supports regular expressions for pattern matching: + - Use exact match: ec.decode -collection="^mybucket$" + - Match multiple buckets: ec.decode -collection="bucket.*" + - Match all collections: ec.decode -collection=".*" + ` } @@ -67,8 +72,11 @@ func (c *commandEcDecode) Do(args []string, commandEnv *CommandEnv, writer io.Wr } // apply to all volumes in the collection - volumeIds := collectEcShardIds(topologyInfo, *collection) - fmt.Printf("ec encode volumes: %v\n", volumeIds) + volumeIds, err := collectEcShardIds(topologyInfo, *collection) + if err != nil { + return err + } + fmt.Printf("ec decode volumes: %v\n", volumeIds) for _, vid := range volumeIds { if err = doEcDecode(commandEnv, topologyInfo, *collection, vid); err != nil { return err @@ -240,13 +248,18 @@ func lookupVolumeIds(commandEnv *CommandEnv, volumeIds []string) (volumeIdLocati return resp.VolumeIdLocations, nil } -func collectEcShardIds(topoInfo *master_pb.TopologyInfo, selectedCollection string) (vids []needle.VolumeId) { +func collectEcShardIds(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) { if diskInfo, found := dn.DiskInfos[string(types.HardDriveType)]; found { for _, v := range diskInfo.EcShardInfos { - if v.Collection == selectedCollection { + if collectionRegex.MatchString(v.Collection) { vidMap[v.Id] = true } } -- cgit v1.2.3