From e653ad27e2d5eb527def935a88b36a3dce63da1e Mon Sep 17 00:00:00 2001 From: jaime Date: Fri, 21 Jun 2024 11:36:00 +0800 Subject: [PATCH] fix: metrics database_num is 0 after restarting rootcoord (#34011) issue: #34041 Signed-off-by: jaime --- internal/rootcoord/meta_table.go | 13 ++++++++++--- internal/rootcoord/root_coord.go | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/rootcoord/meta_table.go b/internal/rootcoord/meta_table.go index c77b9f534e..b824cb0658 100644 --- a/internal/rootcoord/meta_table.go +++ b/internal/rootcoord/meta_table.go @@ -141,6 +141,7 @@ func (mt *MetaTable) reload() error { metrics.RootCoordNumOfCollections.Reset() metrics.RootCoordNumOfPartitions.Reset() + metrics.RootCoordNumOfDatabases.Set(0) // recover databases. dbs, err := mt.catalog.ListDatabases(mt.ctx, typeutil.MaxTimestamp) @@ -186,6 +187,7 @@ func (mt *MetaTable) reload() error { } } + metrics.RootCoordNumOfDatabases.Inc() metrics.RootCoordNumOfCollections.WithLabelValues(dbName).Add(float64(collectionNum)) log.Info("collections recovered from db", zap.String("db_name", dbName), zap.Int64("collection_num", collectionNum), @@ -257,7 +259,11 @@ func (mt *MetaTable) CreateDatabase(ctx context.Context, db *model.Database, ts mt.ddLock.Lock() defer mt.ddLock.Unlock() - return mt.createDatabasePrivate(ctx, db, ts) + if err := mt.createDatabasePrivate(ctx, db, ts); err != nil { + return err + } + metrics.RootCoordNumOfDatabases.Inc() + return nil } func (mt *MetaTable) createDatabasePrivate(ctx context.Context, db *model.Database, ts typeutil.Timestamp) error { @@ -273,8 +279,8 @@ func (mt *MetaTable) createDatabasePrivate(ctx context.Context, db *model.Databa mt.names.createDbIfNotExist(dbName) mt.aliases.createDbIfNotExist(dbName) mt.dbName2Meta[dbName] = db - log.Ctx(ctx).Info("create database", zap.String("db", dbName), zap.Uint64("ts", ts)) + log.Ctx(ctx).Info("create database", zap.String("db", dbName), zap.Uint64("ts", ts)) return nil } @@ -324,8 +330,9 @@ func (mt *MetaTable) DropDatabase(ctx context.Context, dbName string, ts typeuti mt.names.dropDb(dbName) mt.aliases.dropDb(dbName) delete(mt.dbName2Meta, dbName) - log.Ctx(ctx).Info("drop database", zap.String("db", dbName), zap.Uint64("ts", ts)) + metrics.RootCoordNumOfDatabases.Dec() + log.Ctx(ctx).Info("drop database", zap.String("db", dbName), zap.Uint64("ts", ts)) return nil } diff --git a/internal/rootcoord/root_coord.go b/internal/rootcoord/root_coord.go index 2f40efa440..62f6cef9fd 100644 --- a/internal/rootcoord/root_coord.go +++ b/internal/rootcoord/root_coord.go @@ -867,7 +867,6 @@ func (c *Core) CreateDatabase(ctx context.Context, in *milvuspb.CreateDatabaseRe metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.SuccessLabel).Inc() metrics.RootCoordDDLReqLatency.WithLabelValues(method).Observe(float64(tr.ElapseSpan().Milliseconds())) - metrics.RootCoordNumOfDatabases.Inc() log.Ctx(ctx).Info("done to create database", zap.String("role", typeutil.RootCoordRole), zap.String("dbName", in.GetDbName()), zap.Int64("msgID", in.GetBase().GetMsgID()), zap.Uint64("ts", t.GetTs())) @@ -912,7 +911,6 @@ func (c *Core) DropDatabase(ctx context.Context, in *milvuspb.DropDatabaseReques metrics.RootCoordDDLReqCounter.WithLabelValues(method, metrics.SuccessLabel).Inc() metrics.RootCoordDDLReqLatency.WithLabelValues(method).Observe(float64(tr.ElapseSpan().Milliseconds())) - metrics.RootCoordNumOfDatabases.Dec() metrics.CleanupRootCoordDBMetrics(in.GetDbName()) log.Ctx(ctx).Info("done to drop database", zap.String("role", typeutil.RootCoordRole), zap.String("dbName", in.GetDbName()), zap.Int64("msgID", in.GetBase().GetMsgID()),