RaftGroup getGroup() { return RaftGroup.valueOf(groupId, getRaftConf().getPeers()); }
void setRaftConf(long logIndex, RaftConfiguration conf) { configurationManager.addConfiguration(logIndex, conf); server.getServerRpc().addPeers(conf.getPeers()); LOG.info("{}: set configuration {} at {}", getSelfId(), conf, logIndex); LOG.trace("{}: {}", getSelfId(), configurationManager); }
Collection<CommitInfoProto> getCommitInfos() { final List<CommitInfoProto> infos = new ArrayList<>(); // add the commit info of this server infos.add(commitInfoCache.update(getPeer(), state.getLog().getLastCommittedIndex())); // add the commit infos of other servers if (isLeader()) { Optional.ofNullable(leaderState).ifPresent( leader -> leader.updateFollowerCommitInfos(commitInfoCache, infos)); } else { getRaftConf().getPeers().stream() .filter(p -> !p.getId().equals(state.getSelfId())) .map(RaftPeer::getId) .map(commitInfoCache::get) .filter(i -> i != null) .forEach(infos::add); } return infos; }
Collection<CommitInfoProto> getCommitInfos() { final List<CommitInfoProto> infos = new ArrayList<>(); // add the commit info of this server infos.add(commitInfoCache.update(getPeer(), state.getLog().getLastCommittedIndex())); // add the commit infos of other servers if (isLeader()) { role.getLeaderState().ifPresent( leader -> leader.updateFollowerCommitInfos(commitInfoCache, infos)); } else { getRaftConf().getPeers().stream() .filter(p -> !p.getId().equals(state.getSelfId())) .map(RaftPeer::getId) .map(commitInfoCache::get) .filter(i -> i != null) .forEach(infos::add); } return infos; }
ServerInformationReply getServerInformation(ServerInformationRequest request) { final RaftGroup group = new RaftGroup(groupId, getRaftConf().getPeers()); return new ServerInformationReply(request, getCommitInfos(), group); }
NotLeaderException generateNotLeaderException() { if (lifeCycle.getCurrentState() != RUNNING) { return new NotLeaderException(getId(), null, null); } RaftPeerId leaderId = state.getLeaderId(); if (leaderId == null || leaderId.equals(state.getSelfId())) { // No idea about who is the current leader. Or the peer is the current // leader, but it is about to step down RaftPeer suggestedLeader = getRaftConf().getRandomPeer(state.getSelfId()); leaderId = suggestedLeader == null ? null : suggestedLeader.getId(); } RaftConfiguration conf = getRaftConf(); Collection<RaftPeer> peers = conf.getPeers(); return new NotLeaderException(getId(), conf.getPeer(leaderId), peers.toArray(new RaftPeer[peers.size()])); }
NotLeaderException generateNotLeaderException() { if (lifeCycle.getCurrentState() != RUNNING) { return new NotLeaderException(getId(), null, null); } RaftPeerId leaderId = state.getLeaderId(); if (leaderId == null || leaderId.equals(state.getSelfId())) { // No idea about who is the current leader. Or the peer is the current // leader, but it is about to step down RaftPeer suggestedLeader = getRaftConf().getRandomPeer(state.getSelfId()); leaderId = suggestedLeader == null ? null : suggestedLeader.getId(); } RaftConfiguration conf = getRaftConf(); Collection<RaftPeer> peers = conf.getPeers(); return new NotLeaderException(getId(), conf.getPeer(leaderId), peers.toArray(new RaftPeer[peers.size()])); }
void updateConfiguration(LogEntryProto[] entries) { if (entries != null && entries.length > 0) { configurationManager.removeConfigurations(entries[0].getIndex()); for (LogEntryProto entry : entries) { if (ProtoUtils.isConfigurationLogEntry(entry)) { final RaftConfiguration conf = ServerProtoUtils.toRaftConfiguration( entry.getIndex(), entry.getConfigurationEntry()); configurationManager.addConfiguration(entry.getIndex(), conf); server.getServerRpc().addPeers(conf.getPeers()); } } } }