From cdeca85e3187f1300371220b8c5daead53a1d263 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 1 Sep 2022 15:19:59 +0800 Subject: [PATCH] refactor: do some internal refactor. --- source/dnode/vnode/src/tsdb/tsdbMergeTree.c | 36 +++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index a32721b2b3..a53f67d949 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -189,6 +189,7 @@ bool tLDataIterNextRow(SLDataIter *pIter) { } int32_t iBlockL = pIter->iBlockL; + if (pIter->bData.nRow == 0 && pIter->pBlockL != NULL) { // current block not loaded yet code = tsdbReadLastBlockEx(pIter->pReader, pIter->iLast, pIter->pBlockL, &pIter->bData); if (code != TSDB_CODE_SUCCESS) { @@ -199,30 +200,25 @@ bool tLDataIterNextRow(SLDataIter *pIter) { } pIter->iRow += step; - findNextValidRow(pIter); - if (pIter->iRow >= pIter->bData.nRow || pIter->iRow < 0) { - tLDataIterNextBlock(pIter); - if (pIter->pBlockL == NULL) { // no more data - goto _exit; + while(1) { + findNextValidRow(pIter); + + if (pIter->iRow >= pIter->bData.nRow || pIter->iRow < 0) { + tLDataIterNextBlock(pIter); + if (pIter->pBlockL == NULL) { // no more data + goto _exit; + } + } else { + break; } - } - if (iBlockL != pIter->iBlockL) { - if (pIter->pBlockL) { + if (iBlockL != pIter->iBlockL) { code = tsdbReadLastBlockEx(pIter->pReader, pIter->iLast, pIter->pBlockL, &pIter->bData); if (code) { goto _exit; } - - pIter->iRow = pIter->backward? (pIter->bData.nRow-1):0; - findNextValidRow(pIter); - if (pIter->iRow >= pIter->bData.nRow || pIter->iRow < 0) { - // todo try next block - } - } else { - // no more data - goto _exit; + pIter->iRow = pIter->backward ? (pIter->bData.nRow - 1) : 0; } } @@ -232,10 +228,10 @@ bool tLDataIterNextRow(SLDataIter *pIter) { _exit: if (code != TSDB_CODE_SUCCESS) { - return false; - } else { - return pIter->pBlockL != NULL; + terrno = code; } + + return (code == TSDB_CODE_SUCCESS) && (pIter->pBlockL != NULL); } SRowInfo *tLDataIterGet(SLDataIter *pIter) { -- GitLab