From 2c3f35e7c789d0489e4f53d09a90a1d24c2feb49 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 25 Jan 2022 11:46:15 +0000 Subject: [PATCH] save sdb in every 3 seconds --- source/dnode/mgmt/impl/src/dndMgmt.c | 2 +- source/dnode/mnode/impl/src/mndTrans.c | 4 +++- source/dnode/mnode/sdb/src/sdb.c | 6 +----- source/dnode/mnode/sdb/src/sdbFile.c | 15 ++++++++++++--- tests/script/tsim/dnode/basic1.sim | 6 +++--- tests/script/tsim/table/basic1.sim | 12 ++++++------ 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndMgmt.c b/source/dnode/mgmt/impl/src/dndMgmt.c index b127fb1d64..dce5c01895 100644 --- a/source/dnode/mgmt/impl/src/dndMgmt.c +++ b/source/dnode/mgmt/impl/src/dndMgmt.c @@ -529,7 +529,7 @@ int32_t dndInitMgmt(SDnode *pDnode) { } if (pMgmt->dropped) { - dError("dnode will not start for its already dropped"); + dError("dnode not start since its already dropped"); return -1; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 03226c7400..808e6dcbe5 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -921,7 +921,7 @@ static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; - void *pIter = NULL; + void * pIter = NULL; while (1) { pIter = sdbFetch(pMnode->pSdb, SDB_TRANS, pIter, (void **)&pTrans); @@ -930,4 +930,6 @@ void mndTransPullup(SMnode *pMnode) { mndTransExecute(pMnode, pTrans); sdbRelease(pMnode->pSdb, pTrans); } + + sdbWriteFile(pMnode->pSdb); } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 39b5bb4d5b..26809ea059 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -64,11 +64,7 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - if (pSdb->curVer > pSdb->lastCommitVer) { - mDebug("write sdb file for current ver:%" PRId64 " larger than last commit ver:%" PRId64, pSdb->curVer, - pSdb->lastCommitVer); - sdbWriteFile(pSdb); - } + sdbWriteFile(pSdb); if (pSdb->currDir != NULL) { tfree(pSdb->currDir); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 1f6d6cbda8..6d17423324 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -221,7 +221,7 @@ PARSE_SDB_DATA_ERROR: return code; } -int32_t sdbWriteFile(SSdb *pSdb) { +static int32_t sdbWriteFileImp(SSdb *pSdb) { int32_t code = 0; char tmpfile[PATH_MAX] = {0}; @@ -229,7 +229,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { char curfile[PATH_MAX] = {0}; snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); - mDebug("start to write file:%s", curfile); + mDebug("start to write file:%s, current ver:%" PRId64 ", commit ver:%" PRId64, curfile, pSdb->curVer, + pSdb->lastCommitVer); FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile); if (fd <= 0) { @@ -323,12 +324,20 @@ int32_t sdbWriteFile(SSdb *pSdb) { return code; } +int32_t sdbWriteFile(SSdb *pSdb) { + if (pSdb->curVer == pSdb->lastCommitVer) { + return 0; + } + + return sdbWriteFileImp(pSdb); +} + int32_t sdbDeploy(SSdb *pSdb) { if (sdbRunDeployFp(pSdb) != 0) { return -1; } - if (sdbWriteFile(pSdb) != 0) { + if (sdbWriteFileImp(pSdb) != 0) { return -1; } diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/basic1.sim index e689bb3261..6061b6ece1 100644 --- a/tests/script/tsim/dnode/basic1.sim +++ b/tests/script/tsim/dnode/basic1.sim @@ -178,9 +178,9 @@ if $rows != 3 then endi sql select * from st -#if $rows != 15 then -# return -1 -#endi +if $rows != 15 then + return -1 +endi print =============== drop dnode sql drop dnode 2; diff --git a/tests/script/tsim/table/basic1.sim b/tests/script/tsim/table/basic1.sim index f47630b737..776b09b813 100644 --- a/tests/script/tsim/table/basic1.sim +++ b/tests/script/tsim/table/basic1.sim @@ -139,9 +139,9 @@ endi print =============== query data frpm st sql select * from st -#if $rows != 21 then -# return -1 -#endi +if $rows != 21 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start @@ -200,8 +200,8 @@ endi print =============== query data frpm st sql select * from st -#if $rows != 21 then -# return -1 -#endi +if $rows != 21 then + return -1 +endi system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file