From f977a50e9b3cb9569022d3008f9c489060dc2c32 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 13 Jul 2022 01:11:55 +0000 Subject: [PATCH] more vnode snapshot --- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 3 +- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 48 +++++++++++----------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index 06d4a86116..b02e1dabd3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -232,11 +232,12 @@ int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, STsdbSnapRe goto _err; } + tsdbInfo("vgId:%d vnode snapshot tsdb reader opened", TD_VID(pTsdb->pVnode)); *ppReader = pReader; return code; _err: - tsdbError("vgId:%d snapshot reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d vnode snapshot tsdb reader open failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); *ppReader = NULL; return code; } diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 0163ea0449..0e14df0380 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -55,9 +55,13 @@ _err: int32_t vnodeSnapReaderClose(SVSnapReader *pReader) { int32_t code = 0; - // tFree(pReader->pData); - // if (pReader->pTsdbReader) tsdbSnapReaderClose(&pReader->pTsdbReader); - // if (pReader->pMetaReader) metaSnapReaderClose(&pReader->pMetaReader); + if (pReader->pTsdbReader) { + tsdbSnapReaderClose(&pReader->pTsdbReader); + } + + if (pReader->pMetaReader) { + metaSnapReaderClose(&pReader->pMetaReader); + } vInfo("vgId:%d vnode snapshot reader closed", TD_VID(pReader->pVnode)); taosMemoryFree(pReader); @@ -85,8 +89,6 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) pReader->metaDone = 1; code = metaSnapReaderClose(&pReader->pMetaReader); if (code) goto _err; - - vInfo("vgId:%d vnode snapshot meta data read end, index:%" PRId64, TD_VID(pReader->pVnode), pReader->index); } } } @@ -94,23 +96,23 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) // TSDB ============== if (!pReader->tsdbDone) { // open if not - // if (pReader->pTsdbReader == NULL) { - // code = tsdbSnapReaderOpen(pReader->pVnode->pTsdb, pReader->sver, pReader->ever, &pReader->pTsdbReader); - // if (code) goto _err; - // } - - // code = tsdbSnapRead(pReader->pTsdbReader, &pReader->pData); - // if (code) { - // if (code == TSDB_CODE_VND_READ_END) { - // pReader->tsdbDone = 1; - // } else { - // goto _err; - // } - // } else { - // *ppData = pReader->pData; - // *nData = sizeof(SSnapDataHdr) + ((SSnapDataHdr *)pReader->pData)->size; - // goto _exit; - // } + if (pReader->pTsdbReader == NULL) { + code = tsdbSnapReaderOpen(pReader->pVnode->pTsdb, pReader->sver, pReader->ever, &pReader->pTsdbReader); + if (code) goto _err; + } + + code = tsdbSnapRead(pReader->pTsdbReader, ppData); + if (code) { + goto _err; + } else { + if (*ppData) { + goto _exit; + } else { + pReader->tsdbDone = 1; + code = tsdbSnapReaderClose(&pReader->pTsdbReader); + if (code) goto _err; + } + } } *ppData = NULL; @@ -130,7 +132,7 @@ _exit: return code; _err: - vError("vgId:% snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); + vError("vgId:% vnode snapshot read failed since %s", TD_VID(pReader->pVnode), tstrerror(code)); return code; } -- GitLab