Search in sources :

Example 1 with Configuration

use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.

the class NodeImpl method addLearners.

@Override
public void addLearners(final List<PeerId> learners, final Closure done) {
    checkPeers(learners);
    this.writeLock.lock();
    try {
        final Configuration newConf = new Configuration(this.conf.getConf());
        for (final PeerId peer : learners) {
            newConf.addLearner(peer);
        }
        unsafeRegisterConfChange(this.conf.getConf(), newConf, done);
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 2 with Configuration

use of io.dingodb.raft.conf.Configuration 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 Configuration

use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.

the class CliServiceImpl method recordConfigurationChange.

private void recordConfigurationChange(final String groupId, final List<String> oldPeersList, final List<String> newPeersList) {
    final Configuration oldConf = new Configuration();
    for (final String peerIdStr : oldPeersList) {
        final PeerId oldPeer = new PeerId();
        oldPeer.parse(peerIdStr);
        oldConf.addPeer(oldPeer);
    }
    final Configuration newConf = new Configuration();
    for (final String peerIdStr : newPeersList) {
        final PeerId newPeer = new PeerId();
        newPeer.parse(peerIdStr);
        newConf.addPeer(newPeer);
    }
    LOG.info("Configuration of replication group {} changed from {} to {}.", groupId, oldConf, newConf);
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 4 with Configuration

use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.

the class NodeImpl method addPeer.

@Override
public void addPeer(final PeerId peer, final Closure done) {
    Requires.requireNonNull(peer, "Null peer");
    this.writeLock.lock();
    try {
        Requires.requireTrue(!this.conf.getConf().contains(peer), "Peer already exists in current configuration");
        final Configuration newConf = new Configuration(this.conf.getConf());
        newConf.addPeer(peer);
        unsafeRegisterConfChange(this.conf.getConf(), newConf, done);
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Configuration(io.dingodb.raft.conf.Configuration)

Example 5 with Configuration

use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.

the class NodeImpl method resetPeers.

@Override
public Status resetPeers(final Configuration newPeers) {
    Requires.requireNonNull(newPeers, "Null new peers");
    Requires.requireTrue(!newPeers.isEmpty(), "Empty new peers");
    Requires.requireTrue(newPeers.isValid(), "Invalid new peers: %s", newPeers);
    this.writeLock.lock();
    try {
        if (newPeers.isEmpty()) {
            LOG.warn("Node {} set empty peers.", getNodeId());
            return new Status(RaftError.EINVAL, "newPeers is empty");
        }
        if (!this.state.isActive()) {
            LOG.warn("Node {} is in state {}, can't set peers.", getNodeId(), this.state);
            return new Status(RaftError.EPERM, "Bad state: %s", this.state);
        }
        // bootstrap?
        if (this.conf.getConf().isEmpty()) {
            LOG.info("Node {} set peers to {} from empty.", getNodeId(), newPeers);
            this.conf.setConf(newPeers);
            stepDown(this.currTerm + 1, false, new Status(RaftError.ESETPEER, "Set peer from empty configuration"));
            return Status.OK();
        }
        if (this.state == State.STATE_LEADER && this.confCtx.isBusy()) {
            LOG.warn("Node {} set peers need wait current conf changing.", getNodeId());
            return new Status(RaftError.EBUSY, "Changing to another configuration");
        }
        // check equal, maybe retry direct return
        if (this.conf.getConf().equals(newPeers)) {
            return Status.OK();
        }
        final Configuration newConf = new Configuration(newPeers);
        LOG.info("Node {} set peers from {} to {}.", getNodeId(), this.conf.getConf(), newPeers);
        this.conf.setConf(newConf);
        this.conf.getOldConf().reset();
        stepDown(this.currTerm + 1, false, new Status(RaftError.ESETPEER, "Raft node set peer normally"));
        return Status.OK();
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration)

Aggregations

Configuration (io.dingodb.raft.conf.Configuration)31 PeerId (io.dingodb.raft.entity.PeerId)16 Status (io.dingodb.raft.Status)9 LogId (io.dingodb.raft.entity.LogId)5 ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)3 LogEntry (io.dingodb.raft.entity.LogEntry)3 CliRequests (io.dingodb.raft.rpc.CliRequests)3 TimeoutException (java.util.concurrent.TimeoutException)3 Message (com.google.protobuf.Message)2 RaftException (io.dingodb.raft.error.RaftException)2 NodeOptions (io.dingodb.raft.option.NodeOptions)2 RpcRequests (io.dingodb.raft.rpc.RpcRequests)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 com.lmax.disruptor (com.lmax.disruptor)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 Closure (io.dingodb.raft.Closure)1