use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class GroupManagementImpl method list.
@Override
public GroupListReply list() throws IOException {
final long callId = CallId.getAndIncrement();
final RaftClientReply reply = client.io().sendRequestWithRetry(() -> new GroupListRequest(client.getId(), server, client.getGroupId(), callId));
Preconditions.assertTrue(reply instanceof GroupListReply, () -> "Unexpected reply: " + reply);
return (GroupListReply) reply;
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class ServerRestartTests method runTestRestartFollower.
void runTestRestartFollower(MiniRaftCluster cluster) throws Exception {
RaftTestUtil.waitForLeader(cluster);
final RaftPeerId leaderId = cluster.getLeader().getId();
// write some messages
final AtomicInteger messageCount = new AtomicInteger();
final Supplier<Message> newMessage = () -> new SimpleMessage("m" + messageCount.getAndIncrement());
writeSomething(newMessage, cluster);
// restart a follower
RaftPeerId followerId = cluster.getFollowers().get(0).getId();
LOG.info("Restart follower {}", followerId);
cluster.restartServer(followerId, false);
// write some more messages
writeSomething(newMessage, cluster);
final int truncatedMessageIndex = messageCount.get() - 1;
final long leaderLastIndex = cluster.getLeader().getRaftLog().getLastEntryTermIndex().getIndex();
// make sure the restarted follower can catchup
final RaftServer.Division followerState = cluster.getDivision(followerId);
JavaUtils.attemptRepeatedly(() -> {
Assert.assertTrue(followerState.getInfo().getLastAppliedIndex() >= leaderLastIndex);
return null;
}, 10, ONE_SECOND, "follower catchup", LOG);
// make sure the restarted peer's log segments is correct
final RaftServer.Division follower = cluster.restartServer(followerId, false);
final RaftLog followerLog = follower.getRaftLog();
final long followerLastIndex = followerLog.getLastEntryTermIndex().getIndex();
Assert.assertTrue(followerLastIndex >= leaderLastIndex);
final File followerOpenLogFile = getOpenLogFile(follower);
final File leaderOpenLogFile = getOpenLogFile(cluster.getDivision(leaderId));
// shutdown all servers
for (RaftServer s : cluster.getServers()) {
s.close();
}
// truncate log and
assertTruncatedLog(followerId, followerOpenLogFile, followerLastIndex, cluster);
assertTruncatedLog(leaderId, leaderOpenLogFile, leaderLastIndex, cluster);
// restart and write something.
cluster.restart(false);
writeSomething(newMessage, cluster);
// restart again and check messages.
cluster.restart(false);
try (final RaftClient client = cluster.createClient()) {
for (int i = 0; i < messageCount.get(); i++) {
if (i != truncatedMessageIndex) {
final Message m = new SimpleMessage("m" + i);
final RaftClientReply reply = client.io().sendReadOnly(m);
Assert.assertTrue(reply.isSuccess());
LOG.info("query {}: {} {}", m, reply, LogEntryProto.parseFrom(reply.getMessage().getContent()));
}
}
}
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class FileStoreClient method send.
static ByteString send(ByteString request, CheckedFunction<Message, RaftClientReply, IOException> sendFunction) throws IOException {
final RaftClientReply reply = sendFunction.apply(Message.valueOf(request));
final StateMachineException sme = reply.getStateMachineException();
if (sme != null) {
throw new IOException("Failed to send request " + request, sme);
}
Preconditions.assertTrue(reply.isSuccess(), () -> "Failed " + request + ", reply=" + reply);
return reply.getMessage().getContent();
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class Get method operation.
@Override
protected void operation(RaftClient client) throws IOException {
RaftClientReply getValue = client.io().sendReadOnly(Expression.Utils.toMessage(new Variable(name)));
Expression response = Expression.Utils.bytes2Expression(getValue.getMessage().getContent().toByteArray(), 0);
System.out.println(String.format("%s=%s", name, (DoubleValue) response).toString());
}
use of org.apache.ratis.protocol.RaftClientReply in project incubator-ratis by apache.
the class Assign method operation.
@Override
protected void operation(RaftClient client) throws IOException {
RaftClientReply send = client.io().send(new AssignmentMessage(new Variable(name), createExpression(value)));
System.out.println("Success: " + send.isSuccess());
System.out.println("Response: " + send.getMessage().getClass());
}
Aggregations