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());
}
}
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);
}
}
}
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();
}
}
}
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);
}
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());
}
Aggregations