Move rebuild config sdb to after restored.

This commit is contained in:
xiao-77 2024-12-17 11:22:38 +08:00
parent 6eb183a032
commit 474113da4e
7 changed files with 52 additions and 56 deletions

View File

@ -29,7 +29,7 @@ static int32_t mndCfgActionInsert(SSdb *pSdb, SConfigObj *obj);
static int32_t mndCfgActionDelete(SSdb *pSdb, SConfigObj *obj); static int32_t mndCfgActionDelete(SSdb *pSdb, SConfigObj *obj);
static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *oldItem, SConfigObj *newObj); static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *oldItem, SConfigObj *newObj);
static int32_t mndCfgActionDeploy(SMnode *pMnode); static int32_t mndCfgActionDeploy(SMnode *pMnode);
static int32_t mndCfgActionPrepare(SMnode *pMnode); static int32_t mndCfgActionAfterRestored(SMnode *pMnode);
static int32_t mndProcessConfigReq(SRpcMsg *pReq); static int32_t mndProcessConfigReq(SRpcMsg *pReq);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -53,7 +53,7 @@ int32_t mndInitConfig(SMnode *pMnode) {
.updateFp = (SdbUpdateFp)mndCfgActionUpdate, .updateFp = (SdbUpdateFp)mndCfgActionUpdate,
.deleteFp = (SdbDeleteFp)mndCfgActionDelete, .deleteFp = (SdbDeleteFp)mndCfgActionDelete,
.deployFp = (SdbDeployFp)mndCfgActionDeploy, .deployFp = (SdbDeployFp)mndCfgActionDeploy,
.prepareFp = (SdbPrepareFp)mndCfgActionPrepare}; .afterRestoredFp = (SdbAfterRestoredFp)mndCfgActionAfterRestored};
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG, mndProcessConfigReq); mndSetMsgHandle(pMnode, TDMT_MND_CONFIG, mndProcessConfigReq);
mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq); mndSetMsgHandle(pMnode, TDMT_MND_CONFIG_DNODE, mndProcessConfigDnodeReq);
@ -214,7 +214,7 @@ static int32_t mndCfgActionUpdate(SSdb *pSdb, SConfigObj *pOld, SConfigObj *pNew
static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); } static int32_t mndCfgActionDeploy(SMnode *pMnode) { return mndInitWriteCfg(pMnode); }
static int32_t mndCfgActionPrepare(SMnode *pMnode) { return mndTryRebuildCfg(pMnode); } static int32_t mndCfgActionAfterRestored(SMnode *pMnode) { return mndTryRebuildCfg(pMnode); }
static int32_t mndProcessConfigReq(SRpcMsg *pReq) { static int32_t mndProcessConfigReq(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node; SMnode *pMnode = pReq->info.node;

View File

@ -797,14 +797,7 @@ int32_t mndStart(SMnode *pMnode) {
return -1; return -1;
} }
mndSetRestored(pMnode, true); mndSetRestored(pMnode, true);
} else {
if (sdbPrepare(pMnode->pSdb) != 0) {
mError("failed to prepare sdb while start mnode");
return -1;
} }
mndSetRestored(pMnode, true);
}
grantReset(pMnode, TSDB_GRANT_ALL, 0); grantReset(pMnode, TSDB_GRANT_ALL, 0);
return mndInitTimer(pMnode); return mndInitTimer(pMnode);

View File

