Browse Source

`ec.encode`: Fix resolution of target collections. (#6585)

* Don't ignore empty (`""`) collection names when computing collections for a given volume ID.

* `ec.encode`: Fix resolution of target collections.

When no `volumeId` parameter is provided, compute volumes
based on the provided collection name, even if it's empty (`""`).

This restores behavior to before recent EC rebalancing rework. See also
ec30a504ba/weed/shell/command_ec_encode.go (L99) .
pull/5490/merge
Lisandro Pin 3 days ago
committed by GitHub
parent
commit
c07596691c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      weed/shell/command_ec_common.go
  2. 6
      weed/shell/command_ec_common_test.go
  3. 12
      weed/shell/command_ec_encode.go

4
weed/shell/command_ec_common.go

@ -248,14 +248,14 @@ func collectCollectionsForVolumeIds(t *master_pb.TopologyInfo, vids []needle.Vol
for _, diskInfo := range dn.DiskInfos { for _, diskInfo := range dn.DiskInfos {
for _, vi := range diskInfo.VolumeInfos { for _, vi := range diskInfo.VolumeInfos {
for _, vid := range vids { for _, vid := range vids {
if needle.VolumeId(vi.Id) == vid && vi.Collection != "" {
if needle.VolumeId(vi.Id) == vid {
found[vi.Collection] = true found[vi.Collection] = true
} }
} }
} }
for _, ecs := range diskInfo.EcShardInfos { for _, ecs := range diskInfo.EcShardInfos {
for _, vid := range vids { for _, vid := range vids {
if needle.VolumeId(ecs.Id) == vid && ecs.Collection != "" {
if needle.VolumeId(ecs.Id) == vid {
found[ecs.Collection] = true found[ecs.Collection] = true
} }
} }

6
weed/shell/command_ec_common_test.go

@ -45,9 +45,9 @@ func TestCollectCollectionsForVolumeIds(t *testing.T) {
{topology1, nil, nil}, {topology1, nil, nil},
{topology1, []needle.VolumeId{}, nil}, {topology1, []needle.VolumeId{}, nil},
{topology1, []needle.VolumeId{needle.VolumeId(9999)}, nil}, {topology1, []needle.VolumeId{needle.VolumeId(9999)}, nil},
{topology1, []needle.VolumeId{needle.VolumeId(2)}, nil},
{topology1, []needle.VolumeId{needle.VolumeId(2), needle.VolumeId(272)}, []string{"collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(2), needle.VolumeId(272), needle.VolumeId(299)}, []string{"collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(2)}, []string{""}},
{topology1, []needle.VolumeId{needle.VolumeId(2), needle.VolumeId(272)}, []string{"", "collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(2), needle.VolumeId(272), needle.VolumeId(299)}, []string{"", "collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95)}, []string{"collection1", "collection2"}}, {topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95)}, []string{"collection1", "collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95), needle.VolumeId(51)}, []string{"collection1", "collection2"}}, {topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95), needle.VolumeId(51)}, []string{"collection1", "collection2"}},
{topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95), needle.VolumeId(51), needle.VolumeId(15)}, []string{"collection0", "collection1", "collection2"}}, {topology1, []needle.VolumeId{needle.VolumeId(272), needle.VolumeId(299), needle.VolumeId(95), needle.VolumeId(51), needle.VolumeId(15)}, []string{"collection0", "collection1", "collection2"}},

12
weed/shell/command_ec_encode.go

@ -98,23 +98,19 @@ func (c *commandEcEncode) Do(args []string, commandEnv *CommandEnv, writer io.Wr
} }
} }
var collections []string
var volumeIds []needle.VolumeId var volumeIds []needle.VolumeId
if vid := needle.VolumeId(*volumeId); vid != 0 { if vid := needle.VolumeId(*volumeId); vid != 0 {
// volumeId is provided // volumeId is provided
volumeIds = append(volumeIds, vid) volumeIds = append(volumeIds, vid)
collections = collectCollectionsForVolumeIds(topologyInfo, volumeIds)
} else { } else {
// apply to all volumes in the collection
// apply to all volumes for the given collection
volumeIds, err = collectVolumeIdsForEcEncode(commandEnv, *collection, *fullPercentage, *quietPeriod) volumeIds, err = collectVolumeIdsForEcEncode(commandEnv, *collection, *fullPercentage, *quietPeriod)
if err != nil { if err != nil {
return err return err
} }
}
var collections []string
if *collection != "" {
collections = []string{*collection}
} else {
collections = collectCollectionsForVolumeIds(topologyInfo, volumeIds)
collections = append(collections, *collection)
} }
// encode all requested volumes... // encode all requested volumes...

Loading…
Cancel
Save