hi, i am a deleloper from China, when i am reading code
"FastLeaderElection.java", i am a bit puzzled.
First one :
i am thiking if this code
return ((newEpoch > curEpoch) || ((newEpoch == curEpoch) && (newZxid >
curZxid)) || ((newZxid == curZxid) && (newId > curId)));
can be replaced with
return ((newEpoch > curEpoch) || ((newEpoch == curEpoch) && (newZxid >
curZxid)) || ((newZxid == curZxid) && (newId > proposedLeader)));
i think when replaced, it may be running more efficiently.
Second one:
And when looking at this following part, i am still puzzled
case LEADING:
/*
* Consider all notifications from the same epoch
* together.
*/
if (n.electionEpoch == logicalclock) {
recvset.put(n.sid, new Vote(n.leader, n.zxid, n.electionEpoch,
n.peerEpoch));
if (termPredicate(recvset, new Vote(n.leader, n.zxid, n.electionEpoch,
n.peerEpoch, n.state))
&& checkLeader(outofelection, n.leader, n.electionEpoch)) {
self.setPeerState((n.leader == self.getId()) ? ServerState.LEADING
: learningState());
Vote endVote = new Vote(n.leader, n.zxid, n.peerEpoch);
leaveInstance(endVote);
return endVote;
}
}
i think outofelection have nothing to do in this part, is that so?
and can I replace it like this?
checkLeader(recvset, n.leader, n.electionEpoch))
i hope to hear from you! Thank you!^_^
2012-03-08
chen-hongqin