提交 4a508cdf 编写于 作者: H Haojun Liao

[td-225] refactor codes.

上级 c2ce0fc4
...@@ -207,7 +207,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext ...@@ -207,7 +207,7 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
return NULL; return NULL;
} }
pCacheObj->pHashTable = taosHashInit(128, taosGetDefaultHashFunction(keyType), true); pCacheObj->pHashTable = taosHashInit(128, taosGetDefaultHashFunction(keyType), false);
pCacheObj->name = strdup(cacheName); pCacheObj->name = strdup(cacheName);
if (pCacheObj->pHashTable == NULL) { if (pCacheObj->pHashTable == NULL) {
free(pCacheObj); free(pCacheObj);
...@@ -239,8 +239,6 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext ...@@ -239,8 +239,6 @@ SCacheObj *taosCacheInit(int32_t keyType, int64_t refreshTimeInSeconds, bool ext
} }
void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int duration) { void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const void *pData, size_t dataSize, int duration) {
// SCacheDataNode *pNode = NULL;
if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) { if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) {
return NULL; return NULL;
} }
...@@ -266,12 +264,11 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v ...@@ -266,12 +264,11 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
pCacheObj->name, key, pNode1->data, pNode1->addedTime, pNode1->expireTime, pCacheObj->name, key, pNode1->data, pNode1->addedTime, pNode1->expireTime,
(int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, (int64_t)dataSize); (int32_t)taosHashGetSize(pCacheObj->pHashTable), pCacheObj->totalSize, (int64_t)dataSize);
} else { // old data exists, update the node } else { // old data exists, update the node
bool addToTrashcan = false; bool addToTrashcan = false;
if (T_REF_VAL_GET(pOld) > 0) { if (T_REF_VAL_GET(pOld) > 0) {
// todo removed by node, instead of by key // todo removed by node, instead of by key
taosHashRemove(pCacheObj->pHashTable, pOld->key, pOld->keySize); taosHashRemove(pCacheObj->pHashTable, pOld->key, pOld->keySize);
} else {
addToTrashcan = true; addToTrashcan = true;
} }
...@@ -285,7 +282,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v ...@@ -285,7 +282,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const void *key, size_t keyLen, const v
if (addToTrashcan) { if (addToTrashcan) {
taosAddToTrash(pCacheObj, pOld); taosAddToTrash(pCacheObj, pOld);
} else { } else {
tfree(pOld); free(pOld);
} }
uDebug("cache:%s, key:%p, %p exist in cache, updated old:%p", pCacheObj->name, key, pNode1->data, pOld); uDebug("cache:%s, key:%p, %p exist in cache, updated old:%p", pCacheObj->name, key, pNode1->data, pOld);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册