From 431998ee42c714175bd6a9053d9cc5d29cfa5fba Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 14 May 2020 05:32:41 +0000 Subject: [PATCH] add to commit option to tsdbCloseRepo --- src/inc/tsdb.h | 2 +- src/tsdb/src/tsdbMain.c | 29 ++++++++++++++++++++++------- src/vnode/src/vnodeMain.c | 4 ++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 32e3541692..2c774922a5 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -72,7 +72,7 @@ typedef void TsdbRepoT; // use void to hide implementation details from outside int tsdbCreateRepo(char *rootDir, STsdbCfg *pCfg, void *limiter); int32_t tsdbDropRepo(TsdbRepoT *repo); TsdbRepoT *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH); -int32_t tsdbCloseRepo(TsdbRepoT *repo); +int32_t tsdbCloseRepo(TsdbRepoT *repo, int toCommit); int32_t tsdbConfigRepo(TsdbRepoT *repo, STsdbCfg *pCfg); // --------- TSDB TABLE DEFINITION diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index c85f5cc838..41837eab5f 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -258,7 +258,7 @@ TsdbRepoT *tsdbOpenRepo(char *tsdbDir, STsdbAppH *pAppH) { * * @return 0 for success, -1 for failure and the error number is set */ -int32_t tsdbCloseRepo(TsdbRepoT *repo) { +int32_t tsdbCloseRepo(TsdbRepoT *repo, int toCommit) { STsdbRepo *pRepo = (STsdbRepo *)repo; if (pRepo == NULL) return 0; int id = pRepo->config.tsdbId; @@ -285,7 +285,7 @@ int32_t tsdbCloseRepo(TsdbRepoT *repo) { tsdbUnLockRepo(repo); if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_START); - tsdbCommitData((void *)repo); + if (toCommit) tsdbCommitData((void *)repo); tsdbCloseFileH(pRepo->tsdbFileH); @@ -1018,10 +1018,16 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters // Create and open files for commit tsdbGetDataDirName(pRepo, dataDir); - if ((pGroup = tsdbCreateFGroup(pFileH, dataDir, fid, pCfg->maxTables)) == NULL) goto _err; + if ((pGroup = tsdbCreateFGroup(pFileH, dataDir, fid, pCfg->maxTables)) == NULL) { + tsdbError("vgId:%d, failed to create file group %d", pRepo->config.tsdbId, fid); + goto _err; + } // Open files for write/read - if (tsdbSetAndOpenHelperFile(pHelper, pGroup) < 0) goto _err; + if (tsdbSetAndOpenHelperFile(pHelper, pGroup) < 0) { + tsdbError("vgId:%d, failed to set helper file", pRepo->config.tsdbId); + goto _err; + } // Loop to commit data in each table for (int tid = 1; tid < pCfg->maxTables; tid++) { @@ -1058,13 +1064,22 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters ASSERT(pDataCols->numOfPoints == 0); // Move the last block to the new .l file if neccessary - if (tsdbMoveLastBlockIfNeccessary(pHelper) < 0) goto _err; + if (tsdbMoveLastBlockIfNeccessary(pHelper) < 0) { + tsdbError("vgId:%d, failed to move last block", pRepo->config.tsdbId); + goto _err; + } // Write the SCompBlock part - if (tsdbWriteCompInfo(pHelper) < 0) goto _err; + if (tsdbWriteCompInfo(pHelper) < 0) { + tsdbError("vgId:%d, failed to write compInfo part", pRepo->config.tsdbId); + goto _err; + } } - if (tsdbWriteCompIdx(pHelper) < 0) goto _err; + if (tsdbWriteCompIdx(pHelper) < 0) { + tsdbError("vgId:%d, failed to write compIdx part", pRepo->config.tsdbId); + goto _err; + } tsdbCloseHelperFile(pHelper, 0); // TODO: make it atomic with some methods diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 838b9d290f..e9f0372752 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -376,7 +376,7 @@ static void vnodeCleanUp(SVnodeObj *pVnode) { cqClose(pVnode->cq); pVnode->cq = NULL; - tsdbCloseRepo(pVnode->tsdb); + tsdbCloseRepo(pVnode->tsdb, 1); pVnode->tsdb = NULL; walClose(pVnode->wal); @@ -427,7 +427,7 @@ static void vnodeNotifyFileSynced(void *ahandle) { char rootDir[128] = "\0"; sprintf(rootDir, "%s/tsdb", pVnode->rootDir); // clsoe tsdb, then open tsdb - tsdbCloseRepo(pVnode->tsdb); + tsdbCloseRepo(pVnode->tsdb, 0); STsdbAppH appH = {0}; appH.appH = (void *)pVnode; appH.notifyStatus = vnodeProcessTsdbStatus; -- GitLab