From cb442f84969fe042d202da063d9bde58ffb363b6 Mon Sep 17 00:00:00 2001 From: "zhenshan.cao" Date: Mon, 15 Jul 2024 19:44:05 +0800 Subject: [PATCH] Fixbug: filter by planID is not working Signed-off-by: zhenshan.cao --- states/etcd/show/compaction.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/states/etcd/show/compaction.go b/states/etcd/show/compaction.go index 018a99b4..4b650f17 100644 --- a/states/etcd/show/compaction.go +++ b/states/etcd/show/compaction.go @@ -3,9 +3,12 @@ package show import ( "context" "fmt" + "sort" "strings" "time" + "github.com/samber/lo" + "github.com/milvus-io/birdwatcher/framework" "github.com/milvus-io/birdwatcher/models" "github.com/milvus-io/birdwatcher/states/etcd/common" @@ -20,7 +23,8 @@ type CompactionTaskParam struct { CollectionID int64 `name:"collectionID" default:"0" desc:"collection id to filter"` PartitionID int64 `name:"partitionID" default:"0" desc:"partitionID id to filter"` TriggerID int64 `name:"triggerID" default:"0" desc:"TriggerID to filter"` - PlanID int64 ` name:"planID" default:"" desc:"PlanID to filter"` + PlanID int64 ` name:"planID" default:"0" desc:"PlanID to filter"` + SegmentID int64 ` name:"segmentID" default:"0" desc:"SegmentID to filter"` Detail bool `name:"detail" default:"false" desc:"flags indicating whether printing input/result segmentIDs"` } @@ -45,8 +49,11 @@ func (c *ComponentShow) CompactionTaskCommand(ctx context.Context, p *Compaction if p.TriggerID > 0 && task.GetTriggerID() != p.TriggerID { return false } + if p.PlanID > 0 && task.GetPlanID() != p.PlanID { + return false + } - if p.PlanID > 0 && task.GetPlanID() != p.TriggerID { + if p.SegmentID > 0 && !lo.Contains(task.GetInputSegments(), p.SegmentID) { return false } if p.State != "" && !strings.EqualFold(p.State, task.GetState().String()) { @@ -58,6 +65,9 @@ func (c *ComponentShow) CompactionTaskCommand(ctx context.Context, p *Compaction if err != nil { return nil, err } + sort.Slice(compactionTasks, func(i, j int) bool { + return compactionTasks[i].GetPlanID() < compactionTasks[j].GetPlanID() + }) return &CompactionTasks{ tasks: compactionTasks, total: total,