Search in sources :

Example 16 with Status

use of org.apache.ignite.raft.jraft.Status 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 17 with Status

use of org.apache.ignite.raft.jraft.Status in project ignite-3 by apache.

the class IteratorImpl method runTheRestClosureWithError.

protected void runTheRestClosureWithError() {
    for (long i = Math.max(this.currentIndex, this.firstClosureIndex); i <= this.committedIndex; i++) {
        final Closure done = this.closures.get((int) (i - this.firstClosureIndex));
        if (done != null) {
            Requires.requireNonNull(this.error, "error");
            Requires.requireNonNull(this.error.getStatus(), "error.status");
            final Status status = this.error.getStatus();
            Utils.runClosureInThread(options.getCommonExecutor(), done, status);
        }
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Closure(org.apache.ignite.raft.jraft.Closure)

Example 18 with Status

use of org.apache.ignite.raft.jraft.Status in project ignite-3 by apache.

the class NodeImpl method handlePreVoteResponse.

public void handlePreVoteResponse(final PeerId peerId, final long term, final RequestVoteResponse response) {
    boolean doUnlock = true;
    this.writeLock.lock();
    try {
        if (this.state != State.STATE_FOLLOWER) {
            LOG.warn("Node {} received invalid PreVoteResponse from {}, state not in STATE_FOLLOWER but {}.", getNodeId(), peerId, this.state);
            return;
        }
        if (term != this.currTerm) {
            LOG.warn("Node {} received invalid PreVoteResponse from {}, term={}, currTerm={}.", getNodeId(), peerId, term, this.currTerm);
            return;
        }
        if (response.term() > this.currTerm) {
            LOG.warn("Node {} received invalid PreVoteResponse from {}, term {}, expect={}.", getNodeId(), peerId, response.term(), this.currTerm);
            stepDown(response.term(), false, new Status(RaftError.EHIGHERTERMRESPONSE, "Raft node receives higher term pre_vote_response."));
            return;
        }
        LOG.info("Node {} received PreVoteResponse from {}, term={}, granted={}.", getNodeId(), peerId, response.term(), response.granted());
        // check granted quorum?
        if (response.granted()) {
            this.prevVoteCtx.grant(peerId);
            if (this.prevVoteCtx.isGranted()) {
                doUnlock = false;
                electSelf();
            }
        }
    } finally {
        if (doUnlock) {
            this.writeLock.unlock();
        }
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status)

Example 19 with Status

use of org.apache.ignite.raft.jraft.Status in project ignite-3 by apache.

the class NodeImpl method readFollower.

private void readFollower(final ReadIndexRequest request, final RpcResponseClosure<ReadIndexResponse> closure) {
    if (this.leaderId == null || this.leaderId.isEmpty()) {
        closure.run(new Status(RaftError.EPERM, "No leader at term %d.", this.currTerm));
        return;
    }
    // send request to leader.
    final ReadIndexRequest newRequest = raftOptions.getRaftMessagesFactory().readIndexRequest().groupId(request.groupId()).serverId(request.serverId()).peerId(request.peerId()).entriesList(request.entriesList()).peerId(this.leaderId.toString()).build();
    this.rpcClientService.readIndex(this.leaderId.getEndpoint(), newRequest, -1, closure);
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ReadIndexRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest)

Example 20 with Status

use of org.apache.ignite.raft.jraft.Status in project ignite-3 by apache.

the class CopySessionTest method testOnRpcReturnedRetry.

@Test
public void testOnRpcReturnedRetry() throws Exception {
    assertNull(this.session.getTimer());
    assertNull(this.session.getRpcCall());
    final ByteBufferCollector bufRef = ByteBufferCollector.allocate(0);
    this.session.setDestBuf(bufRef);
    final CompletableFuture<Message> future = new CompletableFuture<>();
    final RpcRequests.GetFileRequest rb = raftOpts.getRaftMessagesFactory().getFileRequest().readerId(99).filename("data").count(Integer.MAX_VALUE).offset(0).readPartly(true).build();
    Mockito.when(this.rpcService.getFile(this.address, rb, this.copyOpts.getTimeoutMs(), session.getDone())).thenReturn(future);
    this.session.onRpcReturned(new Status(RaftError.EINTR, "test"), null);
    assertNotNull(this.session.getTimer());
    Thread.sleep(this.copyOpts.getRetryIntervalMs() + 100);
    assertNotNull(this.session.getRpcCall());
    assertSame(future, this.session.getRpcCall());
    assertNull(this.session.getTimer());
}
Also used : Status(org.apache.ignite.raft.jraft.Status) CompletableFuture(java.util.concurrent.CompletableFuture) ByteBufferCollector(org.apache.ignite.raft.jraft.util.ByteBufferCollector) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) Test(org.junit.jupiter.api.Test)

Aggregations

Status (org.apache.ignite.raft.jraft.Status)121 Test (org.junit.jupiter.api.Test)49 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)43 CountDownLatch (java.util.concurrent.CountDownLatch)31 Message (org.apache.ignite.raft.jraft.rpc.Message)21 ArrayList (java.util.ArrayList)20 Node (org.apache.ignite.raft.jraft.Node)20 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)20 ReadIndexClosure (org.apache.ignite.raft.jraft.closure.ReadIndexClosure)16 LogId (org.apache.ignite.raft.jraft.entity.LogId)14 RaftException (org.apache.ignite.raft.jraft.error.RaftException)14 LogEntry (org.apache.ignite.raft.jraft.entity.LogEntry)11 JRaftException (org.apache.ignite.raft.jraft.error.JRaftException)11 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)10 Endpoint (org.apache.ignite.raft.jraft.util.Endpoint)10 ByteBuffer (java.nio.ByteBuffer)9 List (java.util.List)9 ConfigurationEntry (org.apache.ignite.raft.jraft.conf.ConfigurationEntry)9 Task (org.apache.ignite.raft.jraft.entity.Task)8 RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)8