提交 0ef20b37 编写于 作者: H Haojun Liao

[td-225]

上级 8137a287
...@@ -378,40 +378,43 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { ...@@ -378,40 +378,43 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
} else { } else {
// NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread // NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread
// when reaches here. // when reaches here.
SCacheDataNode* p = NULL; SCacheDataNode *p = NULL;
int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, pNode->key, pNode->keySize, &p, sizeof(void*)); int32_t ret = taosHashRemoveWithData(pCacheObj->pHashTable, pNode->key, pNode->keySize, &p, sizeof(void *));
ref = T_REF_DEC(pNode); ref = T_REF_DEC(pNode);
// successfully remove from hash table, if failed, this node must have been move to trash already, do nothing. // successfully remove from hash table, if failed, this node must have been move to trash already, do nothing.
// note that the remove operation can be executed only once. // note that the remove operation can be executed only once.
if (ret == 0) { if (ret == 0) {
if (p != pNode) { if (p != pNode) {
uDebug("cache:%s, key:%p, successfully removed a new entry:%p, refcnt:%d, prev entry:%p has been removed by others already", pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data); uDebug( "cache:%s, key:%p, successfully removed a new entry:%p, refcnt:%d, prev entry:%p has been removed by "
assert(p->pTNodeHeader == NULL); "others already", pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data);
taosAddToTrash(pCacheObj, p);
} else { assert(p->pTNodeHeader == NULL);
taosAddToTrash(pCacheObj, p);
} else {
uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key,
pNode->data, ref);
if (ref > 0) {
assert(pNode->pTNodeHeader == NULL);
uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, ref); taosAddToTrash(pCacheObj, pNode);
if (ref > 0) { } else { // ref == 0
assert(pNode->pTNodeHeader == NULL); atomic_sub_fetch_64(&pCacheObj->totalSize, pNode->size);
taosAddToTrash(pCacheObj, pNode); int32_t size = (int32_t)taosHashGetSize(pCacheObj->pHashTable);
} else { // ref == 0 uDebug("cache:%s, key:%p, %p is destroyed from cache, size:%dbytes, num:%d size:%" PRId64 "bytes",
atomic_sub_fetch_64(&pCacheObj->totalSize, pNode->size); pCacheObj->name, pNode->key, pNode->data, pNode->size, size, pCacheObj->totalSize);
int32_t size = (int32_t)taosHashGetSize(pCacheObj->pHashTable); if (pCacheObj->freeFp) {
uDebug("cache:%s, key:%p, %p is destroyed from cache, size:%dbytes, num:%d size:%" PRId64 "bytes", pCacheObj->freeFp(pNode->data);
pCacheObj->name, pNode->key, pNode->data, pNode->size, size, pCacheObj->totalSize); }
if (pCacheObj->freeFp) { free(pNode);
pCacheObj->freeFp(pNode->data);
} }
free(pNode);
} }
}
} else { } else {
uDebug("cache:%s, key:%p, %p has been removed from hash table by other thread already, refcnt:%d", pCacheObj->name, pNode->key, pNode->data, ref); uDebug("cache:%s, key:%p, %p has been removed from hash table by other thread already, refcnt:%d",
pCacheObj->name, pNode->key, pNode->data, ref);
} }
} }
...@@ -513,7 +516,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) { ...@@ -513,7 +516,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
pCacheObj->numOfElemsInTrash++; pCacheObj->numOfElemsInTrash++;
__cache_unlock(pCacheObj); __cache_unlock(pCacheObj);
uDebug("%s key:%p, %p move to trash, numOfElem in trash:%d", pCacheObj->name, pNode->key, pNode->data, uDebug("cache:%s key:%p, %p move to trash, numOfElem in trash:%d", pCacheObj->name, pNode->key, pNode->data,
pCacheObj->numOfElemsInTrash); pCacheObj->numOfElemsInTrash);
} }
......
...@@ -10,6 +10,6 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) ...@@ -10,6 +10,6 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR)
INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${HEADER_GTEST_INCLUDE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(utilTest ./cacheTest.cpp ./hashTest.cpp) ADD_EXECUTABLE(utilTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES(utilTest tutil common osdetail gtest pthread gcov) TARGET_LINK_LIBRARIES(utilTest tutil common osdetail gtest pthread gcov)
ENDIF() ENDIF()
#include "os.h" #include "os.h"
#include <iostream> #include <iostream>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sys/time.h>
#include "taos.h" #include "taos.h"
//#include "tsdb.h"
//#include "testCommon.h"
#include "tstoken.h"
#include "tutil.h"
#include "tcache.h" #include "tcache.h"
#include "ttimer.h"
namespace { namespace {
int32_t tsMaxMgmtConnections = 10000; int32_t tsMaxMgmtConnections = 10000;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册