From 02bdbce35af7a75fef1b63cc3534cb6c61d69245 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 1 Aug 2020 16:15:07 +0800 Subject: [PATCH] [td-225] merge develop --- src/mnode/src/mnodeProfile.c | 2 +- src/util/inc/hash.h | 9 ------ src/util/inc/tcache.h | 2 +- src/util/src/hash.c | 4 +-- src/util/src/tcache.c | 54 ++++++++++++++++++------------------ 5 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 353dd59671..e8f37f1422 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -112,7 +112,7 @@ void mnodeReleaseConn(SConnObj *pConn) { SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t port) { uint64_t expireTime = CONN_KEEP_TIME * 1000 + (uint64_t)taosGetTimestampMs(); - SConnObj *pConn = taosCacheUpdateExpireTimeByName(tsMnodeConnCache, &connId, sizeof(int32_t), expireTime); + SConnObj *pConn = taosCacheAcquireByKey(tsMnodeConnCache, &connId, sizeof(int32_t)); if (pConn == NULL) { mDebug("connId:%d, is already destroyed, user:%s ip:%s:%u", connId, user, taosIpStr(ip), port); return NULL; diff --git a/src/util/inc/hash.h b/src/util/inc/hash.h index 688bf317d6..71493788ac 100644 --- a/src/util/inc/hash.h +++ b/src/util/inc/hash.h @@ -41,18 +41,9 @@ typedef struct SHashNode { typedef enum SHashLockTypeE { HASH_NO_LOCK = 0, -// HASH_GLOBAL_LOCK = 1, HASH_ENTRY_LOCK = 1, } SHashLockTypeE; -//typedef struct SHashLock { -//#if defined(LINUX) -// pthread_rwlock_t *lock; -//#else -// pthread_mutex_t *lock; -//#endif -//} SHashLock; - typedef struct SHashEntry { int32_t num; // number of elements in current entry SRWLatch latch; // entry latch diff --git a/src/util/inc/tcache.h b/src/util/inc/tcache.h index 1e2aeae394..11121fcf3b 100644 --- a/src/util/inc/tcache.h +++ b/src/util/inc/tcache.h @@ -121,7 +121,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen * @param expireTime new expire time of data * @return */ -void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t keyLen, uint64_t expireTime); +//void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t keyLen, uint64_t expireTime); /** * Add one reference count for the exist data, and assign this data for a new owner. diff --git a/src/util/src/hash.c b/src/util/src/hash.c index ed4f445795..83e2630e41 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -447,8 +447,7 @@ void taosHashCleanup(SHashObj *pHashObj) { pHashObj->freeFp(pNode->data); } - free(pNode->data); - free(pNode); + FREE_HASH_NODE(pNode); pNode = pNext; } } @@ -651,6 +650,7 @@ void taosHashTableResize(SHashObj *pHashObj) { SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, size_t dsize, uint32_t hashVal) { SHashNode *pNewNode = calloc(1, sizeof(SHashNode)); + if (pNewNode == NULL) { uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index c360d09a4a..e7f4b29744 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -340,33 +340,33 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen return pData; } -void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t keyLen, uint64_t expireTime) { - if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) { - return NULL; - } - - __cache_rd_lock(pCacheObj); - - SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen); - if (ptNode != NULL) { - T_REF_INC(*ptNode); - (*ptNode)->expireTime = expireTime; // taosGetTimestampMs() + (*ptNode)->lifespan; - } - - __cache_unlock(pCacheObj); - - if (ptNode != NULL) { - atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1); - uDebug("cache:%s, key:%p, %p expireTime is updated in cache, refcnt:%d", pCacheObj->name, key, - (*ptNode)->data, T_REF_VAL_GET(*ptNode)); - } else { - atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); - uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); - } - - atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1); - return (ptNode != NULL) ? (*ptNode)->data : NULL; -} +//void* taosCacheUpdateExpireTimeByName(SCacheObj *pCacheObj, void *key, size_t keyLen, uint64_t expireTime) { +// if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) { +// return NULL; +// } +// +// __cache_rd_lock(pCacheObj); +// +// SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen); +// if (ptNode != NULL) { +// T_REF_INC(*ptNode); +// (*ptNode)->expireTime = expireTime; // taosGetTimestampMs() + (*ptNode)->lifespan; +// } +// +// __cache_unlock(pCacheObj); +// +// if (ptNode != NULL) { +// atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1); +// uDebug("cache:%s, key:%p, %p expireTime is updated in cache, refcnt:%d", pCacheObj->name, key, +// (*ptNode)->data, T_REF_VAL_GET(*ptNode)); +// } else { +// atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); +// uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key); +// } +// +// atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1); +// return (ptNode != NULL) ? (*ptNode)->data : NULL; +//} void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) { if (pCacheObj == NULL || data == NULL) return NULL; -- GitLab