From c0a0e075978224f6fd39c3c2263aec79f5466015 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 1 Aug 2023 16:02:09 +0800 Subject: [PATCH] cache/read: lazy init uidList when laoding from tsdb --- source/dnode/vnode/src/tsdb/tsdbCache.c | 29 ++++++++++++++++++++- source/dnode/vnode/src/tsdb/tsdbCacheRead.c | 23 ---------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 5a384c6bb5..62c61dd397 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -1615,10 +1615,37 @@ static STableLoadInfo *getTableLoadInfo(SCacheRowsReader *pReader, uint64_t uid) return pInfo; } +static int32_t uidComparFunc(const void *p1, const void *p2) { + uint64_t pu1 = *(uint64_t *)p1; + uint64_t pu2 = *(uint64_t *)p2; + if (pu1 == pu2) { + return 0; + } else { + return (pu1 < pu2) ? -1 : 1; + } +} + +static uint64_t *getUidList(SCacheRowsReader *pReader) { + if (!pReader->uidList) { + int32_t numOfTables = pReader->numOfTables; + + pReader->uidList = taosMemoryMalloc(numOfTables * sizeof(uint64_t)); + + for (int32_t i = 0; i < numOfTables; ++i) { + uint64_t uid = pReader->pTableList[i].uid; + pReader->uidList[i] = uid; + } + + taosSort(pReader->uidList, numOfTables, sizeof(uint64_t), uidComparFunc); + } + + return pReader->uidList; +} + static int32_t loadTombFromBlk(const TTombBlkArray *pTombBlkArray, SCacheRowsReader *pReader, void *pFileReader, bool isFile) { int32_t code = 0; - uint64_t *uidList = pReader->uidList; + uint64_t *uidList = getUidList(pReader); int32_t numOfTables = pReader->numOfTables; int64_t suid = pReader->info.suid; diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index eb899fb82c..d51305f446 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -133,16 +133,6 @@ int32_t tsdbReuseCacherowsReader(void* reader, void* pTableIdList, int32_t numOf return TSDB_CODE_SUCCESS; } -static int32_t uidComparFunc(const void* p1, const void* p2) { - uint64_t pu1 = *(uint64_t*)p1; - uint64_t pu2 = *(uint64_t*)p2; - if (pu1 == pu2) { - return 0; - } else { - return (pu1 < pu2) ? -1 : 1; - } -} - int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, int32_t numOfTables, int32_t numOfCols, SArray* pCidList, int32_t* pSlotIds, uint64_t suid, void** pReader, const char* idstr) { *pReader = NULL; @@ -168,19 +158,6 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, p->pTableList = pTableIdList; p->numOfTables = numOfTables; - p->uidList = taosMemoryMalloc(numOfTables * sizeof(uint64_t)); - if (p->uidList == NULL) { - tsdbCacherowsReaderClose(p); - return TSDB_CODE_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < numOfTables; ++i) { - uint64_t uid = p->pTableList[i].uid; - p->uidList[i] = uid; - } - - taosSort(p->uidList, numOfTables, sizeof(uint64_t), uidComparFunc); - int32_t code = setTableSchema(p, suid, idstr); if (code != TSDB_CODE_SUCCESS) { tsdbCacherowsReaderClose(p);