From 22d9a8079ae767c4f88aae9259cebb09e657a6b1 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 6 Jan 2021 22:53:38 +0800 Subject: [PATCH] partial work --- src/tsdb/src/tsdbCommit.c | 66 +++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index b98dfed698..276285a347 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -29,6 +29,8 @@ typedef struct { SCommitIter *iters; // memory iterators SReadH readh; SDFileSet * pWSet; + TSKEY minKey; + TSKEY maxKey; SArray * aBlkIdx; SArray * aSupBlk; SArray * aSubBlk; @@ -439,22 +441,74 @@ static int tsdbCommitToTable(SCommitH *pch, int tid) { tsdbSetCommitTable(pch, pIter->pTable); + // No memory data and no disk data, just return if (pIter->pIter == NULL && pch->readh.pBlockIdx == NULL) { TSDB_RUNLOCK_TABLE(pIter->pTable); return 0; } - if (tsdbLoadBlockInfo(pch, NULL) < 0) { - TSDB_RUNLOCK_TABLE(pIter->pTable); - return -1; - } + tsdbLoadBlockInfo(&(pch->readh), NULL); - // Loop to merge disk data and - while (true) { + if (pIter->pIter == NULL) { + // No memory data but has disk data // TODO + } else { + TSKEY nextKey = tsdbNextIterKey(pIter->pIter); + int cidx = 0; + SBlock *pBlock = NULL; + + void *ptr = taosbsearch((void *)(&nextKey), pch->readh.pBlkInfo->blocks, pch->readh.pBlockIdx->numOfBlocks, + sizeof(SBlock), tsdbComparKeyBlock, TD_GE); + + while (true) { + if ((nextKey == TSDB_DATA_TIMESTAMP_NULL || nextKey > pch->maxKey) && (cidx >= pch->readh.pBlockIdx->numOfBlocks)) + break; + + if (tsdbComparKeyBlock((void *)(&nextKey), pBlock) < 0) { + if (pBlock->last) { + // merge with the last block + } else { + // Commit until pch->maxKey or (pBlock[1].keyFirst-1) + } + } else if (tsdbComparKeyBlock((void *)(&nextKey), pBlock) == 0) { // merge the block + + } else { + + } + } } TSDB_RUNLOCK_TABLE(pIter->pTable); + tsdbWriteBlockInfo(pch); + + return 0; +} + +static int tsdbSetCommitTable(SCommitH *pch, STable *pTable) { + // TODO + return 0; +} + +static int tsdbComparKeyBlock(const void *arg1, const void *arg2) { + TSKEY key = *(TSKEY *)arg1; + SBlock *pBlock = (SBlock *)arg2; + + if (key < pBlock->keyFirst) { + return -1; + } else if (key > pBlock->keyLast) { + return 1; + } else { + return 0; + } +} + +static int tsdbAppendCommit(SCommitIter *pIter, TSKEY keyEnd) { + // TODO + return 0; +} + +static int tsdbMergeCommit(SCommitIter *pIter, SBlock *pBlock, TSKEY keyEnd) { + // TODO return 0; } \ No newline at end of file -- GitLab