From 01ffea909839c457585e6cd3bda6ff93fc314142 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 16 Apr 2020 18:08:53 +0800 Subject: [PATCH] TD-100 --- src/tsdb/src/tsdbRWHelper.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 2656334567..8b0025432b 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -884,18 +884,11 @@ static int tsdbMergeDataWithBlock(SRWHelper *pHelper, int blkIdx, SDataCols *pDa static int compTSKEY(const void *key1, const void *key2) { return ((TSKEY *)key1 - (TSKEY *)key2); } -static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t spaceNeeded) { +static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize) { SCompIdx *pIdx = pHelper->pCompIdx + pHelper->tableInfo.tid; - size_t spaceLeft = tsizeof((void *)pHelper->pCompInfo) - pIdx->len; - ASSERT(spaceLeft >= 0); - if (spaceLeft < spaceNeeded) { - size_t tsize = tsizeof(pHelper->pCompInfo) + sizeof(SCompBlock) * 16; - if (tsizeof(pHelper->pCompInfo) == 0) { - pIdx->len = sizeof(SCompData) + sizeof(TSCKSUM); - tsize = tsize + sizeof(SCompInfo) + sizeof(TSCKSUM); - } - + if (tsizeof((void *)pHelper->pCompInfo) <= esize) { + size_t tsize = esize + sizeof(SCompBlock) * 16; pHelper->pCompInfo = (SCompInfo *)trealloc(pHelper->pCompInfo, tsize); if (pHelper->pCompInfo == NULL) return -1; } @@ -910,7 +903,8 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int ASSERT(pCompBlock->numOfSubBlocks == 1); // Adjust memory if no more room - if (tsdbAdjustInfoSizeIfNeeded(pHelper, sizeof(SCompBlock)) < 0) goto _err; + if (pIdx->len == 0) pIdx->len = sizeof(SCompData) + sizeof(TSCKSUM); + if (tsdbAdjustInfoSizeIfNeeded(pHelper, pIdx->len + sizeof(SCompInfo)) < 0) goto _err; // Change the offset for (int i = 0; i < pIdx->numOfSuperBlocks; i++) { @@ -949,7 +943,8 @@ static int tsdbAddSubBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int blkId SCompBlock *pSCompBlock = pHelper->pCompInfo->blocks + blkIdx; ASSERT(pSCompBlock->numOfSubBlocks >= 1 && pSCompBlock->numOfSubBlocks < TSDB_MAX_SUBBLOCKS); - size_t spaceNeeded = (pSCompBlock->numOfSubBlocks == 1) ? sizeof(SCompBlock) * 2 : sizeof(SCompBlock); + size_t spaceNeeded = + (pSCompBlock->numOfSubBlocks == 1) ? pIdx->len + sizeof(SCompBlock) * 2 : pIdx->len + sizeof(SCompBlock); if (tsdbAdjustInfoSizeIfNeeded(pHelper, spaceNeeded) < 0) goto _err; // Add the sub-block -- GitLab