/** * Handle a raft configuration change request from client. */ @Override public CompletableFuture<RaftClientReply> setConfigurationAsync( SetConfigurationRequest request) throws IOException { return getImpl().setConfigurationAsync(request); }
@Override public RaftClientReply setConfiguration(SetConfigurationRequest request) throws IOException { return getImpl().setConfiguration(request); }
@Override public RequestVoteReplyProto requestVote(RequestVoteRequestProto r) throws IOException { return getImpl().requestVote(r); }
@Override public RaftClientReply submitClientRequest(RaftClientRequest request) throws IOException { return getImpl().submitClientRequest(request); }
@Override public CompletableFuture<RaftClientReply> submitClientRequestAsync( RaftClientRequest request) throws IOException { return getImpl().submitClientRequestAsync(request); }
@Override public CompletableFuture<AppendEntriesReplyProto> appendEntriesAsync( AppendEntriesRequestProto r) throws IOException { return getImpl().appendEntriesAsync(r); }
@Override public AppendEntriesReplyProto appendEntries(AppendEntriesRequestProto r) throws IOException { return getImpl().appendEntries(r); }
@Override public InstallSnapshotReplyProto installSnapshot( InstallSnapshotRequestProto request) throws IOException { return getImpl().installSnapshot(request); }
@Override public String toString() { try { return getImpl().toString(); } catch (IOException ignored) { return getClass().getSimpleName() + ":" + getId(); } } }
@Override public RaftClientReply submitClientRequest(RaftClientRequest request) throws IOException { return getImpl(request.getRaftGroupId()).submitClientRequest(request); }
private void checkInitialization() throws IOException { if (this.log == null) { ServerState state = proxy.getImpl(groupId).getState(); this.log = state.getLog(); } }
@Override public RaftClientReply setConfiguration(SetConfigurationRequest request) throws IOException { return getImpl(request.getRaftGroupId()).setConfiguration(request); }
@Override public AppendEntriesReplyProto appendEntries(AppendEntriesRequestProto request) throws IOException { return getImpl(request.getServerRequest()).appendEntries(request); }
@Override public RequestVoteReplyProto requestVote(RequestVoteRequestProto request) throws IOException { return getImpl(request.getServerRequest()).requestVote(request); }
@Override public InstallSnapshotReplyProto installSnapshot(InstallSnapshotRequestProto request) throws IOException { return getImpl(request.getServerRequest()).installSnapshot(request); }
private RaftServerImpl getImpl(RaftRpcRequestProto proto) throws IOException { return getImpl(ProtoUtils.toRaftGroupId(proto.getRaftGroupId())); }
public static RaftServerImpl getRaftServerImpl(RaftServerProxy proxy, RaftGroupId groupId) { return JavaUtils.callAsUnchecked(() -> proxy.getImpl(groupId)); } }
public String printServers(RaftGroupId groupId) { final StringBuilder b = new StringBuilder("printing "); if (groupId != null) { b.append(groupId); } else { b.append("ALL groups"); } getServers().stream().filter( s -> { if (groupId == null) { return true; } try { return groupId.equals(s.getImpl().getGroupId()); } catch (IOException e) { return false; } }) .forEach(s -> b.append("\n ").append(s)); return b.toString(); }
public RaftServerImpl restartServer(RaftPeerId newId, RaftGroup group, boolean format) throws IOException { killServer(newId); servers.remove(newId); final RaftServerProxy proxy = putNewServer(newId, group, format); proxy.start(); return group == null? null: proxy.getImpl(group.getGroupId()); }
@Test public void testLateServerStart() throws Exception { final int numServer = 3; LOG.info("Running testLateServerStart"); final MiniRaftCluster cluster = newCluster(numServer); cluster.initServers(); // start all except one servers final Iterator<RaftServerProxy> i = cluster.getServers().iterator(); for(int j = 1; j < numServer; j++) { i.next().start(); } final RaftServerImpl leader = waitForLeader(cluster); final TimeDuration sleepTime = TimeDuration.valueOf(5, TimeUnit.SECONDS); LOG.info("sleep " + sleepTime); sleepTime.sleep(); // start the last server final RaftServerProxy lastServer = i.next(); lastServer.start(); final RaftPeerId lastServerLeaderId = JavaUtils.attempt( () -> getLeader(lastServer.getImpl().getState()), 10, 1000, "getLeaderId", LOG); Assert.assertEquals(leader.getId(), lastServerLeaderId); }