fix(tsdb): record the pinned block iter.

This commit is contained in:
Haojun Liao 2023-10-16 11:48:57 +08:00
parent 18bb27cdff
commit ccecf05ff8
2 changed files with 21 additions and 17 deletions

View File

@ -749,8 +749,7 @@ typedef struct SMergeTree {
int8_t backward; int8_t backward;
SRBTree rbt; SRBTree rbt;
SLDataIter *pIter; SLDataIter *pIter;
bool destroyLoadInfo; SLDataIter *pPinnedBlockIter;
SSttBlockLoadInfo *pLoadInfo;
const char *idStr; const char *idStr;
bool ignoreEarlierTs; bool ignoreEarlierTs;
} SMergeTree; } SMergeTree;

View File

@ -846,16 +846,18 @@ static void tLDataIterPinSttBlock(SLDataIter* pIter, const char* id) {
if (pInfo->blockData[0].sttBlockIndex == pIter->iSttBlk) { if (pInfo->blockData[0].sttBlockIndex == pIter->iSttBlk) {
pInfo->blockData[0].pin = true; pInfo->blockData[0].pin = true;
ASSERT(!pInfo->blockData[1].pin); ASSERT(!pInfo->blockData[1].pin);
tsdbDebug("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id);
return; return;
} }
if (pInfo->blockData[1].sttBlockIndex == pIter->iSttBlk) { if (pInfo->blockData[1].sttBlockIndex == pIter->iSttBlk) {
pInfo->blockData[1].pin = true; pInfo->blockData[1].pin = true;
ASSERT(!pInfo->blockData[0].pin); ASSERT(!pInfo->blockData[0].pin);
tsdbDebug("pin stt-block, blockIndex:%d, stt-fileVer:%"PRId64" %s", pIter->iSttBlk, pIter->cid, id);
return; return;
} }
tsdbError("failed to pin any stt block, sttBlock:%d, %s", pIter->iSttBlk, id); tsdbError("failed to pin any stt block, sttBlock:%d stt-fileVer:%"PRId64" %s", pIter->iSttBlk, pIter->cid, id);
} }
static void tLDataIterUnpinSttBlock(SLDataIter* pIter, const char* id) { static void tLDataIterUnpinSttBlock(SLDataIter* pIter, const char* id) {
@ -863,16 +865,20 @@ static void tLDataIterUnpinSttBlock(SLDataIter* pIter, const char* id) {
if (pInfo->blockData[0].pin) { if (pInfo->blockData[0].pin) {
ASSERT(!pInfo->blockData[1].pin); ASSERT(!pInfo->blockData[1].pin);
pInfo->blockData[0].pin = false; pInfo->blockData[0].pin = false;
tsdbDebug("unpin stt-block, blockIndex:%d, stt-fileVer:%"PRId64" %s", pInfo->blockData[1].sttBlockIndex,
pIter->cid, id);
return; return;
} }
if (pInfo->blockData[1].pin) { if (pInfo->blockData[1].pin) {
ASSERT(!pInfo->blockData[0].pin); ASSERT(!pInfo->blockData[0].pin);
pInfo->blockData[1].pin = false; pInfo->blockData[1].pin = false;
tsdbDebug("pin stt-block, blockIndex:%d, stt-fileVer:%" PRId64 " %s", pInfo->blockData[1].sttBlockIndex, pIter->cid,
id);
return; return;
} }
tsdbError("failed to unpin any stt block, sttBlock:%d, %s", pIter->iSttBlk, id); tsdbError("failed to unpin any stt block, sttBlock:%d stt-fileVer:%" PRId64 " %s", pIter->iSttBlk, pIter->cid, id);
} }
void tMergeTreePinSttBlock(SMergeTree *pMTree) { void tMergeTreePinSttBlock(SMergeTree *pMTree) {
@ -880,16 +886,18 @@ void tMergeTreePinSttBlock(SMergeTree *pMTree) {
return; return;
} }
SLDataIter* pIter = pMTree->pIter; SLDataIter *pIter = pMTree->pIter;
pMTree->pPinnedBlockIter = pIter;
tLDataIterPinSttBlock(pIter, pMTree->idStr); tLDataIterPinSttBlock(pIter, pMTree->idStr);
} }
void tMergeTreeUnpinSttBlock(SMergeTree *pMTree) { void tMergeTreeUnpinSttBlock(SMergeTree *pMTree) {
if (pMTree->pIter == NULL) { if (pMTree->pPinnedBlockIter == NULL) {
return; return;
} }
SLDataIter* pIter = pMTree->pIter; SLDataIter* pIter = pMTree->pPinnedBlockIter;
pMTree->pPinnedBlockIter = NULL;
tLDataIterUnpinSttBlock(pIter, pMTree->idStr); tLDataIterUnpinSttBlock(pIter, pMTree->idStr);
} }
@ -927,8 +935,5 @@ bool tMergeTreeNext(SMergeTree *pMTree) {
void tMergeTreeClose(SMergeTree *pMTree) { void tMergeTreeClose(SMergeTree *pMTree) {
pMTree->pIter = NULL; pMTree->pIter = NULL;
if (pMTree->destroyLoadInfo) { pMTree->pPinnedBlockIter = NULL;
pMTree->pLoadInfo = destroyLastBlockLoadInfo(pMTree->pLoadInfo);
pMTree->destroyLoadInfo = false;
}
} }