提交 00211b32 编写于 作者: D dapan1121

feat: add catalog cache stat

上级 51d81f08
...@@ -44,7 +44,7 @@ extern "C" { ...@@ -44,7 +44,7 @@ extern "C" {
#define CTG_BATCH_FETCH 1 #define CTG_BATCH_FETCH 1
typedef enum { typedef enum {
CTG_CI_CLUSTER, CTG_CI_CLUSTER = 0,
CTG_CI_DNODE, CTG_CI_DNODE,
CTG_CI_QNODE, CTG_CI_QNODE,
CTG_CI_DB, CTG_CI_DB,
...@@ -65,6 +65,10 @@ typedef enum { ...@@ -65,6 +65,10 @@ typedef enum {
CTG_CI_MAX_VALUE, CTG_CI_MAX_VALUE,
} CTG_CACHE_ITEM; } CTG_CACHE_ITEM;
#define CTG_CI_FLAG_LEVEL_GLOBAL (1)
#define CTG_CI_FLAG_LEVEL_CLUSTER (1<<1)
#define CTG_CI_FLAG_LEVEL_DB (1<<2)
enum { enum {
CTG_READ = 1, CTG_READ = 1,
CTG_WRITE, CTG_WRITE,
...@@ -118,9 +122,16 @@ typedef struct SCtgDebug { ...@@ -118,9 +122,16 @@ typedef struct SCtgDebug {
bool cacheEnable; bool cacheEnable;
bool apiEnable; bool apiEnable;
bool metaEnable; bool metaEnable;
bool statEnable;
uint32_t showCachePeriodSec; uint32_t showCachePeriodSec;
} SCtgDebug; } SCtgDebug;
typedef struct SCtgCacheStat {
uint64_t cacheNum[CTG_CI_MAX_VALUE];
uint64_t cacheHit[CTG_CI_MAX_VALUE];
uint64_t cacheNHit[CTG_CI_MAX_VALUE];
} SCtgCacheStat;
typedef struct SCtgTbCacheInfo { typedef struct SCtgTbCacheInfo {
bool inCache; bool inCache;
uint64_t dbId; uint64_t dbId;
...@@ -374,12 +385,6 @@ typedef struct SCtgRuntimeStat { ...@@ -374,12 +385,6 @@ typedef struct SCtgRuntimeStat {
uint64_t numOfOpClearCache; uint64_t numOfOpClearCache;
} SCtgRuntimeStat; } SCtgRuntimeStat;
typedef struct SCtgCacheStat {
uint64_t cacheNum[CTG_CI_MAX_VALUE];
uint64_t cacheHit[CTG_CI_MAX_VALUE];
uint64_t cacheNHit[CTG_CI_MAX_VALUE];
} SCtgCacheStat;
typedef struct SCatalogStat { typedef struct SCatalogStat {
SCtgApiStat api; SCtgApiStat api;
SCtgRuntimeStat runtime; SCtgRuntimeStat runtime;
...@@ -486,7 +491,7 @@ typedef struct SCatalogMgmt { ...@@ -486,7 +491,7 @@ typedef struct SCatalogMgmt {
SCtgQueue queue; SCtgQueue queue;
TdThread updateThread; TdThread updateThread;
SHashObj* pCluster; // key: clusterId, value: SCatalog* SHashObj* pCluster; // key: clusterId, value: SCatalog*
SCatalogStat stat; SCatalogStat statInfo;
SCatalogCfg cfg; SCatalogCfg cfg;
} SCatalogMgmt; } SCatalogMgmt;
...@@ -499,6 +504,11 @@ typedef struct SCtgOperation { ...@@ -499,6 +504,11 @@ typedef struct SCtgOperation {
ctgOpFunc func; ctgOpFunc func;
} SCtgOperation; } SCtgOperation;
typedef struct SCtgCacheItemInfo {
char *name;
int32_t flag;
} SCtgCacheItemInfo;
#define CTG_AUTH_READ(_t) ((_t) == AUTH_TYPE_READ || (_t) == AUTH_TYPE_READ_OR_WRITE) #define CTG_AUTH_READ(_t) ((_t) == AUTH_TYPE_READ || (_t) == AUTH_TYPE_READ_OR_WRITE)
#define CTG_AUTH_WRITE(_t) ((_t) == AUTH_TYPE_WRITE || (_t) == AUTH_TYPE_READ_OR_WRITE) #define CTG_AUTH_WRITE(_t) ((_t) == AUTH_TYPE_WRITE || (_t) == AUTH_TYPE_READ_OR_WRITE)
...@@ -509,43 +519,41 @@ typedef struct SCtgOperation { ...@@ -509,43 +519,41 @@ typedef struct SCtgOperation {
#define CTG_STAT_DEC(_item, _n) atomic_sub_fetch_64(&(_item), _n) #define CTG_STAT_DEC(_item, _n) atomic_sub_fetch_64(&(_item), _n)
#define CTG_STAT_GET(_item) atomic_load_64(&(_item)) #define CTG_STAT_GET(_item) atomic_load_64(&(_item))
#define CTG_DB_NUM_INC(_item) dbCache->dbCacheNum[_itme] += 1 #define CTG_DB_NUM_INC(_item) dbCache->dbCacheNum[_item] += 1
#define CTG_DB_NUM_DEC(_item) dbCache->dbCacheNum[_itme] -= 1 #define CTG_DB_NUM_DEC(_item) dbCache->dbCacheNum[_item] -= 1
#define CTG_DB_NUM_SET(_item) dbCache->dbCacheNum[_itme] = 1 #define CTG_DB_NUM_SET(_item) dbCache->dbCacheNum[_item] = 1
#define CTG_DB_NUM_RESET(_item) dbCache->dbCacheNum[_itme] = 0 #define CTG_DB_NUM_RESET(_item) dbCache->dbCacheNum[_item] = 0
#define CTG_STAT_API_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.api.item, n)) #define CTG_STAT_API_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.api.item, n))
#define CTG_STAT_RT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.runtime.item, n)) #define CTG_STAT_RT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.runtime.item, n))
#define CTG_STAT_NUM_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.cache.cacheNum[item], n)) #define CTG_STAT_NUM_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
#define CTG_STAT_NUM_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.stat.cache.cacheNum[item], n)) #define CTG_STAT_NUM_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
#define CTG_STAT_HIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.cache.cacheHit[item], n)) #define CTG_STAT_HIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
#define CTG_STAT_HIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.stat.cache.cacheHit[item], n)) #define CTG_STAT_HIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
#define CTG_STAT_NHIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.stat.cache.cacheNHit[item], n)) #define CTG_STAT_NHIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheNHit[item], n))
#define CTG_STAT_NHIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.stat.cache.cacheNHit[item], n)) #define CTG_STAT_NHIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheNHit[item], n))
#define CTG_CACHE_NUM_INC(item, n) (CTG_STAT_INC(pCtg->stat.cache.cacheNum[item], n)) #define CTG_CACHE_NUM_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNum[item], n))
#define CTG_CACHE_NUM_DEC(item, n) (CTG_STAT_DEC(pCtg->stat.cache.cacheNum[item], n)) #define CTG_CACHE_NUM_DEC(item, n) (CTG_STAT_DEC(pCtg->cacheStat.cacheNum[item], n))
#define CTG_CACHE_HIT_INC(item, n) (CTG_STAT_INC(pCtg->stat.cache.cacheHit[item], n)) #define CTG_CACHE_HIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheHit[item], n))
#define CTG_CACHE_HIT_DEC(item, n) (CTG_STAT_DEC(pCtg->stat.cache.cacheHit[item], n)) #define CTG_CACHE_NHIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNHit[item], n))
#define CTG_CACHE_NHIT_INC(item, n) (CTG_STAT_INC(pCtg->stat.cache.cacheNHit[item], n))
#define CTG_CACHE_NHIT_DEC(item, n) (CTG_STAT_DEC(pCtg->stat.cache.cacheNHit[item], n))
#define CTG_META_NUM_INC(type) do { \ #define CTG_META_NUM_INC(type) do { \
switch (type) { \ switch (type) { \
case TSDB_SUPER_TABLE: \ case TSDB_SUPER_TABLE: \
CTG_DB_NUM_INC(CTG_CI_STABLE_META, 1); \ CTG_DB_NUM_INC(CTG_CI_STABLE_META); \
break; \ break; \
case TSDB_CHILD_TABLE: \ case TSDB_CHILD_TABLE: \
CTG_DB_NUM_INC(CTG_CI_CTABLE_META, 1); \ CTG_DB_NUM_INC(CTG_CI_CTABLE_META); \
break; \ break; \
case TSDB_NORMAL_TABLE: \ case TSDB_NORMAL_TABLE: \
CTG_DB_NUM_INC(CTG_CI_NTABLE_META, 1); \ CTG_DB_NUM_INC(CTG_CI_NTABLE_META); \
break; \ break; \
case TSDB_SYSTEM_TABLE: \ case TSDB_SYSTEM_TABLE: \
CTG_DB_NUM_INC(CTG_CI_SYSTABLE_META, 1); \ CTG_DB_NUM_INC(CTG_CI_SYSTABLE_META); \
break; \ break; \
default: \ default: \
CTG_DB_NUM_INC(CTG_CI_OTHERTABLE_META, 1); \ CTG_DB_NUM_INC(CTG_CI_OTHERTABLE_META); \
break; \ break; \
} \ } \
} while (0) } while (0)
...@@ -553,19 +561,19 @@ typedef struct SCtgOperation { ...@@ -553,19 +561,19 @@ typedef struct SCtgOperation {
#define CTG_META_NUM_DEC(type) do { \ #define CTG_META_NUM_DEC(type) do { \
switch (type) { \ switch (type) { \
case TSDB_SUPER_TABLE: \ case TSDB_SUPER_TABLE: \
CTG_DB_NUM_INC(CTG_CI_STABLE_META, 1); \ CTG_DB_NUM_DEC(CTG_CI_STABLE_META); \
break; \ break; \
case TSDB_CHILD_TABLE: \ case TSDB_CHILD_TABLE: \
CTG_DB_NUM_INC(CTG_CI_CTABLE_META, 1); \ CTG_DB_NUM_DEC(CTG_CI_CTABLE_META); \
break; \ break; \
case TSDB_NORMAL_TABLE: \ case TSDB_NORMAL_TABLE: \
CTG_DB_NUM_INC(CTG_CI_NTABLE_META, 1); \ CTG_DB_NUM_DEC(CTG_CI_NTABLE_META); \
break; \ break; \
case TSDB_SYSTEM_TABLE: \ case TSDB_SYSTEM_TABLE: \
CTG_DB_NUM_INC(CTG_CI_SYSTABLE_META, 1); \ CTG_DB_NUM_DEC(CTG_CI_SYSTABLE_META); \
break; \ break; \
default: \ default: \
CTG_DB_NUM_INC(CTG_CI_OTHERTABLE_META, 1); \ CTG_DB_NUM_DEC(CTG_CI_OTHERTABLE_META); \
break; \ break; \
} \ } \
} while (0) } while (0)
...@@ -776,6 +784,7 @@ typedef struct SCtgOperation { ...@@ -776,6 +784,7 @@ typedef struct SCtgOperation {
void ctgdShowTableMeta(SCatalog* pCtg, const char* tbName, STableMeta* p); void ctgdShowTableMeta(SCatalog* pCtg, const char* tbName, STableMeta* p);
void ctgdShowClusterCache(SCatalog* pCtg); void ctgdShowClusterCache(SCatalog* pCtg);
int32_t ctgdShowCacheInfo(void); int32_t ctgdShowCacheInfo(void);
int32_t ctgdShowStatInfo(void);
int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq); int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq);
int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
...@@ -900,10 +909,12 @@ int32_t ctgAcquireVgMetaFromCache(SCatalog *pCtg, const char *dbFName, const cha ...@@ -900,10 +909,12 @@ int32_t ctgAcquireVgMetaFromCache(SCatalog *pCtg, const char *dbFName, const cha
int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta, char* dbFName); int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta, char* dbFName);
void ctgReleaseVgMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache); void ctgReleaseVgMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache);
void ctgReleaseTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache); void ctgReleaseTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache);
void ctgGetGlobalCacheStat(SCtgCacheStat *pStat);
extern SCatalogMgmt gCtgMgmt; extern SCatalogMgmt gCtgMgmt;
extern SCtgDebug gCTGDebug; extern SCtgDebug gCTGDebug;
extern SCtgAsyncFps gCtgAsyncFps[]; extern SCtgAsyncFps gCtgAsyncFps[];
extern SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE];
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -31,6 +31,28 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {{CTG_OP_UPDATE_VGROUP, "update v ...@@ -31,6 +31,28 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {{CTG_OP_UPDATE_VGROUP, "update v
{CTG_OP_DROP_TB_INDEX, "drop tbIndex", ctgOpDropTbIndex}, {CTG_OP_DROP_TB_INDEX, "drop tbIndex", ctgOpDropTbIndex},
{CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}}; {CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}};
SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
{"Cluster ", CTG_CI_FLAG_LEVEL_GLOBAL}, //CTG_CI_CLUSTER
{"Dnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_DNODE,
{"Qnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_QNODE,
{"DB ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_DB,
{"DbVgroup ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_VGROUP,
{"DbCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_CFG,
{"DbInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_INFO,
{"StbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_STABLE_META,
{"NtbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_NTABLE_META,
{"CtbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_CTABLE_META,
{"SysTblMeta", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_SYSTABLE_META,
{"OthTblMeta", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_OTHERTABLE_META,
{"TblSMA ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_SMA,
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_CFG,
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_INDEX_INFO,
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_USER,
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_UDF,
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} //CTG_CI_SVR_VER,
};
int32_t ctgRLockVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) { int32_t ctgRLockVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock); CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock);
...@@ -787,7 +809,7 @@ int32_t ctgEnqueue(SCatalog *pCtg, SCtgCacheOperation *operation) { ...@@ -787,7 +809,7 @@ int32_t ctgEnqueue(SCatalog *pCtg, SCtgCacheOperation *operation) {
ctgDebug("action [%s] added into queue", opName); ctgDebug("action [%s] added into queue", opName);
CTG_QUEUE_INC(); CTG_QUEUE_INC();
CTG_RT_STAT_INC(numOfOpEnqueue, 1); CTG_STAT_RT_INC(numOfOpEnqueue, 1);
tsem_post(&gCtgMgmt.queue.reqSem); tsem_post(&gCtgMgmt.queue.reqSem);
...@@ -1545,7 +1567,6 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam ...@@ -1545,7 +1567,6 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
if (taosHashRemove(dbCache->stbCache, &orig->suid, sizeof(orig->suid))) { if (taosHashRemove(dbCache->stbCache, &orig->suid, sizeof(orig->suid))) {
ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:0x%" PRIx64, dbFName, tbName, orig->suid); ctgError("stb not exist in stbCache, dbFName:%s, stb:%s, suid:0x%" PRIx64, dbFName, tbName, orig->suid);
} else { } else {
CTG_META_NUM_DEC(origType);
ctgDebug("stb removed from stbCache, dbFName:%s, stb:%s, suid:0x%" PRIx64, dbFName, tbName, orig->suid); ctgDebug("stb removed from stbCache, dbFName:%s, stb:%s, suid:0x%" PRIx64, dbFName, tbName, orig->suid);
} }
} }
...@@ -1563,14 +1584,15 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam ...@@ -1563,14 +1584,15 @@ int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNam
pCache = taosHashGet(dbCache->tbCache, tbName, strlen(tbName)); pCache = taosHashGet(dbCache->tbCache, tbName, strlen(tbName));
} else { } else {
CTG_LOCK(CTG_WRITE, &pCache->metaLock); CTG_LOCK(CTG_WRITE, &pCache->metaLock);
if (orig) {
CTG_META_NUM_DEC(origType);
}
taosMemoryFree(pCache->pMeta); taosMemoryFree(pCache->pMeta);
pCache->pMeta = meta; pCache->pMeta = meta;
CTG_UNLOCK(CTG_WRITE, &pCache->metaLock); CTG_UNLOCK(CTG_WRITE, &pCache->metaLock);
} }
if (NULL == orig) { CTG_META_NUM_INC(pCache->pMeta->tableType);
CTG_META_NUM_INC(pCache->pMeta->tableType);
}
ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType); ctgDebug("tbmeta updated to cache, dbFName:%s, tbName:%s, tbType:%d", dbFName, tbName, meta->tableType);
ctgdShowTableMeta(pCtg, tbName, meta); ctgdShowTableMeta(pCtg, tbName, meta);
...@@ -2300,10 +2322,10 @@ void ctgCleanupCacheQueue(void) { ...@@ -2300,10 +2322,10 @@ void ctgCleanupCacheQueue(void) {
ctgDebug("process [%s] operation", gCtgCacheOperation[op->opId].name); ctgDebug("process [%s] operation", gCtgCacheOperation[op->opId].name);
(*gCtgCacheOperation[op->opId].func)(op); (*gCtgCacheOperation[op->opId].func)(op);
stopQueue = true; stopQueue = true;
CTG_RT_STAT_INC(numOfOpDequeue, 1); CTG_STAT_RT_INC(numOfOpDequeue, 1);
} else { } else {
ctgFreeCacheOperationData(op); ctgFreeCacheOperationData(op);
CTG_RT_STAT_INC(numOfOpAbort, 1); CTG_STAT_RT_INC(numOfOpAbort, 1);
} }
if (op->syncOp) { if (op->syncOp) {
...@@ -2359,9 +2381,10 @@ void *ctgUpdateThreadFunc(void *param) { ...@@ -2359,9 +2381,10 @@ void *ctgUpdateThreadFunc(void *param) {
taosMemoryFreeClear(operation); taosMemoryFreeClear(operation);
} }
CTG_RT_STAT_INC(numOfOpDequeue, 1); CTG_STAT_RT_INC(numOfOpDequeue, 1);
ctgdShowCacheInfo(); ctgdShowCacheInfo();
ctgdShowStatInfo();
} }
qInfo("catalog update thread stopped"); qInfo("catalog update thread stopped");
...@@ -2502,7 +2525,8 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2502,7 +2525,8 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgDebug("tb %s not in cache, dbFName:%s", pName->tname, dbFName); ctgDebug("tb %s not in cache, dbFName:%s", pName->tname, dbFName);
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
CTG_META_NHIT_INC();
continue; continue;
} }
...@@ -2512,12 +2536,15 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2512,12 +2536,15 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgDebug("tb %s meta not in cache, dbFName:%s", pName->tname, dbFName); ctgDebug("tb %s meta not in cache, dbFName:%s", pName->tname, dbFName);
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
CTG_META_NHIT_INC();
continue; continue;
} }
STableMeta *tbMeta = pCache->pMeta; STableMeta *tbMeta = pCache->pMeta;
CTG_META_HIT_INC(tbMeta->tableType);
SCtgTbMetaCtx nctx = {0}; SCtgTbMetaCtx nctx = {0};
nctx.flag = flag; nctx.flag = flag;
nctx.tbInfo.inCache = true; nctx.tbInfo.inCache = true;
...@@ -2585,8 +2612,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2585,8 +2612,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgDebug("stb 0x%" PRIx64 " not in cache, dbFName:%s", pTableMeta->suid, dbFName); ctgDebug("stb 0x%" PRIx64 " not in cache, dbFName:%s", pTableMeta->suid, dbFName);
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
taosMemoryFreeClear(pTableMeta); taosMemoryFreeClear(pTableMeta);
CTG_META_NHIT_INC();
continue; continue;
} }
...@@ -2597,8 +2625,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2597,8 +2625,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
taosMemoryFreeClear(pTableMeta); taosMemoryFreeClear(pTableMeta);
CTG_META_NHIT_INC();
continue; continue;
} }
...@@ -2612,9 +2641,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2612,9 +2641,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
taosMemoryFreeClear(pTableMeta); taosMemoryFreeClear(pTableMeta);
CTG_META_NHIT_INC();
continue; continue;
} }
...@@ -2628,9 +2657,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2628,9 +2657,9 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag); ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
taosArrayPush(ctx->pResList, &(SMetaRes){0}); taosArrayPush(ctx->pResList, &(SMetaRes){0});
taosMemoryFreeClear(pTableMeta); taosMemoryFreeClear(pTableMeta);
CTG_META_NHIT_INC();
continue; continue;
} }
...@@ -2646,6 +2675,8 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe ...@@ -2646,6 +2675,8 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
CTG_UNLOCK(CTG_READ, &pCache->metaLock); CTG_UNLOCK(CTG_READ, &pCache->metaLock);
taosHashRelease(dbCache->tbCache, pCache); taosHashRelease(dbCache->tbCache, pCache);
CTG_META_HIT_INC(pTableMeta->tableType);
res.pRes = pTableMeta; res.pRes = pTableMeta;
taosArrayPush(ctx->pResList, &res); taosArrayPush(ctx->pResList, &res);
......
...@@ -345,7 +345,7 @@ int32_t ctgdGetOneHandle(SCatalog **pHandle) { ...@@ -345,7 +345,7 @@ int32_t ctgdGetOneHandle(SCatalog **pHandle) {
int32_t ctgdGetStatNum(char *option, void *res) { int32_t ctgdGetStatNum(char *option, void *res) {
if (0 == strcasecmp(option, "runtime.numOfOpDequeue")) { if (0 == strcasecmp(option, "runtime.numOfOpDequeue")) {
*(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.numOfOpDequeue); *(uint64_t *)res = atomic_load_64(&gCtgMgmt.statInfo.runtime.numOfOpDequeue);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -517,6 +517,27 @@ void ctgdShowClusterCache(SCatalog *pCtg) { ...@@ -517,6 +517,27 @@ void ctgdShowClusterCache(SCatalog *pCtg) {
ctgDebug("## cluster 0x%" PRIx64 " %p cache Info END ##", pCtg->clusterId, pCtg); ctgDebug("## cluster 0x%" PRIx64 " %p cache Info END ##", pCtg->clusterId, pCtg);
} }
int32_t ctgdShowStatInfo(void) {
if (!gCTGDebug.statEnable) {
return TSDB_CODE_CTG_OUT_OF_SERVICE;
}
CTG_API_ENTER();
SCtgCacheStat cache;
ctgGetGlobalCacheStat(&cache);
qDebug("## Global Stat Info %s ##", "begin");
qDebug("## \t%s \t%s \t%s ##", "Num", "Hit", "Nhit");
for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
qDebug("# %s \t%" PRIu64 " \t%" PRIu64 " \t%" PRIu64 " #", gCtgStatItem[i].name, cache.cacheNum[i], cache.cacheHit[i], cache.cacheNHit[i]);
}
qDebug("## Global Stat Info %s ##", "end");
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
}
int32_t ctgdShowCacheInfo(void) { int32_t ctgdShowCacheInfo(void) {
if (!gCTGDebug.cacheEnable) { if (!gCTGDebug.cacheEnable) {
return TSDB_CODE_CTG_OUT_OF_SERVICE; return TSDB_CODE_CTG_OUT_OF_SERVICE;
......
...@@ -258,8 +258,6 @@ void ctgFreeInstDbCache(SHashObj* pDbCache) { ...@@ -258,8 +258,6 @@ void ctgFreeInstDbCache(SHashObj* pDbCache) {
} }
taosHashCleanup(pDbCache); taosHashCleanup(pDbCache);
CTG_CACHE_NUM_DEC(CTG_CI_DB, dbNum);
} }
void ctgFreeInstUserCache(SHashObj* pUserCache) { void ctgFreeInstUserCache(SHashObj* pUserCache) {
...@@ -1419,3 +1417,69 @@ void catalogFreeMetaData(SMetaData* pData) { ...@@ -1419,3 +1417,69 @@ void catalogFreeMetaData(SMetaData* pData) {
taosMemoryFreeClear(pData->pSvrVer); taosMemoryFreeClear(pData->pSvrVer);
taosMemoryFree(pData); taosMemoryFree(pData);
} }
void ctgGetClusterCacheStat(SCatalog* pCtg) {
for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
if (0 == (gCtgStatItem[i].flag & CTG_CI_FLAG_LEVEL_DB)) {
continue;
}
pCtg->cacheStat.cacheNum[i] = 0;
}
SCtgDBCache *dbCache = NULL;
void *pIter = taosHashIterate(pCtg->dbCache, NULL);
while (pIter) {
dbCache = (SCtgDBCache *)pIter;
for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
if (0 == (gCtgStatItem[i].flag & CTG_CI_FLAG_LEVEL_DB)) {
continue;
}
pCtg->cacheStat.cacheNum[i] += dbCache->dbCacheNum[i];
}
pIter = taosHashIterate(pCtg->dbCache, pIter);
}
}
void ctgSummaryClusterCacheStat(SCatalog *pCtg) {
for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
if (gCtgStatItem[i].flag & CTG_CI_FLAG_LEVEL_GLOBAL) {
continue;
}
gCtgMgmt.statInfo.cache.cacheNum[i] += pCtg->cacheStat.cacheNum[i];
gCtgMgmt.statInfo.cache.cacheHit[i] += pCtg->cacheStat.cacheHit[i];
gCtgMgmt.statInfo.cache.cacheNHit[i] += pCtg->cacheStat.cacheNHit[i];
}
}
void ctgGetGlobalCacheStat(SCtgCacheStat *pStat) {
for (int32_t i = 0; i < CTG_CI_MAX_VALUE; ++i) {
if (gCtgStatItem[i].flag & CTG_CI_FLAG_LEVEL_GLOBAL) {
continue;
}
gCtgMgmt.statInfo.cache.cacheNum[i] = 0;
gCtgMgmt.statInfo.cache.cacheHit[i] = 0;
gCtgMgmt.statInfo.cache.cacheNHit[i] = 0;
}
SCatalog *pCtg = NULL;
void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL);
while (pIter) {
pCtg = *(SCatalog **)pIter;
if (pCtg) {
ctgGetClusterCacheStat(pCtg);
ctgSummaryClusterCacheStat(pCtg);
}
pIter = taosHashIterate(gCtgMgmt.pCluster, pIter);
}
memcpy(pStat, &gCtgMgmt.statInfo.cache, sizeof(gCtgMgmt.statInfo.cache));
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册