use of org.apache.ratis.protocol.RaftClientReply in project alluxio by Alluxio.
the class SnapshotReplicationManager method requestData.
private boolean requestData() {
Preconditions.checkState(mDownloadState.get() == DownloadState.REQUEST_DATA);
// request snapshots from the most recent to least recent
while (!mSnapshotCandidates.isEmpty()) {
Pair<SnapshotMetadata, RaftPeerId> candidate = mSnapshotCandidates.poll();
SnapshotMetadata metadata = candidate.getFirst();
RaftPeerId peerId = candidate.getSecond();
LOG.info("Request data from follower {} for snapshot (t: {}, i: {})", peerId, metadata.getSnapshotTerm(), metadata.getSnapshotIndex());
try {
RaftClientReply reply = mJournalSystem.sendMessageAsync(peerId, toMessage(JournalQueryRequest.newBuilder().setSnapshotRequest(GetSnapshotRequest.getDefaultInstance()).build())).get();
if (reply.getException() != null) {
throw reply.getException();
}
return true;
} catch (Exception e) {
LOG.warn("Failed to request snapshot data from {}: {}", peerId, e);
}
}
// return failure if there are no more candidates to ask snapshot from
return false;
}
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.send(new AssignmentMessage(new Variable(name), createExpression(value)));
System.out.println("Success: " + send.isSuccess());
System.out.println("Response: " + send.getMessage().getClass());
}
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.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 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 RaftSnapshotBaseTest method testBasicInstallSnapshot.
/**
* Basic test for install snapshot: start a one node cluster and let it
* generate a snapshot. Then delete the log and restart the node, and add more
* nodes as followers.
*/
@Test
public void testBasicInstallSnapshot() throws Exception {
List<LogPathAndIndex> logs;
try {
RaftTestUtil.waitForLeader(cluster);
final RaftPeerId leaderId = cluster.getLeader().getId();
int i = 0;
try (final RaftClient client = cluster.createClient(leaderId)) {
for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1; i++) {
RaftClientReply reply = client.send(new SimpleMessage("m" + i));
Assert.assertTrue(reply.isSuccess());
}
}
// wait for the snapshot to be done
RaftStorageDirectory storageDirectory = cluster.getLeader().getState().getStorage().getStorageDir();
final File snapshotFile = getSnapshotFile(cluster, i);
logs = storageDirectory.getLogSegmentFiles();
int retries = 0;
do {
Thread.sleep(1000);
} while (!snapshotFile.exists() && retries++ < 10);
Assert.assertTrue(snapshotFile + " does not exist", snapshotFile.exists());
} finally {
cluster.shutdown();
}
// delete the log segments from the leader
for (LogPathAndIndex path : logs) {
FileUtils.deleteFile(path.path.toFile());
}
// restart the peer
LOG.info("Restarting the cluster");
cluster.restart(false);
try {
assertLeaderContent(cluster);
// generate some more traffic
try (final RaftClient client = cluster.createClient(cluster.getLeader().getId())) {
Assert.assertTrue(client.send(new SimpleMessage("test")).isSuccess());
}
// add two more peers
MiniRaftCluster.PeerChanges change = cluster.addNewPeers(new String[] { "s3", "s4" }, true);
// trigger setConfiguration
cluster.setConfiguration(change.allPeersInNewConf);
RaftServerTestUtil.waitAndCheckNewConf(cluster, change.allPeersInNewConf, 0, null);
} finally {
cluster.shutdown();
}
}
Aggregations