From e3f57a167870dd50cd69d9945dc679cae13a0bed Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 14 Nov 2024 10:34:19 +0800 Subject: [PATCH] tsdb/cache: reuse update ctx array --- source/dnode/vnode/src/inc/tsdb.h | 1 + source/dnode/vnode/src/tsdb/tsdbCache.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index c1123db7a33d..ef37b41f3094 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -347,6 +347,7 @@ typedef struct { tb_uid_t suid; tb_uid_t uid; STSchema *pTSchema; + SArray *ctxArray; } SRocksCache; typedef struct { diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 2cef541cdba3..eb0e7b684e92 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -234,6 +234,7 @@ static int32_t tsdbOpenRocksCache(STsdb *pTsdb) { pTsdb->rCache.suid = -1; pTsdb->rCache.uid = -1; pTsdb->rCache.pTSchema = NULL; + pTsdb->rCache.ctxArray = NULL; TAOS_RETURN(code); @@ -267,6 +268,7 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) { rocksdb_cache_destroy(pTsdb->rCache.blockcache); rocksdb_comparator_destroy(pTsdb->rCache.my_comparator); taosMemoryFree(pTsdb->rCache.pTSchema); + taosArrayDestroy(pTsdb->rCache.ctxArray); } static void rocksMayWrite(STsdb *pTsdb, bool force) { @@ -1340,7 +1342,6 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 TSDBROW lRow = {.type = TSDBROW_ROW_FMT, .pTSRow = aRow[nRow - 1], .version = version}; STSchema *pTSchema = NULL; int32_t sver = TSDBROW_SVERSION(&lRow); - SArray *ctxArray = NULL; SSHashObj *iColHash = NULL; TAOS_CHECK_GOTO(tsdbUpdateSkm(pTsdb, suid, uid, sver), &lino, _exit); @@ -1349,10 +1350,13 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 TSDBROW tRow = {.type = TSDBROW_ROW_FMT, .version = version}; int32_t nCol = pTSchema->numOfCols; - ctxArray = taosArrayInit(nCol * 2, sizeof(SLastUpdateCtx)); - if (ctxArray == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + if (!pTsdb->rCache.ctxArray) { + pTsdb->rCache.ctxArray = taosArrayInit(nCol * 2, sizeof(SLastUpdateCtx)); + if (!pTsdb->rCache.ctxArray) { + TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + } } + SArray *ctxArray = pTsdb->rCache.ctxArray; // 1. prepare by lrow STsdbRowKey tsdbRowKey = {0}; @@ -1436,8 +1440,8 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 tsdbError("vgId:%d, %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code)); } - taosArrayDestroy(ctxArray); tSimpleHashCleanup(iColHash); + taosArrayClear(ctxArray); TAOS_RETURN(code); }