Fix collection metrics leakage (#19944)

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>

Signed-off-by: xiaofan-luan <xiaofan.luan@zilliz.com>
pull/19967/head
Xiaofan 2022-10-21 10:13:28 +08:00 committed by GitHub
parent f1f305007f
commit 3d3289ce3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 8 deletions

View File

@ -110,12 +110,14 @@ func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *p
collectionName := request.CollectionName
collectionID := request.CollectionID
var aliasName []string
if globalMetaCache != nil {
if collectionName != "" {
globalMetaCache.RemoveCollection(ctx, collectionName) // no need to return error, though collection may be not cached
}
if request.CollectionID != UniqueID(0) {
globalMetaCache.RemoveCollectionsByID(ctx, collectionID)
aliasName = globalMetaCache.RemoveCollectionsByID(ctx, collectionID)
}
}
if request.GetBase().GetMsgType() == commonpb.MsgType_DropCollection {
@ -123,6 +125,9 @@ func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *p
node.chMgr.removeDMLStream(request.GetCollectionID())
// clean up collection level metrics
metrics.CleanupCollectionMetrics(Params.ProxyCfg.GetNodeID(), collectionName)
for _, alias := range aliasName {
metrics.CleanupCollectionMetrics(Params.ProxyCfg.GetNodeID(), alias)
}
}
logutil.Logger(ctx).Info("complete to invalidate collection meta cache",
zap.String("role", typeutil.ProxyRole),

View File

@ -63,7 +63,7 @@ type Cache interface {
GetShards(ctx context.Context, withCache bool, collectionName string) (map[string][]nodeInfo, error)
ClearShards(collectionName string)
RemoveCollection(ctx context.Context, collectionName string)
RemoveCollectionsByID(ctx context.Context, collectionID UniqueID)
RemoveCollectionsByID(ctx context.Context, collectionID UniqueID) []string
RemovePartition(ctx context.Context, collectionName string, partitionName string)
// GetCredentialInfo operate credential cache
@ -515,14 +515,17 @@ func (m *MetaCache) RemoveCollection(ctx context.Context, collectionName string)
delete(m.collInfo, collectionName)
}
func (m *MetaCache) RemoveCollectionsByID(ctx context.Context, collectionID UniqueID) {
func (m *MetaCache) RemoveCollectionsByID(ctx context.Context, collectionID UniqueID) []string {
m.mu.Lock()
defer m.mu.Unlock()
var collNames []string
for k, v := range m.collInfo {
if v.collID == collectionID {
delete(m.collInfo, k)
collNames = append(collNames, k)
}
}
return collNames
}
func (m *MetaCache) RemovePartition(ctx context.Context, collectionName, partitionName string) {

View File

@ -50,9 +50,10 @@ func (a *alterCollectionTask) Execute(ctx context.Context) error {
})
redoTask.AddSyncStep(&expireCacheStep{
baseStep: baseStep{core: a.core},
collectionID: oldColl.CollectionID,
ts: ts,
baseStep: baseStep{core: a.core},
collectionNames: []string{oldColl.Name},
collectionID: oldColl.CollectionID,
ts: ts,
})
a.Req.CollectionID = oldColl.CollectionID

View File

@ -56,7 +56,7 @@ func (t *createPartitionTask) Execute(ctx context.Context) error {
undoTask := newBaseUndoTask(t.core.stepExecutor)
undoTask.AddStep(&expireCacheStep{
baseStep: baseStep{core: t.core},
collectionNames: []string{t.Req.GetCollectionName()},
collectionNames: []string{t.collMeta.Name},
collectionID: t.collMeta.CollectionID,
ts: t.GetTs(),
}, &nullStep{})

View File

@ -63,7 +63,7 @@ func (t *dropPartitionTask) Execute(ctx context.Context) error {
})
redoTask.AddSyncStep(&expireCacheStep{
baseStep: baseStep{core: t.core},
collectionNames: []string{t.Req.GetCollectionName()},
collectionNames: []string{t.collMeta.Name},
collectionID: t.collMeta.CollectionID,
ts: t.GetTs(),
})