[TD-825] race condtion while free object in cache
This commit is contained in:
parent
4b8428855f
commit
627cdc0749
|
@ -453,21 +453,20 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
} else {
|
} else {
|
||||||
uDebug("cache:%s, key:%p, %p is released, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, T_REF_VAL_GET(pNode) - 1);
|
uDebug("cache:%s, key:%p, %p is released, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, T_REF_VAL_GET(pNode) - 1);
|
||||||
|
|
||||||
|
__cache_wr_lock(pCacheObj);
|
||||||
|
|
||||||
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
// NOTE: once refcount is decrease, pNode may be freed by other thread immediately.
|
||||||
int32_t ref = T_REF_DEC(pNode);
|
int32_t ref = T_REF_DEC(pNode);
|
||||||
|
|
||||||
if (inTrashCan) {
|
if (inTrashCan && (ref == 0)) {
|
||||||
// Remove it if the ref count is 0.
|
// Remove it if the ref count is 0.
|
||||||
// The ref count does not need to load and check again after lock acquired, since ref count can not be increased when
|
// The ref count does not need to load and check again after lock acquired, since ref count can not be increased when
|
||||||
// the node is in trashcan.
|
// the node is in trashcan.
|
||||||
if (ref == 0) {
|
assert(pNode->pTNodeHeader->pData == pNode);
|
||||||
__cache_wr_lock(pCacheObj);
|
taosRemoveFromTrashCan(pCacheObj, pNode->pTNodeHeader);
|
||||||
assert(pNode->pTNodeHeader->pData == pNode);
|
|
||||||
taosRemoveFromTrashCan(pCacheObj, pNode->pTNodeHeader);
|
|
||||||
__cache_unlock(pCacheObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__cache_unlock(pCacheObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// else {
|
// else {
|
||||||
|
|
Loading…
Reference in New Issue