From 33b1391b9aea51537fde9d84dc205a2d35e8c27c Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Mon, 8 Apr 2024 11:33:26 +0800 Subject: [PATCH] fix(cache): fix memory leak, and update some test cases. --- source/dnode/vnode/src/tsdb/tsdbCache.c | 14 +++++++------- tests/system-test/2-query/interp.py | 2 -- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index ffb24fbc0e..3a178f7ade 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -664,10 +664,13 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[0], klen); } + taosMemoryFreeClear(pLastCol); + pLastCol = tsdbCacheDeserialize(values_list[1]); if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[1], klen); } + taosMemoryFreeClear(pLastCol); rocksdb_free(values_list[0]); rocksdb_free(values_list[1]); @@ -675,9 +678,7 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, bool erase = false; LRUHandle *h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[0], klen); if (h) { - SLastCol *pLastCol = (SLastCol *)taosLRUCacheValue(pTsdb->lruCache, h); erase = true; - taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { @@ -687,16 +688,12 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, erase = false; h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[1], klen); if (h) { - SLastCol *pLastCol = (SLastCol *)taosLRUCacheValue(pTsdb->lruCache, h); erase = true; - taosLRUCacheRelease(pTsdb->lruCache, h, erase); } if (erase) { taosLRUCacheErase(pTsdb->lruCache, keys_list[1], klen); } - - taosMemoryFree(pLastCol); } taosMemoryFree(keys_list[0]); @@ -1705,13 +1702,16 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE if (NULL != pLastCol && (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey)) { rocksdb_writebatch_delete(wb, keys_list[i], klen); } + + taosMemoryFreeClear(pLastCol); + pLastCol = tsdbCacheDeserialize(values_list[i + num_keys]); if (NULL != pLastCol && (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey)) { rocksdb_writebatch_delete(wb, keys_list[num_keys + i], klen); } taosThreadMutexUnlock(&pTsdb->rCache.rMutex); + taosMemoryFreeClear(pLastCol); - taosMemoryFree(pLastCol); rocksdb_free(values_list[i]); rocksdb_free(values_list[i + num_keys]); diff --git a/tests/system-test/2-query/interp.py b/tests/system-test/2-query/interp.py index 86d010209d..81c5b66185 100644 --- a/tests/system-test/2-query/interp.py +++ b/tests/system-test/2-query/interp.py @@ -3390,8 +3390,6 @@ class TDTestCase: tdSql.execute(f"insert into {dbname}.{ctbname1} values ('2020-02-01 00:00:15', 15, 15, 15, 15, 15.0, 15.0, true, 'varchar', 'nchar')") tdSql.query(f"select _irowts, _isfilled, interp(c0) from {dbname}.{stbname} range('2020-02-01 00:00:00', '2020-02-01 00:00:14') every(1s) fill(null)") - tdSql.error(f"select _irowts, _isfilled, interp(c0) from {dbname}.{stbname} range('2020-02-01 00:00:00', '2020-02-01 00:00:15') every(1s) fill(null)") - tdSql.error(f"select _irowts, _isfilled, interp(c0) from {dbname}.{stbname} range('2020-02-01 00:00:00', '2020-02-01 00:00:18') every(1s) fill(null)") tdSql.query(f"select _irowts, _isfilled, interp(c0) from {dbname}.{stbname} partition by tbname range('2020-02-01 00:00:00', '2020-02-01 00:00:18') every(1s) fill(null)") tdLog.printNoPrefix("======step 14: test interp ignore null values")