Search in sources :

Example 1 with Status

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);
        }
    }
}
Also used : Status(io.dingodb.raft.Status) Closure(io.dingodb.raft.Closure)

Example 2 with 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;
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 3 with Status

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);
    }
}
Also used : Status(io.dingodb.raft.Status)

Example 4 with 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);
        }
    }
}
Also used : Status(io.dingodb.raft.Status)

Example 5 with 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);
}
Also used : Status(io.dingodb.raft.Status) RpcRequests(io.dingodb.raft.rpc.RpcRequests)

Aggregations

Status (io.dingodb.raft.Status)112 PeerId (io.dingodb.raft.entity.PeerId)31 BaseKVStoreClosure (io.dingodb.store.row.storage.BaseKVStoreClosure)21 Message (com.google.protobuf.Message)19 Configuration (io.dingodb.raft.conf.Configuration)12 RpcRequests (io.dingodb.raft.rpc.RpcRequests)12 JRaftException (io.dingodb.raft.error.JRaftException)11 LogId (io.dingodb.raft.entity.LogId)10 RaftException (io.dingodb.raft.error.RaftException)9 ArrayList (java.util.ArrayList)9 ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)7 LogEntry (io.dingodb.raft.entity.LogEntry)7 ByteBuffer (java.nio.ByteBuffer)7 RaftOutter (io.dingodb.raft.entity.RaftOutter)6 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)5 Disruptor (com.lmax.disruptor.dsl.Disruptor)5 ProducerType (com.lmax.disruptor.dsl.ProducerType)5 Closure (io.dingodb.raft.Closure)5 FSMCaller (io.dingodb.raft.FSMCaller)5 Node (io.dingodb.raft.Node)5