private void checkStaging() { if (!inStagingState()) { // it is possible that the bootstrapping is done. Then, fallback to UPDATE_COMMIT UPDATE_COMMIT_EVENT.execute(); } else { final long committedIndex = server.getState().getLog() .getLastCommittedIndex(); Collection<BootStrapProgress> reports = checkAllProgress(committedIndex); if (reports.contains(BootStrapProgress.NOPROGRESS)) { LOG.debug("{} fails the setConfiguration request", server.getId()); stagingState.fail(); } else if (!reports.contains(BootStrapProgress.PROGRESSING)) { // all caught up! applyOldNewConf(); senders.forEach(s -> s.getFollower().startAttendVote()); } } }
private void checkNewPeers() { if (!inStagingState()) { // it is possible that the bootstrapping is done and we still have // remaining STAGINGPROGRESS event to handle. updateLastCommitted(); } else { final long committedIndex = server.getState().getLog() .getLastCommittedIndex(); Collection<BootStrapProgress> reports = checkAllProgress(committedIndex); if (reports.contains(BootStrapProgress.NOPROGRESS)) { LOG.debug("{} fails the setConfiguration request", server.getId()); stagingState.fail(); } else if (!reports.contains(BootStrapProgress.PROGRESSING)) { // all caught up! applyOldNewConf(); senders.forEach(s -> s.getFollower().startAttendVote()); } } }
/** * Start bootstrapping new peers */ PendingRequest startSetConfiguration(SetConfigurationRequest request) { Preconditions.assertTrue(running && !inStagingState()); RaftPeer[] peersInNewConf = request.getPeersInNewConf(); Collection<RaftPeer> peersToBootStrap = RaftConfiguration .computeNewPeers(peersInNewConf, server.getRaftConf()); // add the request to the pending queue final PendingRequest pending = pendingRequests.addConfRequest(request); ConfigurationStagingState stagingState = new ConfigurationStagingState( peersToBootStrap, new PeerConfiguration(Arrays.asList(peersInNewConf))); Collection<RaftPeer> newPeers = stagingState.getNewPeers(); // set the staging state this.stagingState = stagingState; if (newPeers.isEmpty()) { applyOldNewConf(); } else { // update the LeaderState's sender list addSenders(newPeers); } return pending; }
/** * Start bootstrapping new peers */ PendingRequest startSetConfiguration(SetConfigurationRequest request) { Preconditions.assertTrue(running && !inStagingState()); RaftPeer[] peersInNewConf = request.getPeersInNewConf(); Collection<RaftPeer> peersToBootStrap = RaftConfiguration .computeNewPeers(peersInNewConf, server.getRaftConf()); // add the request to the pending queue final PendingRequest pending = pendingRequests.addConfRequest(request); ConfigurationStagingState stagingState = new ConfigurationStagingState( peersToBootStrap, new PeerConfiguration(Arrays.asList(peersInNewConf))); Collection<RaftPeer> newPeers = stagingState.getNewPeers(); // set the staging state this.stagingState = stagingState; if (newPeers.isEmpty()) { applyOldNewConf(); } else { // update the LeaderState's sender list addSenders(newPeers); } return pending; }