@ -14,11 +14,11 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndSync.h"
#include "mndCluster.h" #include "mndCluster.h"
#include "mndStream.h"
#include "mndSync.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "mndUser.h" #include "mndUser.h"
#include "mndStream.h"
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
if (pMsg == NULL || pMsg->pCont == NULL) { if (pMsg == NULL || pMsg->pCont == NULL) {
@ -309,6 +309,9 @@ void mndRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) {
} else { } else {
mInfo("vgId:1, sync restore finished, repeat call"); mInfo("vgId:1, sync restore finished, repeat call");
} }
if (sdbAfterRestored(pMnode->pSdb) != 0) {
mError("failed to prepare sdb while start mnode");
}
} else { } else {
mInfo("vgId:1, sync restore finished"); mInfo("vgId:1, sync restore finished");
} }
@ -546,7 +549,7 @@ void mndSyncCheckTimeout(SMnode *pMnode) {
// pMgmt->transSeq = 0; // pMgmt->transSeq = 0;
// terrno = TSDB_CODE_SYN_TIMEOUT; // terrno = TSDB_CODE_SYN_TIMEOUT;
// pMgmt->errCode = TSDB_CODE_SYN_TIMEOUT; // pMgmt->errCode = TSDB_CODE_SYN_TIMEOUT;
//if (tsem_post(&pMgmt->syncSem) < 0) { // if (tsem_post(&pMgmt->syncSem) < 0) {
// mError("failed to post sem"); // mError("failed to post sem");
//} //}
} else { } else {

View File

@ -117,7 +117,7 @@ typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj);
typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj);
typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc); typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc);
typedef int32_t (*SdbDeployFp)(SMnode *pMnode); typedef int32_t (*SdbDeployFp)(SMnode *pMnode);
typedef int32_t (*SdbPrepareFp)(SMnode *pMnode); typedef int32_t (*SdbAfterRestoredFp)(SMnode *pMnode);
typedef int32_t (*SdbValidateFp)(SMnode *pMnode, void *pTrans, SSdbRaw *pRaw); typedef int32_t (*SdbValidateFp)(SMnode *pMnode, void *pTrans, SSdbRaw *pRaw);
typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw);
typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); typedef SSdbRaw *(*SdbEncodeFp)(void *pObj);
@ -208,7 +208,7 @@ typedef struct SSdb {
SdbUpdateFp updateFps[SDB_MAX]; SdbUpdateFp updateFps[SDB_MAX];
SdbDeleteFp deleteFps[SDB_MAX]; SdbDeleteFp deleteFps[SDB_MAX];
SdbDeployFp deployFps[SDB_MAX]; SdbDeployFp deployFps[SDB_MAX];
SdbPrepareFp prepareFps[SDB_MAX]; SdbAfterRestoredFp afterRestoredFps[SDB_MAX];
SdbEncodeFp encodeFps[SDB_MAX]; SdbEncodeFp encodeFps[SDB_MAX];
SdbDecodeFp decodeFps[SDB_MAX]; SdbDecodeFp decodeFps[SDB_MAX];
SdbValidateFp validateFps[SDB_MAX]; SdbValidateFp validateFps[SDB_MAX];
@ -225,7 +225,7 @@ typedef struct {
ESdbType sdbType; ESdbType sdbType;
EKeyType keyType; EKeyType keyType;
SdbDeployFp deployFp; SdbDeployFp deployFp;
SdbPrepareFp prepareFp; SdbAfterRestoredFp afterRestoredFp;
SdbEncodeFp encodeFp; SdbEncodeFp encodeFp;
SdbDecodeFp decodeFp; SdbDecodeFp decodeFp;
SdbInsertFp insertFp; SdbInsertFp insertFp;
@ -279,7 +279,7 @@ int32_t sdbDeploy(SSdb *pSdb);
* @param pSdb The sdb object. * @param pSdb The sdb object.
* @return int32_t 0 for success, -1 for failure. * @return int32_t 0 for success, -1 for failure.
*/ */
int32_t sdbPrepare(SSdb *pSdb); int32_t sdbAfterRestored(SSdb *pSdb);
/** /**
* @brief Load sdb from file. * @brief Load sdb from file.

View File

@ -127,7 +127,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
pSdb->deployFps[sdbType] = table.deployFp; pSdb->deployFps[sdbType] = table.deployFp;
pSdb->encodeFps[sdbType] = table.encodeFp; pSdb->encodeFps[sdbType] = table.encodeFp;
pSdb->decodeFps[sdbType] = table.decodeFp; pSdb->decodeFps[sdbType] = table.decodeFp;
pSdb->prepareFps[sdbType] = table.prepareFp; pSdb->afterRestoredFps[sdbType] = table.afterRestoredFp;
pSdb->validateFps[sdbType] = table.validateFp; pSdb->validateFps[sdbType] = table.validateFp;
int32_t hashType = 0; int32_t hashType = 0;

View File

@ -48,12 +48,12 @@ static int32_t sdbDeployData(SSdb *pSdb) {
return 0; return 0;
} }
static int32_t sdbPrepareData(SSdb *pSdb) { static int32_t sdbAfterRestoredData(SSdb *pSdb) {
int32_t code = 0; int32_t code = 0;
mInfo("start to prepare sdb"); mInfo("start to prepare sdb");
for (int32_t i = SDB_MAX - 1; i >= 0; --i) { for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
SdbPrepareFp fp = pSdb->prepareFps[i]; SdbAfterRestoredFp fp = pSdb->afterRestoredFps[i];
if (fp == NULL) continue; if (fp == NULL) continue;
mInfo("start to prepare sdb:%s", sdbTableName(i)); mInfo("start to prepare sdb:%s", sdbTableName(i));
@ -666,9 +666,9 @@ int32_t sdbDeploy(SSdb *pSdb) {
return 0; return 0;
} }
int32_t sdbPrepare(SSdb *pSdb) { int32_t sdbAfterRestored(SSdb *pSdb) {
int32_t code = 0; int32_t code = 0;
code = sdbPrepareData(pSdb); code = sdbAfterRestoredData(pSdb);
if (code != 0) { if (code != 0) {
TAOS_RETURN(code); TAOS_RETURN(code);
} }