Skip to content

Commit

Permalink
Add remove compaction command
Browse files Browse the repository at this point in the history
Signed-off-by: wayblink <[email protected]>
  • Loading branch information
wayblink committed Jul 16, 2024
1 parent 4511481 commit 9b2c959
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions states/etcd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func RemoveCommand(cli clientv3.KV, instanceName, basePath string) *cobra.Comman
remove.EtcdConfigCommand(cli, instanceName),
// remove collection has been dropped
remove.CollectionCleanCommand(cli, basePath),
// remove compaction task
remove.CompactionTaskCleanCommand(cli, basePath),
)

return removeCmd
Expand Down
66 changes: 66 additions & 0 deletions states/etcd/remove/compaction_task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package remove

import (
"context"
"fmt"
"path"

"github.com/spf13/cobra"
clientv3 "go.etcd.io/etcd/client/v3"

"github.com/milvus-io/birdwatcher/models"
"github.com/milvus-io/birdwatcher/states/etcd/common"
)

// CompactionTaskCleanCommand returns command to remove
func CompactionTaskCleanCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "compaction",
Short: "Remove compaction task",
Run: func(cmd *cobra.Command, args []string) {
compactionType, err := cmd.Flags().GetString("type")
if err != nil {
fmt.Println(err.Error())
return
}
triggerID, err := cmd.Flags().GetString("jobID")
if err != nil {
fmt.Println(err.Error())
return
}
planID, err := cmd.Flags().GetString("taskID")
if err != nil {
fmt.Println(err.Error())
return
}

compactionTasks, err := common.ListCompactionTask(context.TODO(), cli, basePath, func(task *models.CompactionTask) bool {

Check failure on line 37 in states/etcd/remove/compaction_task.go

View workflow job for this annotation

GitHub Actions / lint

SA4006: this value of `err` is never used (staticcheck)
if compactionType != task.GetType().String() {
return false
}
if triggerID != "" && fmt.Sprint(task.GetTriggerID()) != triggerID {
return false
}
if planID != "" && fmt.Sprint(task.GetPlanID()) != planID {
return false
}
return true
})

for _, task := range compactionTasks {
key := path.Join(basePath, common.CompactionTaskPrefix, task.GetType().String(), fmt.Sprint(task.GetTriggerID()), fmt.Sprint(task.GetPlanID()))
_, err = cli.Delete(context.TODO(), key, clientv3.WithPrefix())
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("clean compaction task done, prefix: %s\n", key)
}
},
}

cmd.Flags().String("type", "ClusteringCompaction", "compaction type")
cmd.Flags().String("jobID", "", "jobID also known as triggerID")
cmd.Flags().String("taskID", "", "taskID also known as planID")
return cmd
}

0 comments on commit 9b2c959

Please sign in to comment.