From bf5fb3cd99e725d2ca0d3a9fb374d6bbf29ce6d4 Mon Sep 17 00:00:00 2001 From: wgcn <1026688210@qq.com> Date: Mon, 31 Oct 2022 13:25:35 +0800 Subject: [PATCH] improve show collection (#20124) Signed-off-by: wgcn <1026688210@qq.com> --- internal/rootcoord/meta_table.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index 50e0f3d2fe..bdf9b964ad 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -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()