提交 175d4c55 编写于 作者: H Haojun Liao

[td-225]add handle expired check

上级 0e1a4576
......@@ -6986,6 +6986,7 @@ void* qOpenQueryMgmt(int32_t vgId) {
pthread_mutex_init(&pQueryMgmt->lock, NULL);
taosCacheCheckforExpire(pQueryMgmt->qinfoPool, 600);
qDebug("vgId:%d, open querymgmt success", vgId);
return pQueryMgmt;
}
......
......@@ -75,6 +75,7 @@ typedef struct {
uint8_t deleting; // set the deleting flag to stop refreshing ASAP.
pthread_t refreshWorker;
bool extendLifespan; // auto extend life span when one item is accessed.
int32_t itemExpireTime; // maximum live time in ms in cache for object, if -1, mean never expired.
#if defined(LINUX)
pthread_rwlock_t lock;
#else
......@@ -169,6 +170,9 @@ void taosCacheCleanup(SCacheObj *pCacheObj);
*/
void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp);
// check the query handle not released, debug purpose only
void taosCacheCheckforExpire(SCacheObj *pCacheObj, int32_t expireTimeSec);
#ifdef __cplusplus
}
#endif
......
......@@ -170,6 +170,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
pCacheObj->freeFp = fn;
pCacheObj->refreshTime = refreshTimeInSeconds * 1000;
pCacheObj->extendLifespan = extendLifespan;
pCacheObj->itemExpireTime = -1;
if (__cache_lock_init(pCacheObj) != 0) {
taosHashCleanup(pCacheObj->pHashTable);
......@@ -521,6 +522,8 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
}
void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) {
int64_t now = taosGetTimestampMs();
__cache_wr_lock(pCacheObj);
if (pCacheObj->numOfElemsInTrash == 0) {
......@@ -551,6 +554,12 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) {
doRemoveElemInTrashcan(pCacheObj, p);
doDestroyTrashcanElem(pCacheObj, p);
} else {
// any item should not live longer than the specificed expired time
assert(now >= pElem->pData->addedTime);
if (pCacheObj->itemExpireTime > 0 && ((now - pElem->pData->addedTime) > pCacheObj->itemExpireTime)) {
assert(0);
}
pElem = pElem->next;
}
}
......@@ -653,3 +662,15 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_free_fn_t fp) {
int64_t now = taosGetTimestampMs();
doCacheRefresh(pCacheObj, now, fp);
}
void taosCacheCheckforExpire(SCacheObj *pCacheObj, int32_t expireTimeSec) {
if (pCacheObj == NULL || expireTimeSec < 0) {
return;
}
if (expireTimeSec < pCacheObj->refreshTime) {
expireTimeSec = pCacheObj->refreshTime * 20;
}
pCacheObj->itemExpireTime = expireTimeSec*1000;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册