sync refactor
This commit is contained in:
parent
f7cd75544c
commit
90478b8742
|
@ -31,10 +31,10 @@ extern "C" {
|
||||||
#define TIMER_MAX_MS 0x7FFFFFFF
|
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||||
#define ENV_TICK_TIMER_MS 1000
|
#define ENV_TICK_TIMER_MS 1000
|
||||||
#define PING_TIMER_MS 1000
|
#define PING_TIMER_MS 1000
|
||||||
#define ELECT_TIMER_MS_MIN 150
|
#define ELECT_TIMER_MS_MIN 1500
|
||||||
#define ELECT_TIMER_MS_MAX 300
|
#define ELECT_TIMER_MS_MAX 3000
|
||||||
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
||||||
#define HEARTBEAT_TIMER_MS 30
|
#define HEARTBEAT_TIMER_MS 300
|
||||||
|
|
||||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,14 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm);
|
votesRespondReset(pSyncNode->pVotesRespond, pSyncNode->pRaftStore->currentTerm);
|
||||||
|
|
||||||
syncNodeVoteForSelf(pSyncNode);
|
syncNodeVoteForSelf(pSyncNode);
|
||||||
|
if (voteGrantedMajority(pSyncNode->pVotesGranted)) {
|
||||||
|
// only myself, to leader
|
||||||
|
assert(!pSyncNode->pVotesGranted->toLeader);
|
||||||
|
syncNodeCandidate2Leader(pSyncNode);
|
||||||
|
pSyncNode->pVotesGranted->toLeader = true;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ret = syncNodeRequestVotePeers(pSyncNode);
|
ret = syncNodeRequestVotePeers(pSyncNode);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
syncNodeResetElectTimer(pSyncNode);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
|
|
@ -57,7 +57,7 @@ int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg)
|
||||||
if (pMsg->voteGranted) {
|
if (pMsg->voteGranted) {
|
||||||
voteGrantedVote(ths->pVotesGranted, pMsg);
|
voteGrantedVote(ths->pVotesGranted, pMsg);
|
||||||
if (voteGrantedMajority(ths->pVotesGranted)) {
|
if (voteGrantedMajority(ths->pVotesGranted)) {
|
||||||
if (ths->pVotesGranted->toLeader) {
|
if (!ths->pVotesGranted->toLeader) {
|
||||||
syncNodeCandidate2Leader(ths);
|
syncNodeCandidate2Leader(ths);
|
||||||
ths->pVotesGranted->toLeader = true;
|
ths->pVotesGranted->toLeader = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue