[td-225]
This commit is contained in:
parent
6f3f7f7ff9
commit
abd8b930fa
|
@ -21,6 +21,12 @@
|
||||||
|
|
||||||
#define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR)
|
#define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR)
|
||||||
|
|
||||||
|
#define FREE_HASH_NODE(_n) \
|
||||||
|
do { \
|
||||||
|
tfree((_n)->data); \
|
||||||
|
tfree(_n); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static FORCE_INLINE void __wr_lock(void *lock, int32_t type) {
|
static FORCE_INLINE void __wr_lock(void *lock, int32_t type) {
|
||||||
if (type == HASH_NO_LOCK) {
|
if (type == HASH_NO_LOCK) {
|
||||||
return;
|
return;
|
||||||
|
@ -258,9 +264,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
|
||||||
// enable resize
|
// enable resize
|
||||||
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
__rd_unlock(&pHashObj->lock, pHashObj->type);
|
||||||
|
|
||||||
tfree(pNewNode->data)
|
FREE_HASH_NODE(pNewNode);
|
||||||
tfree(pNewNode);
|
|
||||||
|
|
||||||
return pHashObj->enableUpdate? 0:-1;
|
return pHashObj->enableUpdate? 0:-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,7 +277,7 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
||||||
uint32_t hashVal = (*pHashObj->hashFp)(key, keyLen);
|
uint32_t hashVal = (*pHashObj->hashFp)(key, keyLen);
|
||||||
|
|
||||||
// only add the read lock to disable the resize process
|
// only add the read lock to disable the resize process
|
||||||
__rd_lock(&pHashObj->lock, pHashObj->type);
|
__rd_lock(&pHashObj->lock, pHashObj->type);
|
||||||
|
|
||||||
SHashNode *pNode = doGetNodeFromHashTable(pHashObj, key, keyLen, hashVal);
|
SHashNode *pNode = doGetNodeFromHashTable(pHashObj, key, keyLen, hashVal);
|
||||||
|
|
||||||
|
@ -291,6 +295,18 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
||||||
return taosHashRemoveNode(pHashObj, key, keyLen, NULL, 0);
|
return taosHashRemoveNode(pHashObj, key, keyLen, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void popNodeFromEntryList(SHashEntry* pe, SHashNode* pNode) {
|
||||||
|
SHashNode* pNext = pNode->next;
|
||||||
|
|
||||||
|
assert(pNode->prev != NULL);
|
||||||
|
pNode->prev->next = pNext;
|
||||||
|
if (pNext != NULL) {
|
||||||
|
pNext->prev = pNode->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
pe->num -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t taosHashRemoveNode(SHashObj *pHashObj, const void *key, size_t keyLen, void* data, size_t dsize) {
|
int32_t taosHashRemoveNode(SHashObj *pHashObj, const void *key, size_t keyLen, void* data, size_t dsize) {
|
||||||
if (pHashObj->size <= 0) {
|
if (pHashObj->size <= 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -316,16 +332,7 @@ int32_t taosHashRemoveNode(SHashObj *pHashObj, const void *key, size_t keyLen, v
|
||||||
|
|
||||||
SHashNode* pNode = doSearchEntryList(pe, key, keyLen, hashVal);
|
SHashNode* pNode = doSearchEntryList(pe, key, keyLen, hashVal);
|
||||||
if (pNode != NULL) {
|
if (pNode != NULL) {
|
||||||
assert(pNode->prev != NULL);
|
popNodeFromEntryList(pe, pNode);
|
||||||
|
|
||||||
SHashNode *pNext = pNode->next;
|
|
||||||
pNode->prev->next = pNext;
|
|
||||||
|
|
||||||
if (pNext != NULL) {
|
|
||||||
pNext->prev = pNode->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
pe->num -= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
if (pHashObj->type == HASH_ENTRY_LOCK) {
|
||||||
|
@ -344,8 +351,7 @@ int32_t taosHashRemoveNode(SHashObj *pHashObj, const void *key, size_t keyLen, v
|
||||||
pNode->next = NULL;
|
pNode->next = NULL;
|
||||||
pNode->prev = NULL;
|
pNode->prev = NULL;
|
||||||
|
|
||||||
tfree(pNode->data);
|
FREE_HASH_NODE(pNode);
|
||||||
tfree(pNode);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -540,22 +546,16 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
||||||
int32_t j = HASH_INDEX(pNode->hashVal, pHashObj->capacity);
|
int32_t j = HASH_INDEX(pNode->hashVal, pHashObj->capacity);
|
||||||
if (j == i) { // this key locates in the same slot, no need to relocate it
|
if (j == i) { // this key locates in the same slot, no need to relocate it
|
||||||
pNode = pNode->next;
|
pNode = pNode->next;
|
||||||
assert(pNode == NULL || pNode->next != pNode);
|
|
||||||
} else {
|
} else {
|
||||||
pNext = pNode->next;
|
pNext = pNode->next;
|
||||||
assert(pNode != pNext && (pNext == NULL || pNext->prev == pNode) && pNode->prev->next == pNode);
|
assert(pNode != pNext && (pNext == NULL || pNext->prev == pNode) && pNode->prev->next == pNode);
|
||||||
|
|
||||||
assert(pNode->prev != NULL);
|
popNodeFromEntryList(pe, pNode);
|
||||||
pNode->prev->next = pNext;
|
|
||||||
if (pNext != NULL) {
|
|
||||||
pNext->prev = pNode->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear pointer
|
// clear pointer
|
||||||
pNode->next = NULL;
|
pNode->next = NULL;
|
||||||
pNode->prev = NULL;
|
pNode->prev = NULL;
|
||||||
pe->num -= 1;
|
|
||||||
|
|
||||||
// added into new slot
|
// added into new slot
|
||||||
SHashEntry *pNewEntry = pHashObj->hashList[j];
|
SHashEntry *pNewEntry = pHashObj->hashList[j];
|
||||||
pushfrontNode(pNewEntry, pNode);
|
pushfrontNode(pNewEntry, pNode);
|
||||||
|
|
|
@ -653,7 +653,7 @@ static void doCacheRefresh(SCacheObj* pCacheObj, int64_t time, __cache_free_fn_t
|
||||||
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
||||||
|
|
||||||
if (pNode->expireTime < time && T_REF_VAL_GET(pNode) <= 0) {
|
if (pNode->expireTime < time && T_REF_VAL_GET(pNode) <= 0) {
|
||||||
// taosCacheReleaseNode(pCacheObj, pNode);
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,7 +213,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qReleaseQInfo(pVnode->qMgmt, (void**) &handle, freehandle);
|
qReleaseQInfo(pVnode->qMgmt, (void**) &handle, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SReadMsg *pReadMsg) {
|
||||||
code = vnodeDumpQueryResult(pRet, pVnode, *handle, &freeHandle);
|
code = vnodeDumpQueryResult(pRet, pVnode, *handle, &freeHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
qReleaseQInfo(pVnode->qMgmt, (void**) &handle, freeHandle);
|
qReleaseQInfo(pVnode->qMgmt, (void**) &handle, false);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue