use of io.dingodb.raft.Status in project dingo by dingodb.
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(done, status);
}
}
}
use of io.dingodb.raft.Status in project dingo by dingodb.
the class NodeImpl method checkDeadNodes.
private boolean checkDeadNodes(final Configuration conf, final long monotonicNowMs, final boolean stepDownOnCheckFail) {
// Check learner replicators at first.
for (final PeerId peer : conf.getLearners()) {
checkReplicator(peer);
}
// Ensure quorum nodes alive.
final List<PeerId> peers = conf.listPeers();
final Configuration deadNodes = new Configuration();
if (checkDeadNodes0(peers, monotonicNowMs, true, deadNodes)) {
return true;
}
if (stepDownOnCheckFail) {
LOG.warn("Node {} steps down when alive nodes don't satisfy quorum, term={}, deadNodes={}, conf={}.", getNodeId(), this.currTerm, deadNodes, conf);
final Status status = new Status();
status.setError(RaftError.ERAFTTIMEDOUT, "Majority of the group dies: %d/%d", deadNodes.size(), peers.size());
stepDown(this.currTerm, false, status);
}
return false;
}
use of io.dingodb.raft.Status in project dingo by dingodb.
the class NodeImpl method checkStepDown.
// in writeLock
private void checkStepDown(final long requestTerm, final PeerId serverId) {
final Status status = new Status();
if (requestTerm > this.currTerm) {
status.setError(RaftError.ENEWLEADER, "Raft node receives message from new leader with higher term.");
stepDown(requestTerm, false, status);
} else if (this.state != State.STATE_FOLLOWER) {
status.setError(RaftError.ENEWLEADER, "Candidate receives message from new leader with the same term.");
stepDown(requestTerm, false, status);
} else if (this.leaderId.isEmpty()) {
status.setError(RaftError.ENEWLEADER, "Follower receives message from new leader with the same term.");
stepDown(requestTerm, false, status);
}
// save current leader
if (this.leaderId == null || this.leaderId.isEmpty()) {
resetLeaderId(serverId, status);
}
}
use of io.dingodb.raft.Status in project dingo by dingodb.
the class NodeImpl method doSnapshot.
private void doSnapshot(final Closure done) {
if (this.snapshotExecutor != null) {
this.snapshotExecutor.doSnapshot(done);
} else {
if (done != null) {
final Status status = new Status(RaftError.EINVAL, "Snapshot is not supported");
Utils.runClosureInThread(done, status);
}
}
}
use of io.dingodb.raft.Status in project dingo by dingodb.
the class NodeImpl method readFollower.
private void readFollower(final RpcRequests.ReadIndexRequest request, final RpcResponseClosure<RpcRequests.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 RpcRequests.ReadIndexRequest newRequest = //
RpcRequests.ReadIndexRequest.newBuilder().mergeFrom(//
request).setPeerId(//
this.leaderId.toString()).build();
this.rpcService.readIndex(this.leaderId.getEndpoint(), newRequest, -1, closure);
}
Aggregations