Search in sources :

Example 1 with SnapshotRequest

use of org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest in project ignite-3 by apache.

the class CliServiceImpl method snapshot.

@Override
public Status snapshot(final String groupId, final PeerId peer) {
    Requires.requireTrue(!StringUtils.isBlank(groupId), "Blank group id");
    Requires.requireNonNull(peer, "Null peer");
    if (!this.cliClientService.connect(peer.getEndpoint())) {
        return new Status(-1, "Fail to init channel to %s", peer);
    }
    SnapshotRequest req = cliOptions.getRaftMessagesFactory().snapshotRequest().groupId(groupId).peerId(peer.toString()).build();
    try {
        final Message result = this.cliClientService.snapshot(peer.getEndpoint(), req, null).get();
        return statusFromResponse(result);
    } catch (final Exception e) {
        return new Status(-1, e.getMessage());
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Message(org.apache.ignite.raft.jraft.rpc.Message) SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) JRaftException(org.apache.ignite.raft.jraft.error.JRaftException)

Example 2 with SnapshotRequest

use of org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest in project ignite-3 by apache.

the class RaftGroupServiceImpl method snapshot.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<Void> snapshot(Peer peer) {
    SnapshotRequest req = factory.snapshotRequest().groupId(groupId).build();
    // Disable the timeout for a snapshot request.
    CompletableFuture<NetworkMessage> fut = cluster.messagingService().invoke(peer.address(), req, Integer.MAX_VALUE);
    return fut.thenCompose(resp -> {
        if (resp != null) {
            RpcRequests.ErrorResponse resp0 = (RpcRequests.ErrorResponse) resp;
            if (resp0.errorCode() != RaftError.SUCCESS.getNumber())
                return CompletableFuture.failedFuture(new RaftException(RaftError.forNumber(resp0.errorCode()), resp0.errorMsg()));
        }
        return CompletableFuture.completedFuture(null);
    });
}
Also used : SnapshotRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) NetworkMessage(org.apache.ignite.network.NetworkMessage)

Aggregations

SnapshotRequest (org.apache.ignite.raft.jraft.rpc.CliRequests.SnapshotRequest)2 NetworkMessage (org.apache.ignite.network.NetworkMessage)1 Status (org.apache.ignite.raft.jraft.Status)1 JRaftException (org.apache.ignite.raft.jraft.error.JRaftException)1 Message (org.apache.ignite.raft.jraft.rpc.Message)1 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)1