From 49728a235e83f58df0a995e6a4c88779d9980d9b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 25 Apr 2023 17:32:45 +0800 Subject: [PATCH] fix: more fix --- source/dnode/vnode/src/inc/tsdb.h | 5 +- source/dnode/vnode/src/tsdb/tsdbDataIter.c | 61 ++++++++++++++-------- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 26 +++++---- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 2a85b191a4..4d3111a9b7 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -322,8 +322,9 @@ int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData, #define TSDB_STT_FILE_DATA_ITER 2 #define TSDB_TOMB_FILE_DATA_ITER 3 -#define TSDB_FILTER_FLAG_BY_VERSION 0x1 -#define TSDB_FILTER_FLAG_BY_TABLEID 0x2 +#define TSDB_FILTER_FLAG_BY_VERSION 0x1 +#define TSDB_FILTER_FLAG_BY_TABLEID 0x2 +#define TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE 0x4 #define TSDB_RBTN_TO_DATA_ITER(pNode) ((STsdbDataIter2 *)(((char *)pNode) - offsetof(STsdbDataIter2, rbtn))) /* open */ diff --git a/source/dnode/vnode/src/tsdb/tsdbDataIter.c b/source/dnode/vnode/src/tsdb/tsdbDataIter.c index 3299a2f497..e27aec5b1b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDataIter.c +++ b/source/dnode/vnode/src/tsdb/tsdbDataIter.c @@ -14,6 +14,7 @@ */ #include "tsdb.h" +#include "vnodeInt.h" // STsdbDataIter2 /* open */ @@ -202,13 +203,6 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* for (;;) { while (pIter->dIter.iRow < pIter->dIter.bData.nRow) { if (pFilterInfo) { - if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) { - if (pFilterInfo->tbid.uid == pIter->dIter.bData.uid) { - pIter->dIter.iRow = pIter->dIter.bData.nRow; - continue; - } - } - if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) { if (pIter->dIter.bData.aVersion[pIter->dIter.iRow] < pFilterInfo->sver || pIter->dIter.bData.aVersion[pIter->dIter.iRow] > pFilterInfo->ever) { @@ -232,13 +226,6 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* // filter if (pFilterInfo) { - if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) { - if (tTABLEIDCmprFn(&pFilterInfo->tbid, &pIter->rowInfo) == 0) { - pIter->dIter.iDataBlk = pIter->dIter.mDataBlk.nItem; - continue; - } - } - if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) { if (pFilterInfo->sver > dataBlk.maxVer || pFilterInfo->ever < dataBlk.minVer) { pIter->dIter.iDataBlk++; @@ -262,13 +249,23 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* if (pIter->dIter.iBlockIdx < taosArrayGetSize(pIter->dIter.aBlockIdx)) { SBlockIdx* pBlockIdx = taosArrayGet(pIter->dIter.aBlockIdx, pIter->dIter.iBlockIdx); - if (pFilterInfo && (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID)) { - int32_t c = tTABLEIDCmprFn(pBlockIdx, &pFilterInfo->tbid); - if (c == 0) { - pIter->dIter.iBlockIdx++; - continue; - } else if (c < 0) { - ASSERT(0); + if (pFilterInfo) { + if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) { + int32_t c = tTABLEIDCmprFn(pBlockIdx, &pFilterInfo->tbid); + if (c == 0) { + pIter->dIter.iBlockIdx++; + continue; + } else if (c < 0) { + ASSERT(0); + } + } + + if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) { + SMetaInfo info; + if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pBlockIdx->uid, &info, NULL)) { + pIter->dIter.iBlockIdx++; + continue; + } } } @@ -304,14 +301,24 @@ static int32_t tsdbSttFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* p for (;;) { while (pIter->sIter.iRow < pIter->sIter.bData.nRow) { if (pFilterInfo) { + int64_t uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow]; if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) { - int64_t uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow]; if (pFilterInfo->tbid.uid == uid) { pIter->sIter.iRow++; continue; } } + if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) { + if (pIter->rowInfo.uid != uid) { + SMetaInfo info; + if (metaGetInfo(pIter->sIter.pReader->pTsdb->pVnode->pMeta, uid, &info, NULL)) { + pIter->sIter.iRow++; + continue; + } + } + } + if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) { if (pFilterInfo->sver > pIter->sIter.bData.aVersion[pIter->sIter.iRow] || pFilterInfo->ever < pIter->sIter.bData.aVersion[pIter->sIter.iRow]) { @@ -395,6 +402,16 @@ static int32_t tsdbTombFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* if (pIter->tIter.iDelIdx < taosArrayGetSize(pIter->tIter.aDelIdx)) { SDelIdx* pDelIdx = taosArrayGet(pIter->tIter.aDelIdx, pIter->tIter.iDelIdx); + if (pFilterInfo) { + if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) { + SMetaInfo info; + if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pDelIdx->uid, &info, NULL)) { + pIter->tIter.iDelIdx++; + continue; + } + } + } + code = tsdbReadDelData(pIter->tIter.pReader, pDelIdx, pIter->tIter.aDelData); TSDB_CHECK_CODE(code, lino, _exit); diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index aed863d194..dfea125cc1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -70,10 +70,11 @@ static int32_t tsdbSnapReadFileDataStart(STsdbSnapReader* pReader) { if (pReader->pIter) { // iter to next with filter info (sver, ever) - code = tsdbDataIterNext2(pReader->pIter, - &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION, // flag - .sver = pReader->sver, - .ever = pReader->ever}); + code = tsdbDataIterNext2( + pReader->pIter, + &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE, // flag + .sver = pReader->sver, + .ever = pReader->ever}); TSDB_CHECK_CODE(code, lino, _exit); if (pReader->pIter->rowInfo.suid || pReader->pIter->rowInfo.uid) { @@ -94,10 +95,11 @@ static int32_t tsdbSnapReadFileDataStart(STsdbSnapReader* pReader) { if (pReader->pIter) { // iter to valid row - code = tsdbDataIterNext2(pReader->pIter, - &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION, // flag - .sver = pReader->sver, - .ever = pReader->ever}); + code = tsdbDataIterNext2( + pReader->pIter, + &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE, // flag + .sver = pReader->sver, + .ever = pReader->ever}); TSDB_CHECK_CODE(code, lino, _exit); if (pReader->pIter->rowInfo.suid || pReader->pIter->rowInfo.uid) { @@ -139,7 +141,8 @@ static int32_t tsdbSnapReadNextRow(STsdbSnapReader* pReader, SRowInfo** ppRowInf int32_t lino = 0; if (pReader->pIter) { - code = tsdbDataIterNext2(pReader->pIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION, // flag + code = tsdbDataIterNext2(pReader->pIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | + TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE, // flag .sver = pReader->sver, .ever = pReader->ever}); TSDB_CHECK_CODE(code, lino, _exit); @@ -346,8 +349,9 @@ static int32_t tsdbSnapReadNextTombData(STsdbSnapReader* pReader, SDelInfo** ppD int32_t lino = 0; code = tsdbDataIterNext2( - pReader->pTIter, - &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION, .sver = pReader->sver, .ever = pReader->ever}); + pReader->pTIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE, + .sver = pReader->sver, + .ever = pReader->ever}); TSDB_CHECK_CODE(code, lino, _exit); if (ppDelInfo) { -- GitLab