chore: code optimization

This commit is contained in:
kailixu 2023-05-19 16:06:20 +08:00
parent c770a5c306
commit 8571e6f6c5
1 changed files with 20 additions and 9 deletions

View File

@ -649,18 +649,19 @@ _OVER:
} }
static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq, int8_t action) { static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfgReq, int8_t action) {
SSdbRaw *pRaw = NULL; SSdbRaw *pRaw = NULL;
STrans *pTrans = NULL; STrans *pTrans = NULL;
SDnodeObj *pDnode = NULL;
bool cfgAll = pCfgReq->dnodeId == -1;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
SDnodeObj *pDnode = NULL; if (cfgAll) {
pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
if (pIter == NULL) break; if (pIter == NULL) break;
} else if(!(pDnode = mndAcquireDnode(pMnode, pCfgReq->dnodeId)) {
if (pDnode->id != pCfgReq->dnodeId && pCfgReq->dnodeId != -1) { goto _OVER;
continue;
} }
if (!pTrans) { if (!pTrans) {
@ -687,7 +688,12 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
mInfo("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle, mInfo("dnode:%d, config dnode, cfg:%d, app:%p config:%s value:%s", pDnode->id, pCfgReq->dnodeId, pReq->info.ahandle,
pCfgReq->config, pCfgReq->value); pCfgReq->config, pCfgReq->value);
sdbRelease(pSdb, pDnode); if (cfgAll) {
sdbRelease(pSdb, pDnode);
pDnode = NULL;
} else {
break;
}
} }
if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; if (pTrans && mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
@ -695,6 +701,11 @@ static int32_t mndConfigDnode(SMnode *pMnode, SRpcMsg *pReq, SMCfgDnodeReq *pCfg
terrno = 0; terrno = 0;
_OVER: _OVER:
if (cfgAll) {
sdbRelease(pSdb, pDnode);
} else {
mndReleaseDnode(pMnode, pDnode);
}
mndTransDrop(pTrans); mndTransDrop(pTrans);
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
return terrno; return terrno;