diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 4a6f6777875a7c7a5e855f2a57db38383d3d0d15..1b85ce26fecac4c4c8f6c3e713c7dece723dbeaf 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -103,10 +103,20 @@ static SBlockData* loadLastBlock(SLDataIter *pIter, const char* idStr) { SSttBlockLoadInfo* pInfo = pIter->pBlockLoadInfo; if (pInfo->blockIndex[0] == pIter->iSttBlk) { + if (pInfo->currentLoadBlockIndex != 0) { + tsdbDebug("current load index is set to 0, block index:%d, file index:%d, due to uid:%" PRIu64 ", load data, %s", + pIter->iSttBlk, pIter->iStt, pIter->uid, idStr); + pInfo->currentLoadBlockIndex = 0; + } return &pInfo->blockData[0]; } if (pInfo->blockIndex[1] == pIter->iSttBlk) { + if (pInfo->currentLoadBlockIndex != 1) { + tsdbDebug("current load index is set to 1, block index:%d, file index:%d, due to uid:%"PRIu64", load data, %s", + pIter->iSttBlk, pIter->iStt, pIter->uid, idStr); + pInfo->currentLoadBlockIndex = 1; + } return &pInfo->blockData[1]; } @@ -130,12 +140,15 @@ static SBlockData* loadLastBlock(SLDataIter *pIter, const char* idStr) { pInfo->elapsedTime += el; pInfo->loadBlocks += 1; - tsdbDebug("read last block, index:%d, last file index:%d, elapsed time:%.2f ms, %s", pIter->iSttBlk, pIter->iStt, el, idStr); + tsdbDebug("read last block, total load:%d, trigger by uid:%"PRIu64", last file index:%d, last block index:%d, entry:%d, %p, elapsed time:%.2f ms, %s", + pInfo->loadBlocks, pIter->uid, pIter->iStt, pIter->iSttBlk, pInfo->currentLoadBlockIndex, pBlock, el, idStr); if (code != TSDB_CODE_SUCCESS) { goto _exit; } pInfo->blockIndex[pInfo->currentLoadBlockIndex] = pIter->iSttBlk; + tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr); + pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1; } @@ -323,8 +336,10 @@ void tLDataIterClose(SLDataIter *pIter) { taosMemoryFree(pIter); } -void tLDataIterNextBlock(SLDataIter *pIter) { +void tLDataIterNextBlock(SLDataIter *pIter, const char* idStr) { int32_t step = pIter->backward ? -1 : 1; + int32_t oldIndex = pIter->iSttBlk; + pIter->iSttBlk += step; int32_t index = -1; @@ -371,6 +386,10 @@ void tLDataIterNextBlock(SLDataIter *pIter) { if (index != -1) { pIter->iSttBlk = index; pIter->pSttBlk = (SSttBlk *)taosArrayGet(pIter->pBlockLoadInfo->aSttBlk, pIter->iSttBlk); + tsdbDebug("try next last file block:%d from %d, trigger by uid:%"PRIu64", file index:%d, %s", pIter->iSttBlk, oldIndex, pIter->uid, pIter->iStt, + idStr); + } else { + tsdbDebug("no more last block qualified, uid:%"PRIu64", file index::%d, %s", pIter->uid, oldIndex, idStr); } } @@ -394,15 +413,11 @@ static void findNextValidRow(SLDataIter *pIter, const char* idStr) { for (; i < pBlockData->nRow && i >= 0; i += step) { if (pBlockData->aUid != NULL) { if (!pIter->backward) { - /*if (pBlockData->aUid[i] < pIter->uid) { - continue; - } else */if (pBlockData->aUid[i] > pIter->uid) { + if (pBlockData->aUid[i] > pIter->uid) { break; } } else { - /*if (pBlockData->aUid[i] > pIter->uid) { - continue; - } else */if (pBlockData->aUid[i] < pIter->uid) { + if (pBlockData->aUid[i] < pIter->uid) { break; } } @@ -457,7 +472,7 @@ bool tLDataIterNextRow(SLDataIter *pIter, const char* idStr) { findNextValidRow(pIter, idStr); if (pIter->iRow >= pBlockData->nRow || pIter->iRow < 0) { - tLDataIterNextBlock(pIter); + tLDataIterNextBlock(pIter, idStr); if (pIter->pSttBlk == NULL) { // no more data goto _exit; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index de64b8a61e4888c7143412bc0770ec9430f144fb..ac2b7a8db3279991977c884110b66765a3060757 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -845,8 +845,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn if ((pDumpInfo->rowIndex == 0 && asc) || (pDumpInfo->rowIndex == pBlock->nRow - 1 && (!asc))) { if (asc && pReader->window.skey <= pBlock->minKey.ts) { //pDumpInfo->rowIndex = 0; - } else - if (!asc && pReader->window.ekey >= pBlock->maxKey.ts) { + } else if (!asc && pReader->window.ekey >= pBlock->maxKey.ts) { //pDumpInfo->rowIndex = pBlock->nRow - 1; } else { int32_t pos = asc ? pBlock->nRow - 1 : 0; @@ -1644,6 +1643,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, STSRow* pTSRow = NULL; SRowMerger merge = {0}; TSDBROW fRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree); + tsdbTrace("fRow ptr:%p, %d, uid:%"PRIu64", %s", fRow.pBlockData, fRow.iRow, pLastBlockReader->uid, pReader->idStr); // only last block exists if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) {