diff --git a/models/collection.go b/models/collection.go index bac93e4..8d17d72 100644 --- a/models/collection.go +++ b/models/collection.go @@ -1,6 +1,8 @@ package models import ( + "strconv" + "strings" "sync" "github.com/milvus-io/birdwatcher/proto/v2.0/commonpb" @@ -23,6 +25,7 @@ type Collection struct { ConsistencyLevel ConsistencyLevel State CollectionState Properties map[string]string + DBID int64 // etcd collection key key string @@ -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 @@ -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 diff --git a/states/etcd/show/collection.go b/states/etcd/show/collection.go index 304b154..8876fed 100644 --- a/states/etcd/show/collection.go +++ b/states/etcd/show/collection.go @@ -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() @@ -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 }) @@ -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"))