Search in sources :

Example 1 with SnapshotWriter

use of io.dingodb.raft.storage.snapshot.SnapshotWriter 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)

Aggregations

Status (io.dingodb.raft.Status)1 ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)1 PeerId (io.dingodb.raft.entity.PeerId)1 SnapshotWriter (io.dingodb.raft.storage.snapshot.SnapshotWriter)1