private boolean termPredicate(Map<InetSocketAddress, Vote> votes, long l, long zxid) { Collection<Vote> votesCast = votes.values(); int count = 0; /* * First make the views consistent. Sometimes peers will have different * zxids for a server depending on timing. */ for (Vote v : votesCast) { if ((v.getId() == l) && (v.getZxid() == zxid)) count++; } if (count > (self.getVotingView().size() / 2)) return true; else return false; }
private void leaveInstance(Vote v) { if(LOG.isDebugEnabled()){ LOG.debug("About to leave FLE instance: leader={}, zxid=0x{}, my id={}, my state={}", v.getId(), Long.toHexString(v.getZxid()), self.getId(), self.getPeerState()); } recvqueue.clear(); }
private boolean termPredicate(HashMap<InetSocketAddress, Vote> votes, long l, long zxid) { Collection<Vote> votesCast = votes.values(); int count = 0; /* * First make the views consistent. Sometimes peers will have different * zxids for a server depending on timing. */ for (Vote v : votesCast) { if ((v.getId() == l) && (v.getZxid() == zxid)) count++; } if (count > (self.getVotingView().size() / 2)) return true; else return false; }
private void leaveInstance(Vote v) { if(LOG.isDebugEnabled()){ LOG.debug("About to leave FLE instance: leader=" + v.getId() + ", zxid=0x" + Long.toHexString(v.getZxid()) + ", my id=" + self.getId() + ", my state=" + self.getPeerState()); } recvqueue.clear(); }
case LOOKING: responseBuffer.putLong(current.getId()); responseBuffer.putLong(current.getZxid()); break; case LEADING:
validVotes.put(e.getKey(), v); Long val = maxZxids.get(v.getId()); if (val == null || val < v.getZxid()) { maxZxids.put(v.getId(), v.getZxid()); final Vote v = e.getValue(); Long zxid = maxZxids.get(v.getId()); if (v.getZxid() < zxid) { if (v.getId() == result.vote.getId()) { result.count++; } else if (v.getZxid() > result.vote.getZxid() || (v.getZxid() == result.vote.getZxid() && v.getId() > result.vote.getId())) { result.vote = v; result.count = 1;
case LOOKING: responseBuffer.putLong(current.getId()); responseBuffer.putLong(current.getZxid()); break; case LEADING:
ToSend notmsg = new ToSend(ToSend.mType.notification, current.getId(), current.getZxid(), logicalclock.get(), self.getPeerState(), ToSend notmsg = new ToSend(ToSend.mType.notification, v.getId(), v.getZxid(), logicalclock.get(), self.getPeerState(), self.getId(), response.sid, Long.toHexString(current.getZxid()), current.getId(), Long.toHexString(self.getQuorumVerifier().getVersion())); ToSend.mType.notification, current.getId(), current.getZxid(), current.getElectionEpoch(), self.getPeerState(),
ToSend notmsg = new ToSend(ToSend.mType.notification, current.getId(), current.getZxid(), logicalclock.get(), self.getPeerState(), ToSend notmsg = new ToSend(ToSend.mType.notification, v.getId(), v.getZxid(), logicalclock.get(), self.getPeerState(), self.getId() + " recipient=" + response.sid + " zxid=0x" + Long.toHexString(current.getZxid()) + " leader=" + current.getId()); ToSend.mType.notification, current.getId(), current.getZxid(), current.getElectionEpoch(), self.getPeerState(), ToSend.mType.notification, bcVote.getId(), bcVote.getZxid(), bcVote.getElectionEpoch(), self.getPeerState(),
if (currentVote != null) { setCurrentVote(new Vote(currentVote.getId(), currentVote.getZxid(), currentVote.getElectionEpoch(), newEpoch,
/** * Updates leader election info to avoid inconsistencies when * a new server tries to join the ensemble. * See ZOOKEEPER-1732 for more info. */ protected void updateElectionVote(long newEpoch) { Vote currentVote = getCurrentVote(); setBCVote(currentVote); if (currentVote != null) { setCurrentVote(new Vote(currentVote.getId(), currentVote.getZxid(), currentVote.getElectionEpoch(), newEpoch, currentVote.getState())); } }
@Test public void testOutofElection() { HashMap<Long,Vote> outofelection = new HashMap<Long,Vote>(); outofelection.put(1L, new Vote(0x0, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x17, ServerState.FOLLOWING)); outofelection.put(2L, new Vote(0x0, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x17, ServerState.FOLLOWING)); outofelection.put(4L, new Vote(0x1, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x18, ServerState.FOLLOWING)); Vote vote = new Vote(0x1, 5, ZxidUtils.makeZxid(15, 0), 0xa, 0x18, ServerState.LEADING); outofelection.put(5L, vote); Notification n = new Notification(); n.version = vote.getVersion(); n.leader = vote.getId(); n.zxid = vote.getZxid(); n.electionEpoch = vote.getElectionEpoch(); n.state = vote.getState(); n.peerEpoch = vote.getPeerEpoch(); n.sid = 5L; // Set the logical clock to 1 on fle instance of server 3. fle.logicalclock.set(0x1); Assert.assertTrue("Quorum check failed", fle.getVoteTracker(outofelection, new Vote(n.version, n.leader, n.zxid, n.electionEpoch, n.peerEpoch, n.state)).hasAllQuorums()); Assert.assertTrue("Leader check failed", fle.checkLeader(outofelection, n.leader, n.electionEpoch)); } }
long zxid = peer.getCurrentVote().getZxid(); long electionEpoch = peer.getCurrentVote().getElectionEpoch(); ServerState state = peer.getCurrentVote().getState();
case LOOKING: responseBuffer.putLong(current.getId()); responseBuffer.putLong(current.getZxid()); break; case LEADING:
/** * Updates leader election info to avoid inconsistencies when * a new server tries to join the ensemble. * See ZOOKEEPER-1732 for more info. */ protected void updateElectionVote(long newEpoch) { Vote currentVote = getCurrentVote(); setBCVote(currentVote); if (currentVote != null) { setCurrentVote(new Vote(currentVote.getId(), currentVote.getZxid(), currentVote.getElectionEpoch(), newEpoch, currentVote.getState())); } }