diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 7723b6221b1ad769ae5b1a4b4571a5506ba23e12..af63b10bc55cac9db50f034f98fb8e54428e7550 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -40,8 +40,9 @@ #include "dnodeShell.h" #include "dnodeTelemetry.h" #include "module.h" -#include "qScript.h" #include "mnode.h" +#include "qScript.h" +#include "tcache.h" #if !defined(_MODULE) || !defined(_TD_LINUX) int32_t moduleStart() { return 0; } @@ -207,6 +208,7 @@ void dnodeCleanUpSystem() { dnodeCleanupComponents(); taos_cleanup(); taosCloseLog(); + taosStopCacheRefreshWorker(); } } diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index d381b8b1990f30e2f2067ff68be3039d20406c63..e41b544d00e55f7eece904c5957ef9c06063e6c3 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -178,6 +178,11 @@ void taosCacheCleanup(SCacheObj *pCacheObj); */ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp); +/** + * stop background refresh worker thread + */ +void taosStopCacheRefreshWorker(); + #ifdef __cplusplus } #endif diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index fba62fc0675aa89201806017f6ec78210576ba3f..4aa5b4378f79eaac7c31465cb90880c282670bcc 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -70,6 +70,7 @@ static pthread_t cacheRefreshWorker = {0}; static pthread_once_t cacheThreadInit = PTHREAD_ONCE_INIT; static pthread_mutex_t guard = PTHREAD_MUTEX_INITIALIZER; static SArray* pCacheArrayList = NULL; +static bool stopRefreshWorker = false; static void doInitRefreshThread(void) { pCacheArrayList = taosArrayInit(4, POINTER_BYTES); @@ -685,6 +686,9 @@ void* taosCacheTimedRefresh(void *handle) { while(1) { taosMsleep(SLEEP_DURATION); + if (stopRefreshWorker) { + goto _end; + } pthread_mutex_lock(&guard); size_t size = taosArrayGetSize(pCacheArrayList); @@ -708,13 +712,10 @@ void* taosCacheTimedRefresh(void *handle) { size = taosArrayGetSize(pCacheArrayList); uDebug("%s is destroying, remove it from refresh list, remain cache obj:%"PRIzu, pCacheObj->name, size); - pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj does self destroy process + pCacheObj->deleting = 0; //reset the deleting flag to enable pCacheObj to continue releasing resources. - // all contained caches has been marked to be removed, destroy the scanner it self. - if (size == 0) { - pthread_mutex_unlock(&guard); - goto _end; - } + pthread_mutex_unlock(&guard); + continue; } pthread_mutex_unlock(&guard); @@ -759,3 +760,7 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) { int64_t now = taosGetTimestampMs(); doCacheRefresh(pCacheObj, now, fp); } + +void taosStopCacheRefreshWorker() { + stopRefreshWorker = false; +} \ No newline at end of file