From 0d4b9df6ad15275410fa0a60122ef75eedf26e37 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 21 Oct 2021 13:15:52 +0800 Subject: [PATCH] code optimization --- src/tsdb/inc/tsdbReadImpl.h | 24 ++++++------------------ src/tsdb/src/tsdbCommit.c | 2 +- src/tsdb/src/tsdbReadImpl.c | 6 ++---- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/tsdb/inc/tsdbReadImpl.h b/src/tsdb/inc/tsdbReadImpl.h index 1775873ca9..12727adb89 100644 --- a/src/tsdb/inc/tsdbReadImpl.h +++ b/src/tsdb/inc/tsdbReadImpl.h @@ -71,12 +71,12 @@ typedef struct { * blkVer; // 0 - original block, 1 - block since importing .smad/.smal * aggrOffset; // only valid when blkVer > 0 and aggrStat > 0 */ -#define SBlockFieldsP1 \ - uint64_t aggrStat : 1; \ - uint64_t blkVer : 7; \ - uint64_t aggrOffset : 56; \ - uint32_t aggrLen; \ - uint32_t padding +#define SBlockFieldsP1 \ + uint64_t aggrStat : 1; \ + uint64_t blkVer : 7; \ + uint64_t aggrOffset : 56; \ + uint64_t aggrNumOfCols : 16; \ + uint64_t padding : 48 typedef struct { SBlockFieldsP0; @@ -213,7 +213,6 @@ static FORCE_INLINE size_t tsdbBlockStatisSize(int nCols, uint32_t blkVer) { } } -#define TSDB_BLOCK_AGGR_COLS(blkLen, blkVer) ((blkLen - sizeof(TSCKSUM)) / sizeof(SAggrBlkColV##blkVer)) #define TSDB_BLOCK_AGGR_SIZE(ncols, blkVer) (sizeof(SAggrBlkColV##blkVer) * (ncols) + sizeof(TSCKSUM)) static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { @@ -227,17 +226,6 @@ static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { } } -static FORCE_INLINE int32_t tsdbBlockAggrCols(uint32_t blkLen, uint32_t blkVer) { - switch (blkVer) { - case TSDB_SBLK_VER_0: - ASSERT(false); - return 0; - case TSDB_SBLK_VER_1: - default: - return TSDB_BLOCK_AGGR_COLS(blkLen, 1); - } -} - int tsdbInitReadH(SReadH *pReadh, STsdbRepo *pRepo); void tsdbDestroyReadH(SReadH *pReadh); int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 3a9793ac95..9b79e11f5a 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -1216,7 +1216,7 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDFile pBlock->aggrStat = aggrStatus; pBlock->blkVer = SBlockVerLatest; pBlock->aggrOffset = (uint64_t)offsetAggr; - pBlock->aggrLen = tsizeAggr; + pBlock->aggrNumOfCols = nAggrCols; pBlock->padding = 0; // padding filled with 0 tsdbDebug("vgId:%d tid:%d a block of data is written to file %s, offset %" PRId64 diff --git a/src/tsdb/src/tsdbReadImpl.c b/src/tsdb/src/tsdbReadImpl.c index afe901d1dc..0f238c9a16 100644 --- a/src/tsdb/src/tsdbReadImpl.c +++ b/src/tsdb/src/tsdbReadImpl.c @@ -469,8 +469,7 @@ static int tsdbLoadBlockStatisFromAggr(SReadH *pReadh, SBlock *pBlock) { return -1; } - size_t sizeAggr = pBlock->aggrLen; - // tsdbBlockAggrSize(pBlock->numOfCols, (uint32_t)pBlock->blkVer); + size_t sizeAggr = tsdbBlockAggrSize(pBlock->aggrNumOfCols, (uint32_t)pBlock->blkVer); if (tsdbMakeRoom((void **)(&(pReadh->pAggrBlkData)), sizeAggr) < 0) return -1; int64_t nreadAggr = tsdbReadDFile(pDFileAggr, (void *)(pReadh->pAggrBlkData), sizeAggr); @@ -579,10 +578,9 @@ void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBl } } else if (pBlock->aggrStat) { SAggrBlkData *pAggrBlkData = pReadh->pAggrBlkData; - int32_t nAggrBlkCols = tsdbBlockAggrCols(pBlock->aggrLen, pBlock->blkVer); for (int i = 0, j = 0; i < numOfCols;) { - if (j >= nAggrBlkCols) { + if (j >= pBlock->aggrNumOfCols) { pStatis[i].numOfNull = -1; i++; continue; -- GitLab