From e681bb02cd161a6dd525fe8e732715736b05a727 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 15 Feb 2023 19:23:49 +0800 Subject: [PATCH 1/3] fix(query): set the initial number of tables values. --- source/libs/executor/src/executil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index a98accba77..903151b254 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1086,8 +1086,8 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, size_t size = numOfTables * sizeof(uint64_t) + sizeof(int32_t); char* pPayload = taosMemoryMalloc(size); + *(int32_t*)pPayload = numOfTables; if (numOfTables > 0) { - *(int32_t*)pPayload = numOfTables; memcpy(pPayload + sizeof(int32_t), taosArrayGet(pUidList, 0), numOfTables * sizeof(uint64_t)); } From 717392782a93ffbd0c03805c4ca76347abfeded2 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 15 Feb 2023 19:50:56 +0800 Subject: [PATCH 2/3] fix(query): remove the invalid free. --- source/dnode/vnode/src/tsdb/tsdbCache.c | 4 ++-- source/libs/executor/src/executil.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index ec0944193a..10ab541978 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -17,7 +17,7 @@ static int32_t tsdbOpenBICache(STsdb *pTsdb) { int32_t code = 0; - SLRUCache *pCache = taosLRUCacheInit(5 * 1024 * 1024, -1, .5); + SLRUCache *pCache = taosLRUCacheInit(5 * 1024 * 1024, 1, .5); if (pCache == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -48,7 +48,7 @@ int32_t tsdbOpenCache(STsdb *pTsdb) { SLRUCache *pCache = NULL; size_t cfgCapacity = pTsdb->pVnode->config.cacheLastSize * 1024 * 1024; - pCache = taosLRUCacheInit(cfgCapacity, -1, .5); + pCache = taosLRUCacheInit(cfgCapacity, 1, .5); if (pCache == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 903151b254..040e67713d 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -1092,7 +1092,6 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, } metaUidFilterCachePut(metaHandle, pScanNode->suid, context.digest, tListLen(context.digest), pPayload, size, 1); - taosMemoryFree(pPayload); } } From c7a9ed34d08b85054132a35e245ce4aa775bbbca Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 15 Feb 2023 23:24:43 +0800 Subject: [PATCH 3/3] fix(query): fix memory leak and invalid free for tag filter cache. --- source/dnode/vnode/src/meta/metaCache.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 21a1014e87..366c072b6f 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -508,11 +508,11 @@ static void freePayload(const void* key, size_t keyLen, void* value) { const uint64_t* p = key; if (keyLen != sizeof(int64_t) * 4) { - metaError("key length is invalid, length:%d, expect:%d", (int32_t) keyLen, (int32_t) sizeof(uint64_t)*2); + metaError("key length is invalid, length:%d, expect:%d", (int32_t)keyLen, (int32_t)sizeof(uint64_t) * 2); return; } - SHashObj* pHashObj = (SHashObj*)p[0]; + SHashObj* pHashObj = (SHashObj*)p[0]; STagFilterResEntry** pEntry = taosHashGet(pHashObj, &p[1], sizeof(uint64_t)); { @@ -525,12 +525,13 @@ static void freePayload(const void* key, size_t keyLen, void* value) { while ((pNode = tdListNext(&iter)) != NULL) { uint64_t* digest = (uint64_t*)pNode->data; if (digest[0] == p[2] && digest[1] == p[3]) { - tdListPopNode(&((*pEntry)->list), pNode); + void* tmp = tdListPopNode(&((*pEntry)->list), pNode); + taosMemoryFree(tmp); int64_t et = taosGetTimestampUs(); metaInfo("clear items in cache, remain cached item:%d, elapsed time:%.2fms", listNEles(&((*pEntry)->list)), - (et - st)/1000.0); - return; + (et - st) / 1000.0); + break; } } }