Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: manual compaction trigger #269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions states/etcd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func RepairCommand(cli clientv3.KV, basePath string) *cobra.Command {
repair.IndexMetricCommand(cli, basePath),
repair.DiskAnnIndexParamsCommand(cli, basePath),
repair.AddIndexParamsCommand(cli, basePath),
// repair manual compaction
repair.ManualCompactionCommand(cli, basePath),
)

return repairCmd
Expand Down
73 changes: 73 additions & 0 deletions states/etcd/repair/manual_compaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package repair

import (
"context"
"fmt"
"time"

"github.com/milvus-io/birdwatcher/proto/v2.0/commonpb"
"github.com/milvus-io/birdwatcher/proto/v2.0/datapb"
"github.com/milvus-io/birdwatcher/proto/v2.0/milvuspb"
"github.com/milvus-io/birdwatcher/states/etcd/common"
"github.com/spf13/cobra"
clientv3 "go.etcd.io/etcd/client/v3"
"google.golang.org/grpc"
)

func ManualCompactionCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "manual-compaction",
Short: "do manual compaction",
Run: func(cmd *cobra.Command, args []string) {
collID, err := cmd.Flags().GetInt64("collection")
if err != nil {
fmt.Println(err.Error())
return
}
if collID == 0 {
fmt.Printf("collection id should not be zero\n")
return
}
doManualCompaction(cli, basePath, collID)
},
}
cmd.Flags().Int64("collection", 0, "collection id")
return cmd
}

func doManualCompaction(cli clientv3.KV, basePath string, collID int64) {
sessions, err := common.ListSessions(cli, basePath)
if err != nil {
fmt.Println("failed to list session")
return
}
for _, session := range sessions {
if session.ServerName == "datacoord" {
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.WithTimeout(2 * time.Second),
}

conn, err := grpc.DialContext(context.Background(), session.Address, opts...)
if err != nil {
fmt.Printf("failed to connect to DataCoord(%d) addr: %s, err: %s\n", session.ServerID, session.Address, err.Error())
return
}

client := datapb.NewDataCoordClient(conn)
result, err := client.ManualCompaction(context.Background(), &milvuspb.ManualCompactionRequest{
CollectionID: collID,
})
if err != nil {
fmt.Println("failed to call ManualCompaction", err.Error())
return
}
if result.Status.ErrorCode != commonpb.ErrorCode_Success {
fmt.Printf("ManualCompaction failed, error code = %s, reason = %s\n", result.Status.ErrorCode.String(), result.Status.Reason)
return
}
fmt.Printf("ManualCompaction trigger success, id: %d\n", result.CompactionID)
}
}
}
Loading