private boolean updateVote(long designatedLeader, long zxid){ Vote currentVote = getCurrentVote(); if (currentVote!=null && designatedLeader != currentVote.getId()) { setCurrentVote(new Vote(designatedLeader, zxid)); reconfigFlagSet(); LOG.warn("Suggested leader: " + designatedLeader); return true; } return false; }
self.setCurrentVote(new Vote(self.getId(), self.getLastLoggedZxid())); self.setCurrentVote(new Vote(self.getId(), self.getLastLoggedZxid())); } else { if (result.winner.getId() >= 0) { self.setCurrentVote(result.vote); self.setCurrentVote(result.winner); s.close(); Vote current = self.getCurrentVote();
public void run() { try { Vote v = null; peer.setPeerState(ServerState.LOOKING); LOG.info("Going to call leader election: {}", i); v = peer.getElectionAlg().lookForLeader(); if (v == null) { Assert.fail("Thread " + i + " got a null vote"); } /* * A real zookeeper would take care of setting the current vote. Here * we do it manually. */ peer.setCurrentVote(v); LOG.info("Finished election: {}, {}", i, v.getId()); Assert.assertTrue("State is not leading.", peer.getPeerState() == ServerState.LEADING); } catch (Exception e) { e.printStackTrace(); } LOG.info("Joining"); } }
Vote currentVote = getCurrentVote(); if (currentVote != null) { setCurrentVote(new Vote(currentVote.getId(), currentVote.getZxid(), currentVote.getElectionEpoch(),
@Test public void testIsNotLeaderBecauseNoVote() throws Exception { long localPeerId = 7; QuorumPeer peer = new QuorumPeer(); peer.setId(localPeerId); peer.setCurrentVote(null); assertFalse(peer.isLeader(localPeerId)); }
/** * 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())); } }
startLeaderElection(); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception", e); startLeaderElection(); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception", e);
@Test public void testLocalPeerIsLeader() throws Exception { long localPeerId = 7; QuorumPeer peer = new QuorumPeer(); peer.setId(localPeerId); Vote voteLocalPeerIsLeader = new Vote(localPeerId, 0); peer.setCurrentVote(voteLocalPeerIsLeader); assertTrue(peer.isLeader(localPeerId)); }
@Test public void testLocalPeerIsNotLeader() throws Exception { long localPeerId = 7; long otherPeerId = 17; QuorumPeer peer = new QuorumPeer(); peer.setId(localPeerId); Vote voteLocalPeerIsNotLeader = new Vote(otherPeerId, 0); peer.setCurrentVote(voteLocalPeerIsNotLeader); assertFalse(peer.isLeader(localPeerId)); }
roZkMgr.start(); setBCVote(null); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception",e); try { setBCVote(null); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception", e);
long peerEpoch = peer.getCurrentVote().getPeerEpoch(); Vote newVote = new Vote(leaderSid, zxid+100, electionEpoch+100, peerEpoch, state); peer.setCurrentVote(newVote);
self.setCurrentVote(new Vote(self.getId(), self.getLastLoggedZxid())); self.setCurrentVote(new Vote(self.getId(), self.getLastLoggedZxid())); } else { if (result.winner.id >= 0) { self.setCurrentVote(result.vote); self.setCurrentVote(result.winner); s.close(); Vote current = self.getCurrentVote();
/** * 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())); } }
roZkMgr.start(); setBCVote(null); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception",e); try { setBCVote(null); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception", e);
try { LOG.info("LOOKING"); setCurrentVote(makeLEStrategy().lookForLeader()); } catch (Exception e) { LOG.warn("Unexpected exception",e);