MCPcopy Create free account
hub / github.com/e2wugui/zeze / processRequestVote

Method processRequestVote

ZezeJava/ZezeJava/src/main/java/Zeze/Raft/Raft.java:661–691  ·  view source on GitHub ↗
(RequestVote r)

Source from the content-addressed store, hash-verified

659 }
660
661 @SuppressWarnings("SameReturnValue")
662 private long processRequestVote(RequestVote r) throws Exception {
663 lock();
664 try {
665 // 不管任何状态重置下一次时间,使得每个node从大概一个时刻开始。
666 nextVoteTime = System.currentTimeMillis() + raftConfig.getElectionTimeout();
667
668 if (logSequence.trySetTerm(r.Argument.getTerm()) == LogSequence.SetTermResult.Newer)
669 convertStateTo(RaftState.Follower); // new term found.
670 // else continue process
671
672 // RequestVote RPC
673 // Receiver implementation:
674 // 1.Reply false if term < currentTerm(§5.1)
675 // 2.If votedFor is null or candidateId, and candidate's log is at
676 // least as up - to - date as receiver's log, grant vote(§5.2, §5.4)
677
678 r.Result.setTerm(logSequence.getTerm());
679 r.Result.setVoteGranted(r.Argument.getTerm() == logSequence.getTerm() &&
680 logSequence.canVoteFor(r.Argument.getCandidateId()) && isLastLogUpToDate(r.Argument));
681
682 if (r.Result.getVoteGranted())
683 logSequence.setVoteFor(r.Argument.getCandidateId());
684 logger.info("{}: VoteFor={} Rpc={}", getName(), logSequence.getVoteFor(), r);
685 r.SendResultCode(0);
686
687 return Procedure.Success;
688 } finally {
689 unlock();
690 }
691 }
692
693 @SuppressWarnings("SameReturnValue")
694 private static long processLeaderIs(LeaderIs r) {

Callers

nothing calls this directly

Calls 15

lockMethod · 0.95
convertStateToMethod · 0.95
isLastLogUpToDateMethod · 0.95
getNameMethod · 0.95
unlockMethod · 0.95
trySetTermMethod · 0.80
setVoteGrantedMethod · 0.80
canVoteForMethod · 0.80
getCandidateIdMethod · 0.80
getVoteGrantedMethod · 0.80
setVoteForMethod · 0.80
getVoteForMethod · 0.80

Tested by

no test coverage detected