diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index 9e2fe4aaf004d8bc730242f34228c5903f7bc817..2ceae91f7ccf64a24b331d53db3e6a75b49ba367 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -70,6 +70,7 @@ int32_t metaCacheDrop(SMeta* pMeta, int64_t uid); int32_t metaStatsCacheUpsert(SMeta* pMeta, SMetaStbStats* pInfo); int32_t metaStatsCacheDrop(SMeta* pMeta, int64_t uid); int32_t metaStatsCacheGet(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo); +void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t delta); struct SMeta { TdThreadRwlock lock; diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 4aabd3980050cb805d722b8d68a71f650be82ea1..620022c06de5fd675b6ef55c10840874243d33b1 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -1445,3 +1445,13 @@ int32_t metaGetStbStats(SMeta *pMeta, int64_t uid, SMetaStbStats *pInfo) { _exit: return code; } + +void metaUpdateStbStats(SMeta *pMeta, int64_t uid, int64_t delta) { + SMetaStbStats stats = {0}; + + if (metaStatsCacheGet(pMeta, uid, &stats) == TSDB_CODE_SUCCESS) { + stats.ctbNum += delta; + + metaStatsCacheUpsert(pMeta, &stats); + } +} diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 6dadce80ca459ce371cf13311b643974e6f1cd07..5921adfbfae6c4d318a5332ce06f9ec527548121 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -371,7 +371,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { // update uid index metaUpdateUidIdx(pMeta, &nStbEntry); - metaStatsCacheDrop(pMeta, nStbEntry.uid); + // metaStatsCacheDrop(pMeta, nStbEntry.uid); metaULock(pMeta); @@ -450,6 +450,10 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq, STableMe #endif ++pMeta->pVnode->config.vndStats.numOfCTables; + + metaWLock(pMeta); + metaUpdateStbStats(pMeta, me.ctbEntry.suid, 1); + metaULock(pMeta); } else { me.ntbEntry.ctime = pReq->ctime; me.ntbEntry.ttlDays = pReq->ttl; @@ -670,6 +674,8 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn); --pMeta->pVnode->config.vndStats.numOfCTables; + + metaUpdateStbStats(pMeta, e.ctbEntry.suid, -1); } else if (e.type == TSDB_NORMAL_TABLE) { // drop schema.db (todo)