From d2f991327a1baa4ef6d306740c3a60c84a0822c3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 13 Nov 2021 16:15:09 +0800 Subject: [PATCH] get account error while read sdb file --- include/dnode/mnode/sdb/sdb.h | 8 ++++---- source/dnode/mgmt/src/dnodeMnode.c | 2 +- source/dnode/mnode/impl/src/mnode.c | 2 +- source/dnode/mnode/sdb/src/sdb.c | 4 ---- source/dnode/mnode/sdb/src/sdbFile.c | 20 +++++++++++++++----- source/dnode/mnode/sdb/src/sdbHash.c | 28 ++++++++++++++-------------- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 0f4913069f..90c5ef0c4a 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -116,9 +116,9 @@ typedef enum { SDB_CLUSTER = 2, SDB_DNODE = 3, SDB_MNODE = 4, - SDB_ACCT = 5, + SDB_USER = 5, SDB_AUTH = 6, - SDB_USER = 7, + SDB_ACCT = 7, SDB_DB = 8, SDB_VGROUP = 9, SDB_STABLE = 10, @@ -148,9 +148,9 @@ int32_t sdbInit(); void sdbCleanup(); void sdbSetTable(SSdbTable table); -int32_t sdbRead(); +int32_t sdbOpen(); +void sdbClose(); int32_t sdbWrite(SSdbRaw *pRaw); -int32_t sdbCommit(); int32_t sdbDeploy(); void sdbUnDeploy(); diff --git a/source/dnode/mgmt/src/dnodeMnode.c b/source/dnode/mgmt/src/dnodeMnode.c index 5a1ac3b070..48cc1cb20d 100644 --- a/source/dnode/mgmt/src/dnodeMnode.c +++ b/source/dnode/mgmt/src/dnodeMnode.c @@ -536,7 +536,7 @@ static int32_t dnodeOpenMnode() { SMnodeCfg cfg = {.replica = 1}; cfg.replicas[0].port = tsServerPort; tstrncpy(cfg.replicas[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); - return dnodeDeployMnode(&cfg); + code = dnodeDeployMnode(&cfg); } else { dInfo("start to open mnode"); return dnodeStartMnode(); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 763780ef46..f52e60dbad 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -138,7 +138,7 @@ static int32_t mnodeAllocStartSteps() { if (steps == NULL) return -1; taosStepAdd(steps, "mnode-timer", mnodeInitTimer, NULL); - taosStepAdd(steps, "mnode-sdb-file", sdbRead, (CleanupFp)sdbCommit); + taosStepAdd(steps, "mnode-sdb-file", sdbOpen, sdbClose); taosStepAdd(steps, "mnode-balance", mnodeInitBalance, mnodeCleanupBalance); taosStepAdd(steps, "mnode-profile", mnodeInitProfile, mnodeCleanupProfile); taosStepAdd(steps, "mnode-show", mnodeInitShow, mnodeCleanUpShow); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 88ef813428..8e9b7fbecc 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -58,10 +58,6 @@ int32_t sdbInit() { } void sdbCleanup() { - if (tsSdb.curVer != tsSdb.lastCommitVer) { - sdbCommit(); - } - if (tsSdb.currDir != NULL) { tfree(tsSdb.currDir); } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 0de1bf85a9..69c82c77f1 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -211,7 +211,7 @@ static int32_t sdbWriteDataFile() { return code; } -int32_t sdbRead() { +int32_t sdbOpen() { mDebug("start to read mnode file"); if (sdbReadDataFile() != 0) { @@ -221,9 +221,18 @@ int32_t sdbRead() { return 0; } -int32_t sdbCommit() { - mDebug("start to write mnode file"); - return sdbWriteDataFile(); +void sdbClose() { + if (tsSdb.curVer != tsSdb.lastCommitVer) { + mDebug("start to write mnode file"); + sdbWriteDataFile(); + } + + for (int32_t i = 0; i < SDB_MAX; ++i) { + SHashObj *hash = tsSdb.hashObjs[i]; + if (hash != NULL) { + taosHashClear(hash); + } + } } int32_t sdbDeploy() { @@ -235,10 +244,11 @@ int32_t sdbDeploy() { return -1; } - if (sdbCommit() != 0) { + if (sdbWriteDataFile() != 0) { return -1; } + sdbClose(); return 0; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 1092d39328..9c19e7f1a2 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -55,6 +55,7 @@ static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ if (pDstRow != NULL) { terrno = TSDB_CODE_SDB_OBJ_ALREADY_THERE; taosWUnLockLatch(pLock); + sdbFreeRow(pRow); return -1; } @@ -64,6 +65,7 @@ static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ if (taosHashPut(hash, pRow->pObj, keySize, &pRow, sizeof(void *)) != 0) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosWUnLockLatch(pLock); + sdbFreeRow(pRow); return -1; } @@ -75,6 +77,7 @@ static int32_t sdbInsertRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ taosWLockLatch(pLock); taosHashRemove(hash, pRow->pObj, keySize); taosWUnLockLatch(pLock); + sdbFreeRow(pRow); return -1; } } @@ -98,11 +101,10 @@ static int32_t sdbUpdateRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ SdbUpdateFp updateFp = tsSdb.updateFps[pRow->sdb]; if (updateFp != NULL) { - if ((*updateFp)(pRow->pObj, pDstRow->pObj) != 0) { - return -1; - } + (*updateFp)(pRow->pObj, pDstRow->pObj); } + sdbFreeRow(pRow); return 0; } @@ -111,23 +113,25 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_ taosWLockLatch(pLock); SSdbRow **ppDstRow = taosHashGet(hash, pRow->pObj, keySize); - if (ppDstRow == NULL || *ppDstRow) { + if (ppDstRow == NULL || *ppDstRow == NULL) { terrno = TSDB_CODE_SDB_OBJ_NOT_THERE; taosWUnLockLatch(pLock); + sdbFreeRow(pRow); return -1; } SSdbRow *pDstRow = *ppDstRow; - pRow->status = pRaw->status; - taosHashRemove(hash, pRow->pObj, keySize); + pDstRow->status = pRaw->status; + taosHashRemove(hash, pDstRow->pObj, keySize); taosWUnLockLatch(pLock); - SdbDeleteFp deleteFp = tsSdb.deleteFps[pRow->sdb]; + SdbDeleteFp deleteFp = tsSdb.deleteFps[pDstRow->sdb]; if (deleteFp != NULL) { - (void)(*deleteFp)(pRow->pObj); + (void)(*deleteFp)(pDstRow->pObj); } - sdbRelease(pRow->pObj); + sdbRelease(pDstRow->pObj); + sdbFreeRow(pRow); return 0; } @@ -163,11 +167,7 @@ int32_t sdbWriteImp(SSdbRaw *pRaw) { break; } - if (code != 0) { - sdbFreeRow(pRow); - } - - return 0; + return code; } int32_t sdbWrite(SSdbRaw *pRaw) { -- GitLab