diff --git a/docs/developer_guides/developer_guides.md b/docs/developer_guides/developer_guides.md index 2ae110e14f..a080d13950 100644 --- a/docs/developer_guides/developer_guides.md +++ b/docs/developer_guides/developer_guides.md @@ -1133,6 +1133,7 @@ func (meta *metaTable) AddCollection(coll *CollectionMeta) error func (meta *metaTable) DeleteCollection(collId UniqueId) error func (meta *metaTable) HasCollection(collId UniqueId) bool func (meta *metaTable) GetCollectionByName(collName string) (*CollectionMeta, error) +func (meta *metaTable) ListCollections()([]string, error) func (meta *metaTable) AddPartition(collId UniqueId, tag string) error func (meta *metaTable) HasPartition(collId UniqueId, tag string) bool diff --git a/internal/master/meta_table.go b/internal/master/meta_table.go index 0b676dcd03..918a36c190 100644 --- a/internal/master/meta_table.go +++ b/internal/master/meta_table.go @@ -287,6 +287,17 @@ func (mt *metaTable) GetCollectionByName(collectionName string) (*pb.CollectionM return &col, nil } +func (mt *metaTable) ListCollections() ([]string, error) { + mt.ddLock.RLock() + defer mt.ddLock.RUnlock() + + colls := make([]string, 0, len(mt.collName2ID)) + for name := range mt.collName2ID { + colls = append(colls, name) + } + return colls, nil +} + func (mt *metaTable) AddPartition(collID UniqueID, tag string) error { mt.ddLock.Lock() defer mt.ddLock.Unlock() diff --git a/internal/master/meta_table_test.go b/internal/master/meta_table_test.go index 33af155f80..907cd3bbda 100644 --- a/internal/master/meta_table_test.go +++ b/internal/master/meta_table_test.go @@ -102,6 +102,11 @@ func TestMetaTable_Collection(t *testing.T) { assert.NotNil(t, err) err = meta.AddCollection(&colMeta5) assert.NotNil(t, err) + + collsName, err := meta.ListCollections() + assert.Nil(t, err) + assert.Equal(t, collsName, []string{"coll1", "coll2"}) + hasCollection := meta.HasCollection(colMeta.ID) assert.True(t, hasCollection) err = meta.AddPartition(colMeta.ID, "p1")