From 4ee2cb13aace6f74c5c89bee2cbc255057cbbec1 Mon Sep 17 00:00:00 2001 From: jtao1735 Date: Wed, 13 May 2020 04:28:18 +0000 Subject: [PATCH] avoid a potential bug --- src/tsdb/src/tsdbMain.c | 1 + src/vnode/inc/vnodeInt.h | 1 + src/vnode/src/vnodeMain.c | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index df09b26c71..f06230c16f 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -284,6 +284,7 @@ int32_t tsdbCloseRepo(TsdbRepoT *repo) { pRepo->tsdbCache->curBlock = NULL; tsdbUnLockRepo(repo); + if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_START); tsdbCommitData((void *)repo); tsdbCloseFileH(pRepo->tsdbFileH); diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h index b2dd69df37..d41957d8f4 100644 --- a/src/vnode/inc/vnodeInt.h +++ b/src/vnode/inc/vnodeInt.h @@ -38,6 +38,7 @@ typedef struct { int status; int8_t role; int64_t version; + int64_t savedVersion; void *wqueue; void *rqueue; void *wal; diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index ec5ac40d04..2e55b6f93a 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -380,8 +380,10 @@ static void vnodeCleanUp(SVnodeObj *pVnode) { static int vnodeProcessTsdbStatus(void *arg, int status) { SVnodeObj *pVnode = arg; - if (status == TSDB_STATUS_COMMIT_START) + if (status == TSDB_STATUS_COMMIT_START) { + pVnode->savedVersion = pVnode->version; return walRenew(pVnode->wal); + } if (status == TSDB_STATUS_COMMIT_OVER) return vnodeSaveVersion(pVnode); @@ -690,14 +692,14 @@ static int32_t vnodeSaveVersion(SVnodeObj *pVnode) { char * content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"version\": %" PRId64 "\n", pVnode->version); + len += snprintf(content + len, maxLen - len, " \"version\": %" PRId64 "\n", pVnode->savedVersion); len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); fclose(fp); free(content); - vPrint("vgId:%d, save vnode version:%" PRId64 " successed", pVnode->vgId, pVnode->version); + vPrint("vgId:%d, save vnode version:%" PRId64 " succeed", pVnode->vgId, pVnode->savedVersion); return 0; } @@ -739,7 +741,7 @@ static bool vnodeReadVersion(SVnodeObj *pVnode) { ret = true; - vPrint("vgId:%d, read vnode version successed, version:%%" PRId64, pVnode->vgId, pVnode->version); + vPrint("vgId:%d, read vnode version succeed, version:%" PRId64, pVnode->vgId, pVnode->version); PARSE_OVER: free(content); -- GitLab