use of org.apache.ignite.raft.jraft.rpc.RpcRequests.TimeoutNowResponse in project ignite-3 by apache.
the class NodeImpl method handleTimeoutNowRequest.
@Override
public Message handleTimeoutNowRequest(final TimeoutNowRequest request, final RpcRequestClosure done) {
boolean doUnlock = true;
this.writeLock.lock();
try {
if (request.term() != this.currTerm) {
final long savedCurrTerm = this.currTerm;
if (request.term() > this.currTerm) {
stepDown(request.term(), false, new Status(RaftError.EHIGHERTERMREQUEST, "Raft node receives higher term request"));
}
LOG.info("Node {} received TimeoutNowRequest from {} while currTerm={} didn't match requestTerm={}.", getNodeId(), request.peerId(), savedCurrTerm, request.term());
return raftOptions.getRaftMessagesFactory().timeoutNowResponse().term(this.currTerm).success(false).build();
}
if (this.state != State.STATE_FOLLOWER) {
LOG.info("Node {} received TimeoutNowRequest from {}, while state={}, term={}.", getNodeId(), request.serverId(), this.state, this.currTerm);
return raftOptions.getRaftMessagesFactory().timeoutNowResponse().term(this.currTerm).success(false).build();
}
final long savedTerm = this.currTerm;
final TimeoutNowResponse resp = raftOptions.getRaftMessagesFactory().timeoutNowResponse().term(//
this.currTerm + 1).success(//
true).build();
// Parallelize response and election
done.sendResponse(resp);
doUnlock = false;
LOG.info("Node {} received TimeoutNowRequest from {}, term={} and starts voting.", getNodeId(), request.serverId(), savedTerm);
electSelf();
} finally {
if (doUnlock) {
this.writeLock.unlock();
}
}
return null;
}
Aggregations