Search in sources :

Example 1 with SnapshotManagementRequest

use of org.apache.ratis.protocol.SnapshotManagementRequest in project incubator-ratis by apache.

the class SnapshotManagementTest method runTestTakeSnapshotWithConfigurableGap.

void runTestTakeSnapshotWithConfigurableGap(CLUSTER cluster) throws Exception {
    RaftClientReply snapshotReply;
    final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster);
    final RaftPeerId leaderId = leader.getId();
    try (final RaftClient client = cluster.createClient(leaderId)) {
        for (int i = 0; i < RaftServerConfigKeys.Snapshot.creationGap(getProperties()) / 2 - 1; i++) {
            RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + i));
            Assert.assertTrue(reply.isSuccess());
        }
        Assert.assertTrue(leader.getStateMachine().getLastAppliedTermIndex().getIndex() < RaftServerConfigKeys.Snapshot.creationGap(getProperties()));
        snapshotReply = client.getSnapshotManagementApi(leaderId).create(3000);
        Assert.assertTrue(snapshotReply.isSuccess());
        Assert.assertEquals(0, snapshotReply.getLogIndex());
        for (int i = 0; i < RaftServerConfigKeys.Snapshot.creationGap(getProperties()) / 2 - 1; i++) {
            RaftClientReply reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + i));
            Assert.assertTrue(reply.isSuccess());
        }
        final SnapshotManagementRequest r1 = SnapshotManagementRequest.newCreate(client.getId(), leaderId, cluster.getGroupId(), CallId.getAndIncrement(), 3000);
        snapshotReply = client.getSnapshotManagementApi(leaderId).create(3000);
    }
    Assert.assertTrue(snapshotReply.isSuccess());
    final long snapshotIndex = snapshotReply.getLogIndex();
    LOG.info("snapshotIndex = {}", snapshotIndex);
    final File snapshotFile = SimpleStateMachine4Testing.get(leader).getStateMachineStorage().getSnapshotFile(leader.getInfo().getCurrentTerm(), snapshotIndex);
    Assert.assertTrue(snapshotFile.exists());
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) RaftTestUtil(org.apache.ratis.RaftTestUtil) RaftServer(org.apache.ratis.server.RaftServer) SnapshotManagementRequest(org.apache.ratis.protocol.SnapshotManagementRequest) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) File(java.io.File) RaftClient(org.apache.ratis.client.RaftClient)

Example 2 with SnapshotManagementRequest

use of org.apache.ratis.protocol.SnapshotManagementRequest in project incubator-ratis by apache.

the class GrpcAdminProtocolService method snapshotManagement.

@Override
public void snapshotManagement(SnapshotManagementRequestProto proto, StreamObserver<RaftClientReplyProto> responseObserver) {
    final SnapshotManagementRequest request = ClientProtoUtils.toSnapshotManagementRequest(proto);
    GrpcUtil.asyncCall(responseObserver, () -> protocol.snapshotManagementAsync(request), ClientProtoUtils::toRaftClientReplyProto);
}
Also used : SnapshotManagementRequest(org.apache.ratis.protocol.SnapshotManagementRequest) ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils)

Aggregations

SnapshotManagementRequest (org.apache.ratis.protocol.SnapshotManagementRequest)2 File (java.io.File)1 RaftTestUtil (org.apache.ratis.RaftTestUtil)1 RaftClient (org.apache.ratis.client.RaftClient)1 ClientProtoUtils (org.apache.ratis.client.impl.ClientProtoUtils)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)1 RaftServer (org.apache.ratis.server.RaftServer)1