diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 1eed353f33150c1ca7790d2ec8d082d8d0ac8eea..2bf678fa487a86aa666f39e25f6c9cef76cb4bba 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -146,6 +146,7 @@ int32_t syncGetVgId(int64_t rid); int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak); bool syncEnvIsStart(); const char* syncStr(ESyncState state); +bool syncIsRestoreFinish(int64_t rid); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index 45dec1153f16ae96b5012f68a743024bdaf1239d..7249edc7066eb29f2e930d972bede712f65515b8 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -111,9 +111,16 @@ int32_t mmPutRpcMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t mmPutRpcMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { - if (mmAcquire(pMgmt) != 0) return -1; - int32_t code = mmPutRpcMsgToWorker(&pMgmt->syncWorker, pMsg); - mmRelease(pMgmt); + int32_t code = -1; + if (mmAcquire(pMgmt) == 0) { + code = mmPutRpcMsgToWorker(&pMgmt->syncWorker, pMsg); + mmRelease(pMgmt); + } + + if (code != 0) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + } return code; } diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index e3f7b40526328cd13ac69655980cb674980f2443..b77a2c20a6b60deaaaa77501c4a11d252ae2396d 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -17,13 +17,7 @@ #include "mndSync.h" #include "mndTrans.h" -int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { - int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); - if (code != 0) { - rpcFreeCont(pMsg->pCont); - } - return code; -} +int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { return tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); } int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { return tmsgSendReq(pEpSet, pMsg); } @@ -33,7 +27,7 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM SSyncMgmt *pMgmt = &pMnode->syncMgmt; SSdbRaw *pRaw = pMsg->pCont; - mTrace("ver:%" PRId64 ", apply raw:%p to sdb, role:%s", cbMeta.index, pRaw, syncStr(cbMeta.state)); + mTrace("raw:%p, apply to sdb, ver:%" PRId64 " role:%s", pRaw, cbMeta.index, syncStr(cbMeta.state)); sdbWriteWithoutFree(pSdb, pRaw); sdbSetApplyIndex(pSdb, cbMeta.index); sdbSetApplyTerm(pSdb, cbMeta.term); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 821ed364e840f268f1c0da76f95536a6b2342676..a233603adffd229fb6b0b8891c22305358ef26bc 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -157,6 +157,18 @@ ESyncState syncGetMyRole(int64_t rid) { return state; } +bool syncIsRestoreFinish(int64_t rid) { + SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + if (pSyncNode == NULL) { + return false; + } + assert(rid == pSyncNode->rid); + bool b = pSyncNode->restoreFinish; + + taosReleaseRef(tsNodeRefId, pSyncNode->rid); + return b; +} + const char* syncGetMyRoleStr(int64_t rid) { const char* s = syncUtilState2String(syncGetMyRole(rid)); return s; @@ -308,8 +320,10 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { int32_t ret = TAOS_SYNC_PROPOSE_SUCCESS; SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); if (pSyncNode == NULL) { + rpcFreeCont(pMsg->pCont); return TAOS_SYNC_PROPOSE_OTHER_ERROR; } + assert(rid == pSyncNode->rid); if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {