Skip to content

Commit

Permalink
Add dbid param for show collection cmd (#160)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Jun 28, 2023
1 parent d5bcfd9 commit 4f7744c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions models/collection.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import (
"strconv"
"strings"
"sync"

"github.com/milvus-io/birdwatcher/proto/v2.0/commonpb"
Expand All @@ -23,6 +25,7 @@ type Collection struct {
ConsistencyLevel ConsistencyLevel
State CollectionState
Properties map[string]string
DBID int64

// etcd collection key
key string
Expand Down Expand Up @@ -105,6 +108,7 @@ func NewCollectionFromV2_1(info *etcdpb.CollectionInfo, key string) *Collection
func NewCollectionFromV2_2(info *etcdpbv2.CollectionInfo, key string, fields []*schemapbv2.FieldSchema) *Collection {
c := newCollectionFromBase[*etcdpbv2.CollectionInfo, *commonpbv2.KeyDataPair](info)
c.key = key
c.DBID = parseDBID(key)
c.State = CollectionState(info.GetState())
schema := info.GetSchema()
schema.Fields = fields
Expand All @@ -125,6 +129,18 @@ func NewCollectionFromV2_2(info *etcdpbv2.CollectionInfo, key string, fields []*
return c
}

func parseDBID(key string) int64 {
parts := strings.Split(key, "/")
if len(parts) < 2 {
return 0
}
id, err := strconv.ParseInt(parts[len(parts)-2], 10, 64)
if err != nil {
return 0
}
return id
}

func getChannels[cp interface {
GetKey() string
GetData() []byte
Expand Down
10 changes: 10 additions & 0 deletions states/etcd/show/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func CollectionCommand(cli clientv3.KV, basePath string) *cobra.Command {
fmt.Println(err.Error())
return
}
dbID, err := cmd.Flags().GetInt64("dbid")
if err != nil {
fmt.Println(err.Error())
return
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -50,6 +55,9 @@ func CollectionCommand(cli clientv3.KV, basePath string) *cobra.Command {
if collectionName != "" && coll.Schema.Name != collectionName {
return false
}
if dbID > -1 && coll.DBID != dbID {
return false
}
total++
return true
})
Expand All @@ -76,11 +84,13 @@ func CollectionCommand(cli clientv3.KV, basePath string) *cobra.Command {

cmd.Flags().Int64("id", 0, "collection id to display")
cmd.Flags().String("name", "", "collection name to display")
cmd.Flags().Int64("dbid", -1, "database id")
return cmd
}

func printCollection(collection *models.Collection) {
fmt.Println("================================================================================")
fmt.Printf("DBID: %d\n", collection.DBID)
fmt.Printf("Collection ID: %d\tCollection Name: %s\n", collection.ID, collection.Schema.Name)
t, _ := utils.ParseTS(collection.CreateTime)
fmt.Printf("Collection State: %s\tCreate Time: %s\n", collection.State.String(), t.Format("2006-01-02 15:04:05"))
Expand Down

0 comments on commit 4f7744c

Please sign in to comment.