From 60693e031fd81f537bd20554678c108c36ce894f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 30 Jun 2022 06:35:50 +0000 Subject: [PATCH] refact code --- source/dnode/vnode/src/tsdb/tsdbCommit.c | 92 ++++++++----------- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 9 +- 2 files changed, 41 insertions(+), 60 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 2bf4f5cd73..80c01d137e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -881,10 +881,48 @@ _err: return code; } -static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { +static int32_t tsdbCommitFileDataEnd(SCommitter *pCommitter) { + int32_t code = 0; + + // write blockIdx + code = tsdbWriteBlockIdx(pCommitter->pWriter, pCommitter->aBlockIdxN, NULL); + if (code) goto _err; + + // update file header + code = tsdbUpdateDFileSetHeader(pCommitter->pWriter); + if (code) goto _err; + + // upsert SDFileSet + code = tsdbFSStateUpsertDFileSet(pCommitter->pTsdb->fs->nState, tsdbDataFWriterGetWSet(pCommitter->pWriter)); + if (code) goto _err; + + // close and sync + code = tsdbDataFWriterClose(&pCommitter->pWriter, 1); + if (code) goto _err; + + if (pCommitter->pReader) { + code = tsdbDataFReaderClose(&pCommitter->pReader); + goto _err; + } + +_exit: + return code; + +_err: + tsdbError("vgId:%d commit file data end failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + return code; +} + +static int32_t tsdbCommitFileData(SCommitter *pCommitter) { int32_t code = 0; STsdb *pTsdb = pCommitter->pTsdb; SMemTable *pMemTable = pTsdb->imem; + + // commit file data start + code = tsdbCommitFileDataStart(pCommitter); + if (code) goto _err; + + // commit file data impl int32_t iTbData = 0; int32_t nTbData = taosArrayGetSize(pMemTable->aTbData); int32_t iBlockIdx = 0; @@ -940,56 +978,6 @@ static int32_t tsdbCommitFileDataImpl(SCommitter *pCommitter) { continue; } - return code; - -_err: - tsdbError("vgId:%d commit file data impl failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); - return code; -} - -static int32_t tsdbCommitFileDataEnd(SCommitter *pCommitter) { - int32_t code = 0; - - // write blockIdx - code = tsdbWriteBlockIdx(pCommitter->pWriter, pCommitter->aBlockIdxN, NULL); - if (code) goto _err; - - // update file header - code = tsdbUpdateDFileSetHeader(pCommitter->pWriter); - if (code) goto _err; - - // upsert SDFileSet - code = tsdbFSStateUpsertDFileSet(pCommitter->pTsdb->fs->nState, tsdbDataFWriterGetWSet(pCommitter->pWriter)); - if (code) goto _err; - - // close and sync - code = tsdbDataFWriterClose(&pCommitter->pWriter, 1); - if (code) goto _err; - - if (pCommitter->pReader) { - code = tsdbDataFReaderClose(&pCommitter->pReader); - goto _err; - } - -_exit: - return code; - -_err: - tsdbError("vgId:%d commit file data end failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); - return code; -} - -static int32_t tsdbCommitFileData(SCommitter *pCommitter) { - int32_t code = 0; - - // commit file data start - code = tsdbCommitFileDataStart(pCommitter); - if (code) goto _err; - - // commit file data impl - code = tsdbCommitFileDataImpl(pCommitter); - if (code) goto _err; - // commit file data end code = tsdbCommitFileDataEnd(pCommitter); if (code) goto _err; @@ -997,7 +985,7 @@ static int32_t tsdbCommitFileData(SCommitter *pCommitter) { return code; _err: - tsdbError("vgId:%d commit file data failed since %s", TD_VID(pCommitter->pTsdb->pVnode), tstrerror(code)); + tsdbError("vgId:%d commit file data failed since %s", TD_VID(pTsdb->pVnode), tstrerror(code)); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index cb8e981d2d..0d83fe23ea 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -1239,14 +1239,7 @@ _err: } int32_t tsdbUpdateDFileSetHeader(SDataFWriter *pWriter) { - int32_t code = 0; - int64_t size = TSDB_FHDR_SIZE; - int64_t n; - uint8_t hdr[TSDB_FHDR_SIZE]; - SHeadFile *pHeadFile = &pWriter->wSet.fHead; - SDataFile *pDataFile = &pWriter->wSet.fData; - SLastFile *pLastFile = &pWriter->wSet.fLast; - SSmaFile *pSmaFile = &pWriter->wSet.fSma; + int32_t code = 0; // head ============== code = tsdbUpdateDFileHdr(pWriter->pHeadFD, &pWriter->wSet, TSDB_HEAD_FILE);