enh: set vgroup dropping state before split

This commit is contained in:
Shengliang Guan 2023-01-30 10:08:26 +08:00
parent 316e563ff2
commit f36713a587
1 changed files with 26 additions and 30 deletions

View File

@ -1763,9 +1763,10 @@ static int32_t mndAddAdjustVnodeHashRangeAction(SMnode *pMnode, STrans *pTrans,
} }
static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup) { static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup) {
int32_t code = -1; int32_t code = -1;
STrans *pTrans = NULL; STrans *pTrans = NULL;
SArray *pArray = mndBuildDnodesArray(pMnode, 0); SSdbRaw *pRaw = NULL;
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "split-vgroup"); pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "split-vgroup");
if (pTrans == NULL) goto _OVER; if (pTrans == NULL) goto _OVER;
@ -1802,6 +1803,12 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj
mInfo("vgId:%d, vnode:%d dnode:%d", newVg1.vgId, i, newVg1.vnodeGid[i].dnodeId); mInfo("vgId:%d, vnode:%d dnode:%d", newVg1.vgId, i, newVg1.vnodeGid[i].dnodeId);
} }
pRaw = mndVgroupActionEncode(pVgroup);
if (pRaw == NULL) goto _OVER;
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
(void)sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING);
pRaw = NULL;
SVgObj newVg2 = {0}; SVgObj newVg2 = {0};
memcpy(&newVg2, &newVg1, sizeof(SVgObj)); memcpy(&newVg2, &newVg1, sizeof(SVgObj));
newVg1.replica = 1; newVg1.replica = 1;
@ -1829,35 +1836,23 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER; if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER;
} }
{ pRaw = mndVgroupActionEncode(&newVg1);
SSdbRaw *pRaw = mndVgroupActionEncode(&newVg1); if (pRaw == NULL) goto _OVER;
if (pRaw == NULL) return -1; if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
sdbFreeRaw(pRaw); pRaw = NULL;
return -1;
}
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
}
{ pRaw = mndVgroupActionEncode(&newVg2);
SSdbRaw *pRaw = mndVgroupActionEncode(&newVg2); if (pRaw == NULL) goto _OVER;
if (pRaw == NULL) return -1; if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
sdbFreeRaw(pRaw); pRaw = NULL;
return -1;
}
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
}
{ pRaw = mndVgroupActionEncode(pVgroup);
SSdbRaw *pRaw = mndVgroupActionEncode(pVgroup); if (pRaw == NULL) goto _OVER;
if (pRaw == NULL) return -1; if (mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { (void)sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
sdbFreeRaw(pRaw); pRaw = NULL;
return -1;
}
(void)sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
}
mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg1.vgId, mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg1.vgId,
newVg1.replica, newVg1.hashBegin, newVg1.hashEnd, newVg1.vnodeGid[0].dnodeId); newVg1.replica, newVg1.hashBegin, newVg1.hashEnd, newVg1.vnodeGid[0].dnodeId);
@ -1876,6 +1871,7 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj
_OVER: _OVER:
taosArrayDestroy(pArray); taosArrayDestroy(pArray);
mndTransDrop(pTrans); mndTransDrop(pTrans);
sdbFreeRaw(pRaw);
return code; return code;
} }