refactor: remove assert.
This commit is contained in:
parent
12e0f3fda8
commit
d83f29dc23
|
@ -92,7 +92,6 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*assert(connectRsp.epSet.numOfEps > 0);*/
|
|
||||||
if (connectRsp.epSet.numOfEps == 0) {
|
if (connectRsp.epSet.numOfEps == 0) {
|
||||||
setErrno(pRequest, TSDB_CODE_APP_ERROR);
|
setErrno(pRequest, TSDB_CODE_APP_ERROR);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
|
|
@ -982,7 +982,6 @@ void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// assert(pCur->vgroupIndex != -1 && pCur->tsIndex >= 0 && pCur->blockIndex >= 0);
|
|
||||||
if (pCur->vgroupIndex != -1) {
|
if (pCur->vgroupIndex != -1) {
|
||||||
tsBufGetBlock(pTSBuf, pCur->vgroupIndex, pCur->blockIndex);
|
tsBufGetBlock(pTSBuf, pCur->vgroupIndex, pCur->blockIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(forwardRows >= 0);
|
ASSERT(forwardRows >= 0);
|
||||||
return forwardRows;
|
return forwardRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +165,6 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC);
|
|
||||||
|
|
||||||
TSKEY* keyList = (TSKEY*)pValue;
|
TSKEY* keyList = (TSKEY*)pValue;
|
||||||
int32_t firstPos = 0;
|
int32_t firstPos = 0;
|
||||||
int32_t lastPos = num - 1;
|
int32_t lastPos = num - 1;
|
||||||
|
@ -230,7 +228,7 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
|
||||||
|
|
||||||
int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
|
int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
|
||||||
__block_search_fn_t searchFn, STableQueryInfo* item, int32_t order) {
|
__block_search_fn_t searchFn, STableQueryInfo* item, int32_t order) {
|
||||||
assert(startPos >= 0 && startPos < pDataBlockInfo->rows);
|
ASSERT(startPos >= 0 && startPos < pDataBlockInfo->rows);
|
||||||
|
|
||||||
int32_t num = -1;
|
int32_t num = -1;
|
||||||
int32_t step = GET_FORWARD_DIRECTION_FACTOR(order);
|
int32_t step = GET_FORWARD_DIRECTION_FACTOR(order);
|
||||||
|
@ -261,7 +259,6 @@ int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(num >= 0);
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +430,7 @@ static bool setTimeWindowInterpolationEndTs(SIntervalAggOperatorInfo* pInfo, SEx
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t nextRowIndex = endRowIndex + 1;
|
int32_t nextRowIndex = endRowIndex + 1;
|
||||||
assert(nextRowIndex >= 0);
|
ASSERT(nextRowIndex >= 0);
|
||||||
|
|
||||||
TSKEY nextKey = tsCols[nextRowIndex];
|
TSKEY nextKey = tsCols[nextRowIndex];
|
||||||
doTimeWindowInterpolation(pInfo->pPrevValues, pDataBlock, actualEndKey, endRowIndex, nextKey, nextRowIndex, key,
|
doTimeWindowInterpolation(pInfo->pPrevValues, pDataBlock, actualEndKey, endRowIndex, nextKey, nextRowIndex, key,
|
||||||
|
@ -494,9 +491,9 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext,
|
||||||
*/
|
*/
|
||||||
if (primaryKeys == NULL) {
|
if (primaryKeys == NULL) {
|
||||||
if (ascQuery) {
|
if (ascQuery) {
|
||||||
assert(pDataBlockInfo->window.skey <= pNext->ekey);
|
ASSERT(pDataBlockInfo->window.skey <= pNext->ekey);
|
||||||
} else {
|
} else {
|
||||||
assert(pDataBlockInfo->window.ekey >= pNext->skey);
|
ASSERT(pDataBlockInfo->window.ekey >= pNext->skey);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ascQuery && primaryKeys[startPos] > pNext->ekey) {
|
if (ascQuery && primaryKeys[startPos] > pNext->ekey) {
|
||||||
|
@ -533,7 +530,6 @@ static bool isResultRowInterpolated(SResultRow* pResult, SResultTsInterpType typ
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
|
static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
|
||||||
assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
|
|
||||||
if (type == RESULT_ROW_START_INTERP) {
|
if (type == RESULT_ROW_START_INTERP) {
|
||||||
pResult->startInterp = true;
|
pResult->startInterp = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -69,8 +69,6 @@ SArray* taosArrayInit_s(size_t elemSize, size_t initialSize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosArrayResize(SArray* pArray) {
|
static int32_t taosArrayResize(SArray* pArray) {
|
||||||
assert(pArray->size >= pArray->capacity);
|
|
||||||
|
|
||||||
size_t size = pArray->capacity;
|
size_t size = pArray->capacity;
|
||||||
size = (size << 1u);
|
size = (size << 1u);
|
||||||
|
|
||||||
|
@ -252,12 +250,12 @@ void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArraySet(SArray* pArray, size_t index, void* pData) {
|
void taosArraySet(SArray* pArray, size_t index, void* pData) {
|
||||||
assert(index < pArray->size);
|
ASSERT(index < pArray->size);
|
||||||
memcpy(TARRAY_GET_ELEM(pArray, index), pData, pArray->elemSize);
|
memcpy(TARRAY_GET_ELEM(pArray, index), pData, pArray->elemSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
|
void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
|
||||||
assert(cnt <= pArray->size);
|
ASSERT(cnt <= pArray->size);
|
||||||
pArray->size = pArray->size - cnt;
|
pArray->size = pArray->size - cnt;
|
||||||
if (pArray->size == 0 || cnt == 0) {
|
if (pArray->size == 0 || cnt == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -266,12 +264,15 @@ void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayPopTailBatch(SArray* pArray, size_t cnt) {
|
void taosArrayPopTailBatch(SArray* pArray, size_t cnt) {
|
||||||
assert(cnt <= pArray->size);
|
if (cnt >= pArray->size) {
|
||||||
|
cnt = pArray->size;
|
||||||
|
}
|
||||||
|
|
||||||
pArray->size = pArray->size - cnt;
|
pArray->size = pArray->size - cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosArrayRemove(SArray* pArray, size_t index) {
|
void taosArrayRemove(SArray* pArray, size_t index) {
|
||||||
assert(index < pArray->size);
|
ASSERT(index < pArray->size);
|
||||||
|
|
||||||
if (index == pArray->size - 1) {
|
if (index == pArray->size - 1) {
|
||||||
taosArrayPop(pArray);
|
taosArrayPop(pArray);
|
||||||
|
|
|
@ -244,9 +244,9 @@ static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STr
|
||||||
next->prev = pElem->prev;
|
next->prev = pElem->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCacheObj->numOfElemsInTrash == 0) {
|
// if (pCacheObj->numOfElemsInTrash == 0) {
|
||||||
assert(pCacheObj->pTrash == NULL);
|
// assert(pCacheObj->pTrash == NULL);
|
||||||
}
|
// }
|
||||||
|
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
@ -261,8 +261,6 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj *pCacheObj, STrashElem
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) {
|
static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) {
|
||||||
assert(pNode != NULL && pEntry != NULL);
|
|
||||||
|
|
||||||
pNode->pNext = pEntry->next;
|
pNode->pNext = pEntry->next;
|
||||||
pEntry->next = pNode;
|
pEntry->next = pNode;
|
||||||
pEntry->num += 1;
|
pEntry->num += 1;
|
||||||
|
@ -503,7 +501,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
|
||||||
uDebug("cache:%s, data: %p acquired by data in cache, refcnt:%d", pCacheObj->name, ptNode->data, ref);
|
uDebug("cache:%s, data: %p acquired by data in cache, refcnt:%d", pCacheObj->name, ptNode->data, ref);
|
||||||
|
|
||||||
// the data if referenced by at least one object, so the reference count must be greater than the value of 2.
|
// the data if referenced by at least one object, so the reference count must be greater than the value of 2.
|
||||||
assert(ref >= 2);
|
ASSERT(ref >= 2);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,7 +514,6 @@ void *taosCacheTransferData(SCacheObj *pCacheObj, void **data) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(T_REF_VAL_GET(ptNode) >= 1);
|
|
||||||
char *d = *data;
|
char *d = *data;
|
||||||
|
|
||||||
// clear its reference to old area
|
// clear its reference to old area
|
||||||
|
@ -575,19 +572,19 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
if (ref == 1) {
|
if (ref == 1) {
|
||||||
// If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may be
|
// If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may be
|
||||||
// destroyed by refresh worker if decrease ref count before removing it from linked-list.
|
// destroyed by refresh worker if decrease ref count before removing it from linked-list.
|
||||||
assert(pNode->pTNodeHeader->pData == pNode);
|
ASSERT(pNode->pTNodeHeader->pData == pNode);
|
||||||
|
|
||||||
__trashcan_wr_lock(pCacheObj);
|
__trashcan_wr_lock(pCacheObj);
|
||||||
doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader);
|
doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader);
|
||||||
__trashcan_unlock(pCacheObj);
|
__trashcan_unlock(pCacheObj);
|
||||||
|
|
||||||
ref = T_REF_DEC(pNode);
|
ref = T_REF_DEC(pNode);
|
||||||
assert(ref == 0);
|
ASSERT(ref == 0);
|
||||||
|
|
||||||
doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader);
|
doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader);
|
||||||
} else {
|
} else {
|
||||||
ref = T_REF_DEC(pNode);
|
ref = T_REF_DEC(pNode);
|
||||||
assert(ref >= 0);
|
ASSERT(ref >= 0);
|
||||||
}
|
}
|
||||||
} 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
|
||||||
|
@ -609,13 +606,13 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
"others already, prev must in trashcan",
|
"others already, prev must in trashcan",
|
||||||
pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data, T_REF_VAL_GET(pNode));
|
pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data, T_REF_VAL_GET(pNode));
|
||||||
|
|
||||||
assert(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL);
|
ASSERT(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL);
|
||||||
} else {
|
} else {
|
||||||
removeNodeInEntryList(pe, prev, p);
|
removeNodeInEntryList(pe, prev, p);
|
||||||
uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key,
|
uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key,
|
||||||
pNode->data, ref);
|
pNode->data, ref);
|
||||||
if (ref > 0) {
|
if (ref > 0) {
|
||||||
assert(pNode->pTNodeHeader == NULL);
|
ASSERT(pNode->pTNodeHeader == NULL);
|
||||||
taosAddToTrashcan(pCacheObj, pNode);
|
taosAddToTrashcan(pCacheObj, pNode);
|
||||||
} else { // ref == 0
|
} else { // ref == 0
|
||||||
atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size);
|
atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size);
|
||||||
|
@ -736,7 +733,7 @@ SCacheNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pDat
|
||||||
|
|
||||||
void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) {
|
void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) {
|
||||||
if (pNode->inTrashcan) { /* node is already in trash */
|
if (pNode->inTrashcan) { /* node is already in trash */
|
||||||
assert(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode);
|
ASSERT(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -782,7 +779,7 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) {
|
||||||
STrashElem *pElem = pCacheObj->pTrash;
|
STrashElem *pElem = pCacheObj->pTrash;
|
||||||
while (pElem) {
|
while (pElem) {
|
||||||
T_REF_VAL_CHECK(pElem->pData);
|
T_REF_VAL_CHECK(pElem->pData);
|
||||||
assert(pElem->next != pElem && pElem->prev != pElem);
|
ASSERT(pElem->next != pElem && pElem->prev != pElem);
|
||||||
|
|
||||||
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
||||||
uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key,
|
uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key,
|
||||||
|
@ -814,8 +811,6 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doCacheRefresh(SCacheObj *pCacheObj, int64_t time, __cache_trav_fn_t fp, void *param1) {
|
static void doCacheRefresh(SCacheObj *pCacheObj, int64_t time, __cache_trav_fn_t fp, void *param1) {
|
||||||
assert(pCacheObj != NULL);
|
|
||||||
|
|
||||||
SCacheObjTravSup sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
|
SCacheObjTravSup sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
|
||||||
doTraverseElems(pCacheObj, doRemoveExpiredFn, &sup);
|
doTraverseElems(pCacheObj, doRemoveExpiredFn, &sup);
|
||||||
}
|
}
|
||||||
|
@ -827,9 +822,7 @@ void taosCacheRefreshWorkerUnexpectedStopped(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCacheTimedRefresh(void *handle) {
|
void *taosCacheTimedRefresh(void *handle) {
|
||||||
assert(pCacheArrayList != NULL);
|
|
||||||
uDebug("cache refresh thread starts");
|
uDebug("cache refresh thread starts");
|
||||||
|
|
||||||
setThreadName("cacheRefresh");
|
setThreadName("cacheRefresh");
|
||||||
|
|
||||||
const int32_t SLEEP_DURATION = 500; // 500 ms
|
const int32_t SLEEP_DURATION = 500; // 500 ms
|
||||||
|
|
|
@ -150,7 +150,6 @@ static FORCE_INLINE SHashNode *doSearchInEntryList(SHashObj *pHashObj, SHashEntr
|
||||||
//atomic_add_fetch_64(&pHashObj->compTimes, 1);
|
//atomic_add_fetch_64(&pHashObj->compTimes, 1);
|
||||||
if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
|
if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
|
||||||
pNode->removed == 0) {
|
pNode->removed == 0) {
|
||||||
assert(pNode->hashVal == hashVal);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +188,6 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry *pe, SHashNode *prev, SHashNode *pNode,
|
static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry *pe, SHashNode *prev, SHashNode *pNode,
|
||||||
SHashNode *pNewNode) {
|
SHashNode *pNewNode) {
|
||||||
assert(pNode->keyLen == pNewNode->keyLen);
|
|
||||||
|
|
||||||
atomic_sub_fetch_16(&pNode->refCount, 1);
|
atomic_sub_fetch_16(&pNode->refCount, 1);
|
||||||
if (prev != NULL) {
|
if (prev != NULL) {
|
||||||
prev->next = pNewNode;
|
prev->next = pNewNode;
|
||||||
|
@ -236,7 +233,7 @@ static FORCE_INLINE bool taosHashTableEmpty(const SHashObj *pHashObj) { return t
|
||||||
|
|
||||||
SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTypeE type) {
|
SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTypeE type) {
|
||||||
if (fn == NULL) {
|
if (fn == NULL) {
|
||||||
assert(0);
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,19 +339,11 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
|
||||||
taosHashEntryWLock(pHashObj, pe);
|
taosHashEntryWLock(pHashObj, pe);
|
||||||
|
|
||||||
SHashNode *pNode = pe->next;
|
SHashNode *pNode = pe->next;
|
||||||
#if 0
|
|
||||||
if (pe->num > 0) {
|
|
||||||
assert(pNode != NULL);
|
|
||||||
} else {
|
|
||||||
assert(pNode == NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SHashNode *prev = NULL;
|
SHashNode *prev = NULL;
|
||||||
while (pNode) {
|
while (pNode) {
|
||||||
if ((pNode->keyLen == keyLen) && (*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0 &&
|
if ((pNode->keyLen == keyLen) && (*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0 &&
|
||||||
pNode->removed == 0) {
|
pNode->removed == 0) {
|
||||||
assert(pNode->hashVal == hashVal);
|
ASSERT(pNode->hashVal == hashVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,8 +359,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
|
||||||
}
|
}
|
||||||
|
|
||||||
pushfrontNodeInEntryList(pe, pNewNode);
|
pushfrontNodeInEntryList(pe, pNewNode);
|
||||||
assert(pe->next != NULL);
|
|
||||||
|
|
||||||
taosHashEntryWUnlock(pHashObj, pe);
|
taosHashEntryWUnlock(pHashObj, pe);
|
||||||
|
|
||||||
// enable resize
|
// enable resize
|
||||||
|
@ -446,14 +433,6 @@ void *taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void *
|
||||||
char *data = NULL;
|
char *data = NULL;
|
||||||
taosHashEntryRLock(pHashObj, pe);
|
taosHashEntryRLock(pHashObj, pe);
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (pe->num > 0) {
|
|
||||||
assert(pe->next != NULL);
|
|
||||||
} else {
|
|
||||||
assert(pe->next == NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SHashNode *pNode = doSearchInEntryList(pHashObj, pe, key, keyLen, hashVal);
|
SHashNode *pNode = doSearchInEntryList(pHashObj, pe, key, keyLen, hashVal);
|
||||||
if (pNode != NULL) {
|
if (pNode != NULL) {
|
||||||
if (pHashObj->callbackFp != NULL) {
|
if (pHashObj->callbackFp != NULL) {
|
||||||
|
@ -514,8 +493,6 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
||||||
|
|
||||||
// double check after locked
|
// double check after locked
|
||||||
if (pe->num == 0) {
|
if (pe->num == 0) {
|
||||||
assert(pe->next == NULL);
|
|
||||||
|
|
||||||
taosHashEntryWUnlock(pHashObj, pe);
|
taosHashEntryWUnlock(pHashObj, pe);
|
||||||
taosHashRUnlock(pHashObj);
|
taosHashRUnlock(pHashObj);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -573,8 +550,6 @@ void taosHashClear(SHashObj *pHashObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode = pEntry->next;
|
pNode = pEntry->next;
|
||||||
assert(pNode != NULL);
|
|
||||||
|
|
||||||
while (pNode) {
|
while (pNode) {
|
||||||
pNext = pNode->next;
|
pNext = pNode->next;
|
||||||
FREE_HASH_NODE(pHashObj->freeFp, pNode);
|
FREE_HASH_NODE(pHashObj->freeFp, pNode);
|
||||||
|
@ -677,8 +652,6 @@ void taosHashTableResize(SHashObj *pHashObj) {
|
||||||
|
|
||||||
pNode = pe->next;
|
pNode = pe->next;
|
||||||
|
|
||||||
assert(pNode != NULL);
|
|
||||||
|
|
||||||
while (pNode != NULL) {
|
while (pNode != NULL) {
|
||||||
int32_t newIdx = HASH_INDEX(pNode->hashVal, pHashObj->capacity);
|
int32_t newIdx = HASH_INDEX(pNode->hashVal, pHashObj->capacity);
|
||||||
pNext = pNode->next;
|
pNext = pNode->next;
|
||||||
|
@ -728,8 +701,6 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode) {
|
void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode) {
|
||||||
assert(pNode != NULL && pEntry != NULL);
|
|
||||||
|
|
||||||
pNode->next = pEntry->next;
|
pNode->next = pEntry->next;
|
||||||
pEntry->next = pNode;
|
pEntry->next = pNode;
|
||||||
|
|
||||||
|
|
|
@ -85,13 +85,13 @@ struct SLRUEntry {
|
||||||
#define TAOS_LRU_ENTRY_REF(h) (++(h)->refs)
|
#define TAOS_LRU_ENTRY_REF(h) (++(h)->refs)
|
||||||
|
|
||||||
static bool taosLRUEntryUnref(SLRUEntry *entry) {
|
static bool taosLRUEntryUnref(SLRUEntry *entry) {
|
||||||
assert(entry->refs > 0);
|
ASSERT(entry->refs > 0);
|
||||||
--entry->refs;
|
--entry->refs;
|
||||||
return entry->refs == 0;
|
return entry->refs == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosLRUEntryFree(SLRUEntry *entry) {
|
static void taosLRUEntryFree(SLRUEntry *entry) {
|
||||||
assert(entry->refs == 0);
|
ASSERT(entry->refs == 0);
|
||||||
|
|
||||||
if (entry->deleter) {
|
if (entry->deleter) {
|
||||||
(*entry->deleter)(entry->keyData, entry->keyLength, entry->value);
|
(*entry->deleter)(entry->keyData, entry->keyLength, entry->value);
|
||||||
|
@ -127,7 +127,7 @@ static void taosLRUEntryTableApply(SLRUEntryTable *table, _taos_lru_table_func_t
|
||||||
SLRUEntry *h = table->list[i];
|
SLRUEntry *h = table->list[i];
|
||||||
while (h) {
|
while (h) {
|
||||||
SLRUEntry *n = h->nextHash;
|
SLRUEntry *n = h->nextHash;
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(h));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(h));
|
||||||
func(h);
|
func(h);
|
||||||
h = n;
|
h = n;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ static void taosLRUEntryTableResize(SLRUEntryTable *table) {
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(table->elems == count);
|
ASSERT(table->elems == count);
|
||||||
|
|
||||||
taosMemoryFree(table->list);
|
taosMemoryFree(table->list);
|
||||||
table->list = newList;
|
table->list = newList;
|
||||||
|
@ -240,17 +240,16 @@ struct SLRUCacheShard {
|
||||||
static void taosLRUCacheShardMaintainPoolSize(SLRUCacheShard *shard) {
|
static void taosLRUCacheShardMaintainPoolSize(SLRUCacheShard *shard) {
|
||||||
while (shard->highPriPoolUsage > shard->highPriPoolCapacity) {
|
while (shard->highPriPoolUsage > shard->highPriPoolCapacity) {
|
||||||
shard->lruLowPri = shard->lruLowPri->next;
|
shard->lruLowPri = shard->lruLowPri->next;
|
||||||
assert(shard->lruLowPri != &shard->lru);
|
ASSERT(shard->lruLowPri != &shard->lru);
|
||||||
TAOS_LRU_ENTRY_SET_IN_HIGH_POOL(shard->lruLowPri, false);
|
TAOS_LRU_ENTRY_SET_IN_HIGH_POOL(shard->lruLowPri, false);
|
||||||
|
|
||||||
assert(shard->highPriPoolUsage >= shard->lruLowPri->totalCharge);
|
ASSERT(shard->highPriPoolUsage >= shard->lruLowPri->totalCharge);
|
||||||
shard->highPriPoolUsage -= shard->lruLowPri->totalCharge;
|
shard->highPriPoolUsage -= shard->lruLowPri->totalCharge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosLRUCacheShardLRUInsert(SLRUCacheShard *shard, SLRUEntry *e) {
|
static void taosLRUCacheShardLRUInsert(SLRUCacheShard *shard, SLRUEntry *e) {
|
||||||
assert(e->next == NULL);
|
ASSERT(e->next == NULL && e->prev == NULL);
|
||||||
assert(e->prev == NULL);
|
|
||||||
|
|
||||||
if (shard->highPriPoolRatio > 0 && (TAOS_LRU_ENTRY_IS_HIGH_PRI(e) || TAOS_LRU_ENTRY_HAS_HIT(e))) {
|
if (shard->highPriPoolRatio > 0 && (TAOS_LRU_ENTRY_IS_HIGH_PRI(e) || TAOS_LRU_ENTRY_HAS_HIT(e))) {
|
||||||
e->next = &shard->lru;
|
e->next = &shard->lru;
|
||||||
|
@ -277,8 +276,7 @@ static void taosLRUCacheShardLRUInsert(SLRUCacheShard *shard, SLRUEntry *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
|
static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
|
||||||
assert(e->next);
|
ASSERT(e->next && e->prev);
|
||||||
assert(e->prev);
|
|
||||||
|
|
||||||
if (shard->lruLowPri == e) {
|
if (shard->lruLowPri == e) {
|
||||||
shard->lruLowPri = e->prev;
|
shard->lruLowPri = e->prev;
|
||||||
|
@ -287,10 +285,10 @@ static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
|
||||||
e->prev->next = e->next;
|
e->prev->next = e->next;
|
||||||
e->prev = e->next = NULL;
|
e->prev = e->next = NULL;
|
||||||
|
|
||||||
assert(shard->lruUsage >= e->totalCharge);
|
ASSERT(shard->lruUsage >= e->totalCharge);
|
||||||
shard->lruUsage -= e->totalCharge;
|
shard->lruUsage -= e->totalCharge;
|
||||||
if (TAOS_LRU_ENTRY_IN_HIGH_POOL(e)) {
|
if (TAOS_LRU_ENTRY_IN_HIGH_POOL(e)) {
|
||||||
assert(shard->highPriPoolUsage >= e->totalCharge);
|
ASSERT(shard->highPriPoolUsage >= e->totalCharge);
|
||||||
shard->highPriPoolUsage -= e->totalCharge;
|
shard->highPriPoolUsage -= e->totalCharge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,13 +296,13 @@ static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
|
||||||
static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArray *deleted) {
|
static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArray *deleted) {
|
||||||
while (shard->usage + charge > shard->capacity && shard->lru.next != &shard->lru) {
|
while (shard->usage + charge > shard->capacity && shard->lru.next != &shard->lru) {
|
||||||
SLRUEntry *old = shard->lru.next;
|
SLRUEntry *old = shard->lru.next;
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
|
||||||
|
|
||||||
taosLRUCacheShardLRURemove(shard, old);
|
taosLRUCacheShardLRURemove(shard, old);
|
||||||
taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
||||||
|
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
||||||
assert(shard->usage >= old->totalCharge);
|
ASSERT(shard->usage >= old->totalCharge);
|
||||||
shard->usage -= old->totalCharge;
|
shard->usage -= old->totalCharge;
|
||||||
|
|
||||||
taosArrayPush(deleted, &old);
|
taosArrayPush(deleted, &old);
|
||||||
|
@ -391,11 +389,11 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
|
||||||
if (old != NULL) {
|
if (old != NULL) {
|
||||||
status = TAOS_LRU_STATUS_OK_OVERWRITTEN;
|
status = TAOS_LRU_STATUS_OK_OVERWRITTEN;
|
||||||
|
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(old));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old));
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
||||||
if (!TAOS_LRU_ENTRY_HAS_REFS(old)) {
|
if (!TAOS_LRU_ENTRY_HAS_REFS(old)) {
|
||||||
taosLRUCacheShardLRURemove(shard, old);
|
taosLRUCacheShardLRURemove(shard, old);
|
||||||
assert(shard->usage >= old->totalCharge);
|
ASSERT(shard->usage >= old->totalCharge);
|
||||||
shard->usage -= old->totalCharge;
|
shard->usage -= old->totalCharge;
|
||||||
|
|
||||||
taosArrayPush(lastReferenceList, &old);
|
taosArrayPush(lastReferenceList, &old);
|
||||||
|
@ -455,7 +453,7 @@ static LRUHandle *taosLRUCacheShardLookup(SLRUCacheShard *shard, const void *key
|
||||||
taosThreadMutexLock(&shard->mutex);
|
taosThreadMutexLock(&shard->mutex);
|
||||||
e = taosLRUEntryTableLookup(&shard->table, key, keyLen, hash);
|
e = taosLRUEntryTableLookup(&shard->table, key, keyLen, hash);
|
||||||
if (e != NULL) {
|
if (e != NULL) {
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(e));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e));
|
||||||
if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
|
if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
|
||||||
taosLRUCacheShardLRURemove(shard, e);
|
taosLRUCacheShardLRURemove(shard, e);
|
||||||
}
|
}
|
||||||
|
@ -474,12 +472,12 @@ static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_
|
||||||
|
|
||||||
SLRUEntry *e = taosLRUEntryTableRemove(&shard->table, key, keyLen, hash);
|
SLRUEntry *e = taosLRUEntryTableRemove(&shard->table, key, keyLen, hash);
|
||||||
if (e != NULL) {
|
if (e != NULL) {
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(e));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e));
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
||||||
if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
|
if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
|
||||||
taosLRUCacheShardLRURemove(shard, e);
|
taosLRUCacheShardLRURemove(shard, e);
|
||||||
|
|
||||||
assert(shard->usage >= e->totalCharge);
|
ASSERT(shard->usage >= e->totalCharge);
|
||||||
shard->usage -= e->totalCharge;
|
shard->usage -= e->totalCharge;
|
||||||
lastReference = true;
|
lastReference = true;
|
||||||
}
|
}
|
||||||
|
@ -499,11 +497,11 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
|
||||||
|
|
||||||
while (shard->lru.next != &shard->lru) {
|
while (shard->lru.next != &shard->lru) {
|
||||||
SLRUEntry *old = shard->lru.next;
|
SLRUEntry *old = shard->lru.next;
|
||||||
assert(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
|
ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
|
||||||
taosLRUCacheShardLRURemove(shard, old);
|
taosLRUCacheShardLRURemove(shard, old);
|
||||||
taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
||||||
assert(shard->usage >= old->totalCharge);
|
ASSERT(shard->usage >= old->totalCharge);
|
||||||
shard->usage -= old->totalCharge;
|
shard->usage -= old->totalCharge;
|
||||||
|
|
||||||
taosArrayPush(lastReferenceList, &old);
|
taosArrayPush(lastReferenceList, &old);
|
||||||
|
@ -524,7 +522,7 @@ static bool taosLRUCacheShardRef(SLRUCacheShard *shard, LRUHandle *handle) {
|
||||||
SLRUEntry *e = (SLRUEntry *)handle;
|
SLRUEntry *e = (SLRUEntry *)handle;
|
||||||
taosThreadMutexLock(&shard->mutex);
|
taosThreadMutexLock(&shard->mutex);
|
||||||
|
|
||||||
assert(TAOS_LRU_ENTRY_HAS_REFS(e));
|
ASSERT(TAOS_LRU_ENTRY_HAS_REFS(e));
|
||||||
TAOS_LRU_ENTRY_REF(e);
|
TAOS_LRU_ENTRY_REF(e);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&shard->mutex);
|
taosThreadMutexUnlock(&shard->mutex);
|
||||||
|
@ -545,7 +543,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
|
||||||
lastReference = taosLRUEntryUnref(e);
|
lastReference = taosLRUEntryUnref(e);
|
||||||
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
|
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
|
||||||
if (shard->usage > shard->capacity || eraseIfLastRef) {
|
if (shard->usage > shard->capacity || eraseIfLastRef) {
|
||||||
assert(shard->lru.next == &shard->lru || eraseIfLastRef);
|
ASSERT(shard->lru.next == &shard->lru || eraseIfLastRef);
|
||||||
|
|
||||||
taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash);
|
taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash);
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
||||||
|
@ -557,7 +555,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastReference && e->value) {
|
if (lastReference && e->value) {
|
||||||
assert(shard->usage >= e->totalCharge);
|
ASSERT(shard->usage >= e->totalCharge);
|
||||||
shard->usage -= e->totalCharge;
|
shard->usage -= e->totalCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -595,7 +593,7 @@ static size_t taosLRUCacheShardGetPinnedUsage(SLRUCacheShard *shard) {
|
||||||
|
|
||||||
taosThreadMutexLock(&shard->mutex);
|
taosThreadMutexLock(&shard->mutex);
|
||||||
|
|
||||||
assert(shard->usage >= shard->lruUsage);
|
ASSERT(shard->usage >= shard->lruUsage);
|
||||||
usage = shard->usage - shard->lruUsage;
|
usage = shard->usage - shard->lruUsage;
|
||||||
|
|
||||||
taosThreadMutexUnlock(&shard->mutex);
|
taosThreadMutexUnlock(&shard->mutex);
|
||||||
|
@ -687,7 +685,7 @@ void taosLRUCacheCleanup(SLRUCache *cache) {
|
||||||
if (cache) {
|
if (cache) {
|
||||||
if (cache->shards) {
|
if (cache->shards) {
|
||||||
int numShards = cache->numShards;
|
int numShards = cache->numShards;
|
||||||
assert(numShards > 0);
|
ASSERT(numShards > 0);
|
||||||
for (int i = 0; i < numShards; ++i) {
|
for (int i = 0; i < numShards; ++i) {
|
||||||
taosLRUCacheShardCleanup(&cache->shards[i]);
|
taosLRUCacheShardCleanup(&cache->shards[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue