Skip to content

Commit

Permalink
Add index params with kv pair (#241)
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Zhang <[email protected]>
  • Loading branch information
xiaocai2333 authored Feb 5, 2024
1 parent 5178eef commit 5f0e9f6
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions states/etcd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func RepairCommand(cli clientv3.KV, basePath string) *cobra.Command {
// repair miss index metric_type
repair.IndexMetricCommand(cli, basePath),
repair.DiskAnnIndexParamsCommand(cli, basePath),
repair.AddIndexParamsCommand(cli, basePath),
)

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

import (
"fmt"

"github.com/spf13/cobra"

commonpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/commonpb"
indexpbv2 "github.com/milvus-io/birdwatcher/proto/v2.2/indexpb"
clientv3 "go.etcd.io/etcd/client/v3"
)

// AddIndexParamsCommand return repair segment command.
func AddIndexParamsCommand(cli clientv3.KV, basePath string) *cobra.Command {
cmd := &cobra.Command{
Use: "add_index_params_retrieve_friendly",
Aliases: []string{"add_index_params_retrieve_friendly"},
Short: "check index parma and try to add retrieve_friendly",
Run: func(cmd *cobra.Command, args []string) {
collID, err := cmd.Flags().GetInt64("collection")
if err != nil {
fmt.Println(err.Error())
return
}
run, err := cmd.Flags().GetBool("run")
if err != nil {
fmt.Println(err.Error())
return
}
key, err := cmd.Flags().GetString("key")
if err != nil {
fmt.Println(err.Error())
return
}
value, err := cmd.Flags().GetString("value")
if err != nil {
fmt.Println(err.Error())
return
}
indexes, err := listIndexMetaV2(cli, basePath)
if err != nil {
fmt.Println(err.Error())
return
}
newIndexes := make([]*indexpbv2.FieldIndex, 0)
for _, index := range indexes {
if collID != 0 && index.IndexInfo.CollectionID != collID {
continue
}
newIndex := &indexpbv2.FieldIndex{
IndexInfo: &indexpbv2.IndexInfo{
CollectionID: index.GetIndexInfo().GetCollectionID(),
FieldID: index.GetIndexInfo().GetFieldID(),
IndexName: index.GetIndexInfo().GetIndexName(),
IndexID: index.GetIndexInfo().GetIndexID(),
TypeParams: index.GetIndexInfo().GetTypeParams(),
IndexParams: index.GetIndexInfo().GetIndexParams(),
IndexedRows: index.GetIndexInfo().GetIndexedRows(),
TotalRows: index.GetIndexInfo().GetTotalRows(),
State: index.GetIndexInfo().GetState(),
IndexStateFailReason: index.GetIndexInfo().GetIndexStateFailReason(),
IsAutoIndex: index.GetIndexInfo().GetIsAutoIndex(),
UserIndexParams: index.GetIndexInfo().GetUserIndexParams(),
},
Deleted: index.GetDeleted(),
CreateTime: index.GetCreateTime(),
}
indexType := ""
for _, pair := range index.IndexInfo.IndexParams {
if pair.Key == "index_type" {
indexType = pair.Value
}
}
if indexType != "DISKANN" && indexType != "HNSW" {
continue
}
exist := false
for _, pair := range index.IndexInfo.IndexParams {
if pair.Key == key {
exist = true
break
}
}
if !exist {
newIndex.IndexInfo.IndexParams = append(newIndex.IndexInfo.IndexParams, &commonpbv2.KeyValuePair{
Key: key,
Value: value,
})
newIndexes = append(newIndexes, newIndex)
}
}
if !run {
fmt.Println("after repair index:")
for _, index := range newIndexes {
printIndexV2(*index)
}
return
}
for _, index := range newIndexes {
if err := writeRepairedIndex(cli, basePath, index); err != nil {
fmt.Println(err.Error())
return
}
}
afterRepairIndexes, err := listIndexMetaV2(cli, basePath)
if err != nil {
fmt.Println(err.Error())
return
}
for _, index := range afterRepairIndexes {
printIndexV2(index)
}
},
}

cmd.Flags().Int64("collection", 0, "collection id to filter with")
cmd.Flags().Bool("run", false, "actual do repair")
cmd.Flags().String("key", "retrieve_friendly", "add params key")
cmd.Flags().String("value", "true", "add params value")
return cmd
}

0 comments on commit 5f0e9f6

Please sign in to comment.