From 4d0f46fb5d65222c841d827925be56fed43cb3b2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 5 Jul 2022 03:05:04 +0000 Subject: [PATCH] more snapshot --- source/dnode/vnode/src/meta/metaSnapshot.c | 5 ++- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 47 ++++++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index 013ec19411..e3124096bd 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -75,7 +75,8 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { for (;;) { code = tdbTbcGet(pReader->pTbc, &pKey, &nKey, &pData, &nData); if (code || ((STbDbKey*)pData)->version > pReader->ever) { - return TSDB_CODE_VND_READ_END; + code = TSDB_CODE_VND_READ_END; + goto _exit; } if (((STbDbKey*)pData)->version < pReader->sver) { @@ -95,6 +96,8 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { ((SSnapDataHdr*)(*ppData))->type = 0; // TODO: use macro ((SSnapDataHdr*)(*ppData))->size = nData; memcpy(((SSnapDataHdr*)(*ppData))->data, pData, nData); + +_exit: return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index e5500accab..c4bbca893d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -26,6 +26,8 @@ struct STsdbSnapReader { SDataFReader* pDataFReader; int32_t iBlockIdx; SArray* aBlockIdx; // SArray + SMapData mBlock; // SMapData + SBlockData blkData; // for del file int8_t delDone; SDelFReader* pDelFReader; @@ -57,7 +59,7 @@ _err: static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) { int32_t code = 0; STsdb* pTsdb = pReader->pTsdb; - SDelFile* pDelFile = pTsdb->fs->nState->pDelFile; + SDelFile* pDelFile = pTsdb->fs->cState->pDelFile; if (pReader->pDelFReader == NULL) { if (pDelFile == NULL) { @@ -69,6 +71,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) { code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pTsdb, NULL); if (code) goto _err; + // read index code = tsdbReadDelIdx(pReader->pDelFReader, pReader->aDelIdx, NULL); if (code) goto _err; @@ -121,6 +124,29 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapRe pReader->sver = sver; pReader->ever = ever; + pReader->aBlockIdx = taosArrayInit(0, sizeof(SBlockIdx)); + if (pReader->aBlockIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + pReader->mBlock = tMapDataInit(); + + code = tBlockDataInit(&pReader->blkData); + if (code) goto _err; + + pReader->aDelIdx = taosArrayInit(0, sizeof(SDelIdx)); + if (pReader->aDelIdx == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + + pReader->aDelData = taosArrayInit(0, sizeof(SDelData)); + if (pReader->aDelData == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + *ppReader = pReader; return code; @@ -131,8 +157,23 @@ _err: } int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) { - int32_t code = 0; - taosMemoryFree(ppReader); + int32_t code = 0; + STsdbSnapReader* pReader = *ppReader; + + taosArrayDestroy(pReader->aDelData); + taosArrayDestroy(pReader->aDelIdx); + if (pReader->pDelFReader) { + tsdbDelFReaderClose(&pReader->pDelFReader); + } + tBlockDataClear(&pReader->blkData); + tMapDataClear(&pReader->mBlock); + taosArrayDestroy(&pReader->aBlockIdx); + if (pReader->pDataFReader) { + tsdbDataFReaderClose(&pReader->pDataFReader); + } + taosMemoryFree(pReader); + *ppReader = NULL; + return code; } -- GitLab