From 5cc26ce991868d7ad726ee35cd935d3cd56401c2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 23 Jul 2021 11:27:46 +0800 Subject: [PATCH] [td-225]fix bug found by regression test. --- src/dnode/src/dnodeMain.c | 4 +++- src/util/inc/tcache.h | 5 +++++ src/util/src/tcache.c | 17 +++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 7723b6221b..af63b10bc5 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 d381b8b199..e41b544d00 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 fba62fc067..4aa5b4378f 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 -- GitLab