Search in sources :

Example 6 with Configuration

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

the class NodeImpl method removePeer.

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

Example 7 with Configuration

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

the class ResetPeerRequestProcessor method processRequest0.

@Override
protected Message processRequest0(final CliRequestContext ctx, final CliRequests.ResetPeerRequest request, final RpcRequestClosure done) {
    final Configuration newConf = new Configuration();
    for (final String peerIdStr : request.getNewPeersList()) {
        final PeerId peer = new PeerId();
        if (peer.parse(peerIdStr)) {
            newConf.addPeer(peer);
        } else {
            return // 
            RpcFactoryHelper.responseFactory().newResponse(defaultResp(), RaftError.EINVAL, "Fail to parse peer id %s", peerIdStr);
        }
    }
    LOG.info("Receive ResetPeerRequest to {} from {}, new conf is {}", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), newConf);
    final Status st = ctx.node.resetPeers(newConf);
    return // 
    RpcFactoryHelper.responseFactory().newResponse(defaultResp(), st);
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 8 with Configuration

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

the class ChangePeersRequestProcessor method processRequest0.

@Override
protected Message processRequest0(final CliRequestContext ctx, final CliRequests.ChangePeersRequest request, final RpcRequestClosure done) {
    final List<PeerId> oldConf = ctx.node.listPeers();
    final Configuration conf = new Configuration();
    for (final String peerIdStr : request.getNewPeersList()) {
        final PeerId peer = new PeerId();
        if (peer.parse(peerIdStr)) {
            conf.addPeer(peer);
        } else {
            return // 
            RpcFactoryHelper.responseFactory().newResponse(defaultResp(), RaftError.EINVAL, "Fail to parse peer id %s", peerIdStr);
        }
    }
    LOG.info("Receive ChangePeersRequest to {} from {}, new conf is {}", ctx.node.getNodeId(), done.getRpcCtx().getRemoteAddress(), conf);
    ctx.node.changePeers(conf, status -> {
        if (!status.isOk()) {
            done.run(status);
        } else {
            CliRequests.ChangePeersResponse.Builder rb = CliRequests.ChangePeersResponse.newBuilder();
            for (final PeerId peer : oldConf) {
                rb.addOldPeers(peer.toString());
            }
            for (final PeerId peer : conf) {
                rb.addNewPeers(peer.toString());
            }
            done.sendResponse(rb.build());
        }
    });
    return null;
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 9 with Configuration

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

the class LogManagerImpl method setSnapshot.

@Override
public void setSnapshot(final SnapshotMeta meta) {
    LOG.debug("set snapshot: {}.", meta);
    boolean isUnLock = true;
    this.writeLock.lock();
    try {
        if (meta.getLastIncludedIndex() <= this.lastSnapshotId.getIndex()) {
            return;
        }
        final Configuration conf = confFromMeta(meta);
        final Configuration oldConf = oldConfFromMeta(meta);
        final ConfigurationEntry entry = new ConfigurationEntry(new LogId(meta.getLastIncludedIndex(), meta.getLastIncludedTerm()), conf, oldConf);
        this.configManager.setSnapshot(entry);
        final long term = unsafeGetTerm(meta.getLastIncludedIndex());
        final long savedLastSnapshotIndex = this.lastSnapshotId.getIndex();
        this.lastSnapshotId.setIndex(meta.getLastIncludedIndex());
        this.lastSnapshotId.setTerm(meta.getLastIncludedTerm());
        if (this.lastSnapshotId.compareTo(this.appliedId) > 0) {
            this.appliedId = this.lastSnapshotId.copy();
        }
        // NOTICE: not to update disk_id here as we are not sure if this node really
        // has these logs on disk storage. Just leave disk_id as it was, which can keep
        // these logs in memory all the time until they are flushed to disk. By this
        // way we can avoid some corner cases which failed to get logs.
        // See https://github.com/baidu/braft/pull/224/commits/8ef6fdbf70d23f5a4ee147356a889e2c0fa22aac
        // if (this.lastSnapshotId.compareTo(this.diskId) > 0) {
        // this.diskId = this.lastSnapshotId.copy();
        // }
        long firstKeepedIndex = 0L;
        if (term == 0) {
            // last_included_index is larger than last_index
            // FIXME: what if last_included_index is less than first_index?
            firstKeepedIndex = meta.getLastIncludedIndex() + 1;
            truncatePrefix(firstKeepedIndex);
            isUnLock = false;
            writeLock.unlock();
        } else if (term == meta.getLastIncludedTerm()) {
            // TODO if there are still be need?
            if (savedLastSnapshotIndex > 0) {
                firstKeepedIndex = savedLastSnapshotIndex + 1;
                truncatePrefix(firstKeepedIndex);
                isUnLock = false;
                writeLock.unlock();
            }
        } else {
            final long lastIncludeIndex = meta.getLastIncludedIndex() + 1;
            boolean isOK = reset(lastIncludeIndex);
            isUnLock = false;
            writeLock.unlock();
            if (isOK) {
                final ResetClosure c = new ResetClosure(lastIncludeIndex);
                doPublish(c, EventType.RESET);
                LOG.warn("Reset log manager, nextLogIndex={}", lastIncludeIndex);
            } else {
                LOG.warn("Reset log manager failed, nextLogIndex={}.", lastIncludeIndex);
            }
        }
        if (firstKeepedIndex != 0) {
            final TruncatePrefixClosure c = new TruncatePrefixClosure(firstKeepedIndex);
            doPublish(c, EventType.TRUNCATE_PREFIX);
        }
    } finally {
        if (isUnLock) {
            this.writeLock.unlock();
        }
    }
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) LogId(io.dingodb.raft.entity.LogId)

Example 10 with Configuration

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

the class LogManagerImpl method oldConfFromMeta.

private Configuration oldConfFromMeta(final SnapshotMeta meta) {
    final Configuration oldConf = new Configuration();
    for (int i = 0; i < meta.getOldPeersCount(); i++) {
        final PeerId peer = new PeerId();
        peer.parse(meta.getOldPeers(i));
        oldConf.addPeer(peer);
    }
    for (int i = 0; i < meta.getOldLearnersCount(); i++) {
        final PeerId peer = new PeerId();
        peer.parse(meta.getOldLearners(i));
        oldConf.addLearner(peer);
    }
    return oldConf;
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

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