未验证 提交 12187a38 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #9101 from haoyifan/tcache_cleanup_branch

Tcache cleanup branch
......@@ -85,7 +85,7 @@ static void doInitRefreshThread(void) {
pthread_attr_destroy(&thattr);
}
pthread_t doRegisterCacheObj(SCacheObj* pCacheObj) {
static pthread_t doRegisterCacheObj(SCacheObj* pCacheObj) {
pthread_once(&cacheThreadInit, doInitRefreshThread);
pthread_mutex_lock(&guard);
......@@ -184,7 +184,7 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj* pCacheObj, STrashElem
}
SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool extendLifespan, __cache_free_fn_t fn, const char* cacheName) {
const int32_t SLEEP_DURATION = 500; //500 ms
const int32_t SLEEP_DURATION_IN_MS = 500;
if (refreshTimeInSeconds <= 0) {
return NULL;
......@@ -197,21 +197,29 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
}
pCacheObj->pHashTable = taosHashInit(4096, taosGetDefaultHashFunction(keyType), false, HASH_ENTRY_LOCK);
pCacheObj->name = strdup(cacheName);
if (pCacheObj->pHashTable == NULL) {
free(pCacheObj);
uError("failed to allocate memory, reason:%s", strerror(errno));
return NULL;
}
pCacheObj->name = strdup(cacheName);
if (pCacheObj->name == NULL) {
taosHashCleanup(pCacheObj->pHashTable);
free(pCacheObj);
uError("failed to allocate memory, reason:%s", strerror(errno));
return NULL;
}
// set free cache node callback function
pCacheObj->freeFp = fn;
pCacheObj->refreshTime = refreshTimeInSeconds * 1000;
pCacheObj->checkTick = pCacheObj->refreshTime / SLEEP_DURATION;
pCacheObj->checkTick = pCacheObj->refreshTime / SLEEP_DURATION_IN_MS;
pCacheObj->extendLifespan = extendLifespan; // the TTL after the last access
if (__cache_lock_init(pCacheObj) != 0) {
taosHashCleanup(pCacheObj->pHashTable);
free(pCacheObj->name);
free(pCacheObj);
uError("failed to init lock, reason:%s", strerror(errno));
......@@ -694,12 +702,12 @@ void* taosCacheTimedRefresh(void *handle) {
setThreadName("cacheRefresh");
const int32_t SLEEP_DURATION = 500; //500 ms
const int32_t SLEEP_DURATION_IN_MS = 500;
int64_t count = 0;
atexit(taosCacheRefreshWorkerUnexpectedStopped);
while(1) {
taosMsleep(SLEEP_DURATION);
taosMsleep(SLEEP_DURATION_IN_MS);
if (stopRefreshWorker) {
goto _end;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册