Search in sources :

Example 6 with ConfigurationEntry

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

the class FSMCallerImpl method doSnapshotSave.

private void doSnapshotSave(final SaveSnapshotClosure done) {
    Requires.requireNonNull(done, "SaveSnapshotClosure is null");
    final long lastAppliedIndex = this.lastAppliedIndex.get();
    final RaftOutter.SnapshotMeta.Builder metaBuilder = // 
    RaftOutter.SnapshotMeta.newBuilder().setLastIncludedIndex(// 
    lastAppliedIndex).setLastIncludedTerm(this.lastAppliedTerm);
    final ConfigurationEntry confEntry = this.logManager.getConfiguration(lastAppliedIndex);
    if (confEntry == null || confEntry.isEmpty()) {
        LOG.error("Empty conf entry for lastAppliedIndex={}", lastAppliedIndex);
        Utils.runClosureInThread(done, new Status(RaftError.EINVAL, "Empty conf entry for lastAppliedIndex=%s", lastAppliedIndex));
        return;
    }
    for (final PeerId peer : confEntry.getConf()) {
        metaBuilder.addPeers(peer.toString());
    }
    for (final PeerId peer : confEntry.getConf().getLearners()) {
        metaBuilder.addLearners(peer.toString());
    }
    if (confEntry.getOldConf() != null) {
        for (final PeerId peer : confEntry.getOldConf()) {
            metaBuilder.addOldPeers(peer.toString());
        }
        for (final PeerId peer : confEntry.getOldConf().getLearners()) {
            metaBuilder.addOldLearners(peer.toString());
        }
    }
    final SnapshotWriter writer = done.start(metaBuilder.build());
    if (writer == null) {
        done.run(new Status(RaftError.EINVAL, "snapshot_storage create SnapshotWriter failed"));
        return;
    }
    this.fsm.onSnapshotSave(writer, done);
}
Also used : Status(io.dingodb.raft.Status) SnapshotWriter(io.dingodb.raft.storage.snapshot.SnapshotWriter) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) PeerId(io.dingodb.raft.entity.PeerId)

Example 7 with ConfigurationEntry

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

the class NodeImpl method unsafeRegisterConfChange.

private void unsafeRegisterConfChange(final Configuration oldConf, final Configuration newConf, final Closure done) {
    Requires.requireTrue(newConf.isValid(), "Invalid new conf: %s", newConf);
    // The new conf entry(will be stored in log manager) should be valid
    Requires.requireTrue(new ConfigurationEntry(null, newConf, oldConf).isValid(), "Invalid conf entry: %s", newConf);
    if (this.state != State.STATE_LEADER) {
        LOG.warn("Node {} refused configuration changing as the state={}.", getNodeId(), this.state);
        if (done != null) {
            final Status status = new Status();
            if (this.state == State.STATE_TRANSFERRING) {
                status.setError(RaftError.EBUSY, "Is transferring leadership.");
            } else {
                status.setError(RaftError.EPERM, "Not leader");
            }
            Utils.runClosureInThread(done, status);
        }
        return;
    }
    // check concurrent conf change
    if (this.confCtx.isBusy()) {
        LOG.warn("Node {} refused configuration concurrent changing.", getNodeId());
        if (done != null) {
            Utils.runClosureInThread(done, new Status(RaftError.EBUSY, "Doing another configuration change."));
        }
        return;
    }
    // Return immediately when the new peers equals to current configuration
    if (this.conf.getConf().equals(newConf)) {
        Utils.runClosureInThread(done);
        return;
    }
    this.confCtx.start(oldConf, newConf, done);
}
Also used : Status(io.dingodb.raft.Status) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry)

Aggregations

ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)7 Status (io.dingodb.raft.Status)4 LogId (io.dingodb.raft.entity.LogId)4 Configuration (io.dingodb.raft.conf.Configuration)3 ConfigurationManager (io.dingodb.raft.conf.ConfigurationManager)2 LogEntry (io.dingodb.raft.entity.LogEntry)2 PeerId (io.dingodb.raft.entity.PeerId)2 DisruptorMetricSet (io.dingodb.raft.util.DisruptorMetricSet)2 NamedThreadFactory (io.dingodb.raft.util.NamedThreadFactory)2 com.lmax.disruptor (com.lmax.disruptor)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 FSMCaller (io.dingodb.raft.FSMCaller)1 NodeMetrics (io.dingodb.raft.core.NodeMetrics)1 EntryType (io.dingodb.raft.entity.EnumOutter.EntryType)1 ErrorType (io.dingodb.raft.entity.EnumOutter.ErrorType)1 NodeId (io.dingodb.raft.entity.NodeId)1 SnapshotMeta (io.dingodb.raft.entity.RaftOutter.SnapshotMeta)1 LogEntryCorruptedException (io.dingodb.raft.error.LogEntryCorruptedException)1