From 5caa366464402ac0cb8c19e643a105924dffcb42 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 25 Jul 2024 12:15:00 +0800 Subject: [PATCH] update sync vote & reply --- source/libs/sync/src/syncRequestVote.c | 11 ++++++----- source/libs/sync/src/syncRequestVoteReply.c | 14 +++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index 77e5498127..0e50cca94c 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -20,7 +20,6 @@ #include "syncRaftStore.h" #include "syncUtil.h" #include "syncVoteMgr.h" -#include "syncUtil.h" // TLA+ Spec // HandleRequestVoteRequest(i, j, m) == @@ -95,7 +94,8 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &pMsg->srcId)) { syncLogRecvRequestVote(ths, pMsg, -1, "not in my config"); - return -1; + + TAOS_RETURN(TSDB_CODE_FAILED); } bool logOK = syncNodeOnRequestVoteLogOK(ths, pMsg); @@ -122,8 +122,8 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) { // send msg SRpcMsg rpcMsg = {0}; - ret = syncBuildRequestVoteReply(&rpcMsg, ths->vgId); - ASSERT(ret == 0); + + TAOS_CHECK_RETURN(syncBuildRequestVoteReply(&rpcMsg, ths->vgId)); SyncRequestVoteReply* pReply = rpcMsg.pCont; pReply->srcId = ths->myRaftId; @@ -138,5 +138,6 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) { syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); if (resetElect) syncNodeResetElectTimer(ths); - return 0; + + TAOS_RETURN(TSDB_CODE_SUCCESS); } diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index 25c9f813a6..10d9a6c96b 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -45,19 +45,22 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) { // if already drop replica, do not process if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) { syncLogRecvRequestVoteReply(ths, pMsg, "not in my config"); - return -1; + + TAOS_RETURN(TSDB_CODE_FAILED); } SyncTerm currentTerm = raftStoreGetTerm(ths); // drop stale response if (pMsg->term < currentTerm) { syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response"); - return -1; + + TAOS_RETURN(TSDB_CODE_FAILED); } if (pMsg->term > currentTerm) { syncLogRecvRequestVoteReply(ths, pMsg, "error term"); syncNodeStepDown(ths, pMsg->term); - return -1; + + TAOS_RETURN(TSDB_CODE_FAILED); } syncLogRecvRequestVoteReply(ths, pMsg, ""); @@ -69,7 +72,8 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) { if (ths->pVotesRespond->term != pMsg->term) { sNError(ths, "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "", ths->pVotesRespond->term, pMsg->term); - return -1; + + TAOS_RETURN(TSDB_CODE_FAILED); } votesRespondAdd(ths->pVotesRespond, pMsg); @@ -93,5 +97,5 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) { } } - return 0; + TAOS_RETURN(TSDB_CODE_SUCCESS); }