improve show collection (#20124)

Signed-off-by: wgcn <1026688210@qq.com>
This commit is contained in:
wgcn 2022-10-31 13:25:35 +08:00 committed by GitHub
parent 3625b02d50
commit bf5fb3cd99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -355,6 +355,10 @@ func (mt *MetaTable) ListCollections(ctx context.Context, ts Timestamp) ([]*mode
mt.ddLock.RLock()
defer mt.ddLock.RUnlock()
if isMaxTs(ts) {
return mt.listCollectionFromCache()
}
// list collections should always be loaded from catalog.
ctx1 := contextutil.WithTenantID(ctx, Params.CommonCfg.ClusterName)
colls, err := mt.catalog.ListCollections(ctx1, ts)
@ -370,6 +374,16 @@ func (mt *MetaTable) ListCollections(ctx context.Context, ts Timestamp) ([]*mode
return onlineCollections, nil
}
func (mt *MetaTable) listCollectionFromCache() ([]*model.Collection, error) {
collectionFromCache := make([]*model.Collection, 0)
for _, meta := range mt.collID2Meta {
if meta.Available() {
collectionFromCache = append(collectionFromCache, meta)
}
}
return collectionFromCache, nil
}
func (mt *MetaTable) ListAbnormalCollections(ctx context.Context, ts Timestamp) ([]*model.Collection, error) {
mt.ddLock.RLock()
defer mt.ddLock.RUnlock()