提交 06d94f6c 编写于 作者: D dmchen

to enterprise

上级 565c930f
......@@ -596,112 +596,6 @@ _OVER:
return code;
}
static int32_t mndRestoreDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, int8_t restoreType) {
int32_t code = -1;
SSdbRaw *pRaw = NULL;
STrans *pTrans = NULL;
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "restore-dnode");
if (pTrans == NULL) goto _OVER;
mndTransSetSerial(pTrans);
mInfo("trans:%d, used to restore dnode:%s", pTrans->id, pDnode->ep);
if (mndTrancCheckConflict(pMnode, pTrans) != 0) goto _OVER;
if(restoreType == RESTORE_TYPE__ALL || restoreType == RESTORE_TYPE__MNODE)
{
int32_t totalMnodes = sdbGetSize(pMnode->pSdb, SDB_MNODE);
if (totalMnodes == 2) {
mError("cant't restore mnode, since a mnode on it and replica is 2");
terrno = TSDB_CODE_MNODE_ONLY_TWO_MNODE;
return -1;
}
SMnodeObj *mnodeObj = mndAcquireMnode(pMnode, pDnode->id);
if(mnodeObj == NULL){
mError("trans:%d, no mnode exist on dnode:%s", pTrans->id, pDnode->ep);
}
else
{
SMnodeObj newMnodeObj = {0};
newMnodeObj.id = pDnode->id;
newMnodeObj.createdTime = taosGetTimestampMs();
newMnodeObj.updateTime = newMnodeObj.createdTime;
newMnodeObj.role = TAOS_SYNC_ROLE_LEARNER;
newMnodeObj.lastIndex = pMnode->applied;
if (mndSetRestoreCreateMnodeRedoActions(pMnode, pTrans, pDnode, &newMnodeObj) != 0) goto _OVER;
SMnodeObj mnodeLeaderObj = {0};
mnodeLeaderObj.id = pDnode->id;
mnodeLeaderObj.createdTime = taosGetTimestampMs();
mnodeLeaderObj.updateTime = mnodeLeaderObj.createdTime;
mnodeLeaderObj.role = TAOS_SYNC_ROLE_VOTER;
mnodeLeaderObj.lastIndex = pMnode->applied + 1;
if (mndSetRestoreAlterMnodeTypeRedoActions(pMnode, pTrans, pDnode, &mnodeLeaderObj) != 0) goto _OVER;
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeLeaderObj) != 0) goto _OVER;
mndReleaseMnode(pMnode, mnodeObj);
}
}
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
if(restoreType == RESTORE_TYPE__ALL || restoreType == RESTORE_TYPE__VNODE){
while (1) {
SVgObj *pVgroup = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break;
if (mndVgroupInDnode(pVgroup, pDnode->id)) {
SDbObj *db = mndAcquireDb(pMnode, pVgroup->dbName);
if(db == NULL){
sdbCancelFetch(pSdb, pIter);
sdbRelease(pSdb, pVgroup);
goto _OVER;
}
if (mndBuildRestoreAlterVgroupAction(pMnode, pTrans, db, pVgroup, pDnode) != 0) {
sdbCancelFetch(pSdb, pIter);
mndReleaseDb(pMnode, db);
sdbRelease(pSdb, pVgroup);
goto _OVER;
}
mndReleaseDb(pMnode, db);
}
sdbRelease(pSdb, pVgroup);
}
}
if(restoreType == RESTORE_TYPE__ALL || restoreType == RESTORE_TYPE__QNODE){
pIter = NULL;
while (1) {
SQnodeObj *pQnode = NULL;
pIter = sdbFetch(pSdb, SDB_QNODE, pIter, (void **)&pQnode);
if (pIter == NULL) break;
if (mndQnodeInDnode(pQnode, pDnode->id)) {
if (mndSetCreateQnodeCommitLogs(pTrans, pQnode) != 0) goto _OVER;
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, pQnode) != 0) goto _OVER;
}
sdbRelease(pSdb, pQnode);
}
}
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
code = 0;
_OVER:
mndTransDrop(pTrans);
sdbFreeRaw(pRaw);
return code;
}
static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) {
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册