diff --git a/source/dnode/mnode/impl/src/mndCompact.c b/source/dnode/mnode/impl/src/mndCompact.c index bce8c5901d..82824eb6e8 100644 --- a/source/dnode/mnode/impl/src/mndCompact.c +++ b/source/dnode/mnode/impl/src/mndCompact.c @@ -268,7 +268,11 @@ int32_t mndAddCompactToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompac sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + + if ((code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY)) != 0) { + sdbFreeRaw(pVgRaw); + TAOS_RETURN(code); + } rsp->compactId = pCompact->compactId; @@ -357,7 +361,10 @@ static void *mndBuildKillCompactReq(SMnode *pMnode, SVgObj *pVgroup, int32_t *pC pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSVKillCompactReq((char *)pReq + sizeof(SMsgHead), contLen, &req); + if ((contLen = tSerializeSVKillCompactReq((char *)pReq + sizeof(SMsgHead), contLen, &req)) < 0) { + terrno = contLen; + return NULL; + } *pContLen = contLen; return pReq; } @@ -421,7 +428,10 @@ static int32_t mndKillCompact(SMnode *pMnode, SRpcMsg *pReq, SCompactObj *pCompa mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) { + mndTransDrop(pTrans); + TAOS_RETURN(code); + } void *pIter = NULL; while (1) { @@ -614,7 +624,10 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) { pHead->contLen = htonl(contLen); pHead->vgId = htonl(pDetail->vgId); - (void)tSerializeSQueryCompactProgressReq((char *)pHead + sizeof(SMsgHead), contLen - sizeof(SMsgHead), &req); + if (tSerializeSQueryCompactProgressReq((char *)pHead + sizeof(SMsgHead), contLen - sizeof(SMsgHead), &req) <= 0) { + sdbRelease(pMnode->pSdb, pDetail); + continue; + } SRpcMsg rpcMsg = {.msgType = TDMT_VND_QUERY_COMPACT_PROGRESS, .contLen = contLen}; @@ -719,7 +732,12 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) { mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)) != 0) { + sdbCancelFetch(pMnode->pSdb, pIter); + sdbRelease(pMnode->pSdb, pDetail); + mndTransDrop(pTrans); + TAOS_RETURN(code); + } } sdbRelease(pMnode->pSdb, pDetail); @@ -782,7 +800,12 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) { mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); + if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) { + sdbCancelFetch(pMnode->pSdb, pIter); + sdbRelease(pMnode->pSdb, pDetail); + mndTransDrop(pTrans); + TAOS_RETURN(code); + } mInfo("compact:%d, add drop compactdetail action", pDetail->compactDetailId); } @@ -809,7 +832,11 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) { mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); + if ((code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED)) != 0) { + mError("compact:%d, trans:%d, failed to append commit log since %s", compactId, pTrans->id, terrstr()); + mndTransDrop(pTrans); + TAOS_RETURN(code); + } mInfo("compact:%d, add drop compact action", pCompact->compactId); } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index a432df60a5..b73d4b61a9 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -182,7 +182,7 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER); - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), NULL, _OVER); pRaw = NULL; TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); @@ -621,7 +621,10 @@ static int32_t mndUpdateDnodeObj(SMnode *pMnode, SDnodeObj *pDnode) { TAOS_RETURN(terrno); } - (void)tSerializeSDnodeInfoReq(pReq, contLen, &infoReq); + if ((contLen = tSerializeSDnodeInfoReq(pReq, contLen, &infoReq)) <= 0) { + code = contLen; + goto _exit; + } SRpcMsg rpcMsg = {.msgType = TDMT_MND_UPDATE_DNODE_INFO, .pCont = pReq, .contLen = contLen}; TAOS_CHECK_EXIT(tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg)); @@ -661,7 +664,7 @@ static int32_t mndProcessUpdateDnodeInfoReq(SRpcMsg *pReq) { mError("trans:%d, failed to append commit log since %s", pTrans->id, tstrerror(code)); TAOS_CHECK_EXIT(code); } - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY); + TAOS_CHECK_EXIT(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY)); pCommitRaw = NULL; if ((code = mndTransPrepare(pMnode, pTrans)) != 0) { @@ -874,8 +877,12 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { int32_t contLen = tSerializeSStatusRsp(NULL, 0, &statusRsp); void *pHead = rpcMallocCont(contLen); - (void)tSerializeSStatusRsp(pHead, contLen, &statusRsp); + contLen = tSerializeSStatusRsp(pHead, contLen, &statusRsp); taosArrayDestroy(statusRsp.pDnodeEps); + if (contLen < 0) { + code = contLen; + goto _OVER; + } pReq->info.rspLen = contLen; pReq->info.rsp = pHead; @@ -888,8 +895,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { _OVER: mndReleaseDnode(pMnode, pDnode); taosArrayDestroy(statusReq.pVloads); - (void)mndUpdClusterInfo(pReq); - return code; + return mndUpdClusterInfo(pReq); } static int32_t mndProcessNotifyReq(SRpcMsg *pReq) { @@ -955,7 +961,7 @@ static int32_t mndCreateDnode(SMnode *pMnode, SRpcMsg *pReq, SCreateDnodeReq *pC goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER); - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), NULL, _OVER); pRaw = NULL; TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); @@ -1010,7 +1016,10 @@ static int32_t mndProcessDnodeListReq(SRpcMsg *pReq) { goto _OVER; } - (void)tSerializeSDnodeListRsp(pRsp, rspLen, &rsp); + if ((rspLen = tSerializeSDnodeListRsp(pRsp, rspLen, &rsp)) <= 0) { + code = rspLen; + goto _OVER; + } pReq->info.rspLen = rspLen; pReq->info.rsp = pRsp; @@ -1151,7 +1160,10 @@ static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { goto _OVER; } - (void)tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp); + if ((rspLen = tSerializeSShowVariablesRsp(pRsp, rspLen, &rsp)) <= 0) { + code = rspLen; + goto _OVER; + } pReq->info.rspLen = rspLen; pReq->info.rsp = pRsp; @@ -1247,7 +1259,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendRedolog(pTrans, pRaw), NULL, _OVER); - (void)sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING); + TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING), NULL, _OVER); pRaw = NULL; pRaw = mndDnodeActionEncode(pDnode); @@ -1257,7 +1269,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pRaw), NULL, _OVER); - (void)sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED); + TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED), NULL, _OVER); pRaw = NULL; if (pMObj != NULL) { @@ -1450,7 +1462,10 @@ static int32_t mndSendCfgDnodeReq(SMnode *pMnode, int32_t dnodeId, SDCfgDnodeReq void *pBuf = rpcMallocCont(bufLen); if (pBuf != NULL) { - (void)tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq); + if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) { + code = bufLen; + return code; + } mInfo("dnode:%d, send config req to dnode, config:%s value:%s", dnodeId, pDcfgReq->config, pDcfgReq->value); SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, .pCont = pBuf, .contLen = bufLen}; code = tmsgSendReq(&epSet, &rpcMsg); @@ -1590,7 +1605,11 @@ static int32_t mndProcessCreateEncryptKeyReqImpl(SRpcMsg *pReq, int32_t dnodeId, void *pBuf = rpcMallocCont(bufLen); if (pBuf != NULL) { - (void)tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq); + if ((bufLen = tSerializeSDCfgDnodeReq(pBuf, bufLen, pDcfgReq)) <= 0) { + code = bufLen; + sdbRelease(pSdb, pDnode); + goto _exit; + } SRpcMsg rpcMsg = {.msgType = TDMT_DND_CREATE_ENCRYPT_KEY, .pCont = pBuf, .contLen = bufLen}; if (0 == tmsgSendReq(&epSet, &rpcMsg)) { (void)atomic_add_fetch_16(&pMnode->encryptMgmt.nEncrypt, 1); diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 9a617fb894..9e97aa674b 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -375,7 +375,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SRpcMsg *pReq, SFuncObj *pFunc) { goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendRedolog(pTrans, pRedoRaw), NULL, _OVER); - (void)sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING); + TAOS_CHECK_GOTO(sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING), NULL, _OVER); SSdbRaw *pUndoRaw = mndFuncActionEncode(pFunc); if (pUndoRaw == NULL) { @@ -384,7 +384,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SRpcMsg *pReq, SFuncObj *pFunc) { goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendUndolog(pTrans, pUndoRaw), NULL, _OVER); - (void)sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY); + TAOS_CHECK_GOTO(sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY), NULL, _OVER); SSdbRaw *pCommitRaw = mndFuncActionEncode(pFunc); if (pCommitRaw == NULL) { @@ -393,7 +393,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SRpcMsg *pReq, SFuncObj *pFunc) { goto _OVER; } TAOS_CHECK_GOTO(mndTransAppendCommitlog(pTrans, pCommitRaw), NULL, _OVER); - (void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); + TAOS_CHECK_GOTO(sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED), NULL, _OVER); TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); @@ -598,7 +598,10 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) { goto RETRIEVE_FUNC_OVER; } - (void)tSerializeSRetrieveFuncRsp(pRsp, contLen, &retrieveRsp); + if ((contLen = tSerializeSRetrieveFuncRsp(pRsp, contLen, &retrieveRsp)) <= 0) { + code = contLen; + goto RETRIEVE_FUNC_OVER; + } pReq->info.rsp = pRsp; pReq->info.rspLen = contLen;