From 383a0b5dd5203e5f1e74f397e6327280fc98b013 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 26 Dec 2024 09:52:36 +0800 Subject: [PATCH 1/2] fix: catalog ut and timer stop issue --- source/libs/catalog/src/catalog.c | 11 +++++++++-- source/libs/catalog/test/catalogTests.cpp | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index bc1462176a..a0a4cb301c 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1986,10 +1986,17 @@ void catalogDestroy(void) { } if (gCtgMgmt.cacheTimer) { - if (taosTmrStop(gCtgMgmt.cacheTimer)) { - qTrace("stop catalog cache timer may failed"); + if (!taosTmrStop(gCtgMgmt.cacheTimer)) { + qDebug("catalog cacheTimer %" PRIuPTR " not stopped", (uintptr_t)gCtgMgmt.cacheTimer); + + while (!taosTmrIsStopped(&gCtgMgmt.cacheTimer)) { + taosMsleep(1); + } } + + qDebug("catalog cacheTimer %" PRIuPTR " is stopped", (uintptr_t)gCtgMgmt.cacheTimer); gCtgMgmt.cacheTimer = NULL; + taosTmrCleanUp(gCtgMgmt.timer); gCtgMgmt.timer = NULL; } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index c2889f096b..06eabc09da 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -149,12 +149,13 @@ void ctgTestInitLogFile() { return; } - const char *defaultLogFileNamePrefix = "taoslog"; + const char *defaultLogFileNamePrefix = "catalogTest"; const int32_t maxLogFileNum = 10; tsAsyncLog = 0; qDebugFlag = 159; tmrDebugFlag = 159; + tsNumOfLogLines = 1000000000; TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH); (void)ctgdEnableDebug("api", true); @@ -1839,7 +1840,7 @@ TEST(tableMeta, updateStbMeta) { while (true) { uint64_t n = 0; ASSERT(0 == ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n)); - if (n != 3) { + if (n < 3) { taosMsleep(50); } else { break; From 59b10f414ce58bf70d01a80f4beeaf9d3a565e28 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 26 Dec 2024 10:10:21 +0800 Subject: [PATCH 2/2] fix: catalog dbg issue --- source/libs/catalog/src/catalog.c | 2 ++ source/libs/catalog/src/ctgDbg.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index a0a4cb301c..2e16b0968a 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1987,11 +1987,13 @@ void catalogDestroy(void) { if (gCtgMgmt.cacheTimer) { if (!taosTmrStop(gCtgMgmt.cacheTimer)) { +/* qDebug("catalog cacheTimer %" PRIuPTR " not stopped", (uintptr_t)gCtgMgmt.cacheTimer); while (!taosTmrIsStopped(&gCtgMgmt.cacheTimer)) { taosMsleep(1); } +*/ } qDebug("catalog cacheTimer %" PRIuPTR " is stopped", (uintptr_t)gCtgMgmt.cacheTimer); diff --git a/source/libs/catalog/src/ctgDbg.c b/source/libs/catalog/src/ctgDbg.c index f3a0b04457..a1512f8fd9 100644 --- a/source/libs/catalog/src/ctgDbg.c +++ b/source/libs/catalog/src/ctgDbg.c @@ -480,6 +480,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) { dbCache = (SCtgDBCache *)pIter; + CTG_LOCK(CTG_READ, &dbCache->dbLock); + dbFName = taosHashGetKey(pIter, &len); int32_t metaNum = dbCache->tbCache ? taosHashGetSize(dbCache->tbCache) : 0; @@ -509,6 +511,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) { hashMethod, hashPrefix, hashSuffix, vgNum); if (dbCache->vgCache.vgInfo) { + CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock); + int32_t i = 0; void *pVgIter = taosHashIterate(dbCache->vgCache.vgInfo->vgHash, NULL); while (pVgIter) { @@ -524,6 +528,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) { pVgIter = taosHashIterate(dbCache->vgCache.vgInfo->vgHash, pVgIter); } + + CTG_UNLOCK(CTG_READ, &dbCache->vgCache.vgLock); } if (dbCache->cfgCache.cfgInfo) { @@ -544,6 +550,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) { pCfg->schemaless, pCfg->sstTrigger); } + CTG_UNLOCK(CTG_READ, &dbCache->dbLock); + ++i; pIter = taosHashIterate(dbHash, pIter); }