protected Leader makeLeader(FileTxnSnapLog logFactory) throws IOException, X509Exception { return new Leader(this, new LeaderZooKeeperServer(logFactory, this, this.zkDb)); }
/** * Only used by QuorumStats at the moment */ public String[] getQuorumPeers() { List<String> l = new ArrayList<String>(); synchronized (this) { if (leader != null) { for (LearnerHandler fh : leader.getLearners()) { if (fh.getSocket() != null) { String s = formatInetAddr((InetSocketAddress)fh.getSocket().getRemoteSocketAddress()); if (leader.isLearnerSynced(fh)) s += "*"; l.add(s); } } } else if (follower != null) { l.add(formatInetAddr((InetSocketAddress)follower.sock.getRemoteSocketAddress())); } } return l.toArray(new String[0]); }
public void run() { if (onlyGetEpochToPropose) { try { epoch = leader.getEpochToPropose(followerSid, 0); } catch (Exception e) { } } else { try{ leader.waitForEpochAck(followerSid, new StateSummary(0, 0)); msg = "FollowerMockThread (id = " + followerSid + ") returned from waitForEpochAck"; } catch (Exception e) { } } } }
long epoch = getEpochToPropose(self.getId(), self.getAcceptedEpoch()); waitForEpochAck(self.getId(), leaderStateSummary); self.setCurrentEpoch(epoch); waitForNewLeaderAck(self.getId(), zk.getZxid()); } catch (InterruptedException e) { shutdown("Waiting for a quorum of followers, only synced with sids: [ " + getSidSetString(newLeaderProposal.ackSet) + " ]"); HashSet<Long> followerSet = new HashSet<Long>(); for (LearnerHandler f : learners) startZkServer(); for (LearnerHandler f : getLearners()) { if (!this.isRunning()) { shutdown("Unexpected internal error"); return; shutdown("Not sufficient followers synced, only synced with sids: [ " + getSidSetString(syncedSet) + " ]");
public void run() { try { leader.addLearnerHandler(this); tickOfNextAckDeadline = leader.self.tick.get() + leader.self.initLimit + leader.self.syncLimit; StateSummary ss = null; long zxid = qp.getZxid(); long newEpoch = leader.getEpochToPropose(this.getSid(), lastAcceptedEpoch); ss = new StateSummary(epoch, zxid); leader.waitForEpochAck(this.getSid(), ss); } else { byte ver[] = new byte[4]; leader.waitForEpochAck(this.getSid(), ss); LOG.info("Sending " + Leader.getPacketType(packetToSend)); leaderLastZxid = leader.startForwarding(this, updates); leader.waitForNewLeaderAck(getSid(), qp.getZxid()); leader.processAck(this.sid, qp.getZxid(), sock.getLocalSocketAddress()); break; case Leader.PING:
Long designatedLeader = getDesignatedLeader(p, zxid); commitAndActivate(zxid, designatedLeader); informAndActivate(p, designatedLeader); commit(zxid); inform(p); sendSync(r);
@After public void tearDown(){ leader.shutdown("end of test"); tmpDir.delete(); }
public void processRequest(Request request) throws RequestProcessorException { // LOG.warn("Ack>>> cxid = " + request.cxid + " type = " + // request.type + " id = " + request.sessionId); // request.addRQRec(">prop"); /* In the following IF-THEN-ELSE block, we process syncs on the leader. * If the sync is coming from a follower, then the follower * handler adds it to syncHandler. Otherwise, if it is a client of * the leader that issued the sync command, then syncHandler won't * contain the handler. In this case, we add it to syncHandler, and * call processRequest on the next processor. */ if (request instanceof LearnerSyncRequest){ zks.getLeader().processSync((LearnerSyncRequest)request); } else { nextProcessor.processRequest(request); if (request.getHdr() != null) { // We need to sync and get consensus on any transactions try { zks.getLeader().propose(request); } catch (XidRolloverException e) { throw new RequestProcessorException(e.getMessage(), e); } syncProcessor.processRequest(request); } } }
long epoch = leader.getEpochToPropose(1, 6); Assert.assertEquals("New proposed epoch is wrong", 7, epoch); } catch (Exception e){ leader.shutdown("end of test");
String msg = "zxid lower 32 bits have rolled over, forcing re-election, and therefore new epoch start"; shutdown(msg); throw new XidRolloverException(msg); sendPacket(pp);
addForwardingFollower(handler); } else { addObserverLearnerHandler(handler);
when(follower.toString()).thenReturn("1"); when(follower.getSid()).thenReturn(1L); leader.addLearnerHandler(follower); leader.addForwardingFollower(follower); when(observer.getLearnerType()).thenReturn(LearnerType.OBSERVER); when(observer.toString()).thenReturn("2"); leader.addLearnerHandler(observer); when(nonVotingFollower.toString()).thenReturn("5"); when(nonVotingFollower.getSid()).thenReturn(5L); leader.addLearnerHandler(nonVotingFollower); leader.addForwardingFollower(nonVotingFollower);
@Test public void testGetProposalSize() throws IOException, Leader.XidRolloverException { // Arrange Request req = createMockRequest(); // Act leader.propose(req); // Assert byte[] data = SerializeUtils.serializeRequest(req); assertEquals(data.length, leaderBean.getLastProposalSize()); assertEquals(data.length, leaderBean.getMinProposalSize()); assertEquals(data.length, leaderBean.getMaxProposalSize()); }
/** * Start up Leader ZooKeeper server and initialize zxid to the new epoch */ private synchronized void startZkServer() { // Update lastCommitted and Db's zxid to a value representing the new epoch lastCommitted = zk.getZxid(); LOG.info("Have quorum of supporters, sids: [ " + getSidSetString(newLeaderProposal.ackSet) + " ]; starting up and setting last processed zxid: 0x{}", Long.toHexString(zk.getZxid())); zk.startup(); /* * Update the election vote here to ensure that all members of the * ensemble report the same vote to new servers that start up and * send leader election notifications to the ensemble. * * @see https://issues.apache.org/jira/browse/ZOOKEEPER-1732 */ self.updateElectionVote(getEpoch()); zk.getZKDatabase().setlastProcessedZxid(zk.getZxid()); }
Long designatedLeader = getDesignatedLeader(newLeaderProposal, zk.getZxid()); self.updateElectionVote(getEpoch());
/** * Only used by QuorumStats at the moment */ public String[] getQuorumPeers() { List<String> l = new ArrayList<String>(); synchronized (this) { if (leader != null) { synchronized (leader.learners) { for (LearnerHandler fh : leader.learners) { if (fh.getSocket() == null) continue; String s = fh.getSocket().getRemoteSocketAddress().toString(); if (leader.isLearnerSynced(fh)) s += "*"; l.add(s); } } } else if (follower != null) { l.add(follower.sock.getRemoteSocketAddress().toString()); } } return l.toArray(new String[0]); }
leader.getEpochToPropose(peer.getId(), lastAcceptedEpoch); } catch (InterruptedException e) { try { leader.getEpochToPropose(observerId, lastAcceptedEpoch); } catch (InterruptedException e) { leader.getEpochToPropose(participantId, lastAcceptedEpoch); } catch (Exception e) { Assert.fail("Timed out in getEpochToPropose");
assertTrue("Not following", qu.getPeer(index).peer.follower != null); long epochF = (qu.getPeer(index).peer.getActiveServer().getZxid() >> 32L); long epochL = (leader.getEpoch() >> 32L); assertTrue("Zxid: " + qu.getPeer(index).peer.getActiveServer().getZKDatabase().getDataTreeLastProcessedZxid() + "Current epoch: " + epochF, epochF == epochL);