Search in sources :

Example 1 with SnapshotMetaBuilder

use of org.apache.ignite.raft.jraft.entity.SnapshotMetaBuilder in project ignite-3 by apache.

the class FSMCallerImpl method doSnapshotSave.

private void doSnapshotSave(final SaveSnapshotClosure done) {
    Requires.requireNonNull(done, "SaveSnapshotClosure is null");
    final long lastAppliedIndex = this.lastAppliedIndex.get();
    final ConfigurationEntry confEntry = this.logManager.getConfiguration(lastAppliedIndex);
    if (confEntry == null || confEntry.isEmpty()) {
        LOG.error("Empty conf entry for lastAppliedIndex={}", lastAppliedIndex);
        Utils.runClosureInThread(this.node.getOptions().getCommonExecutor(), done, new Status(RaftError.EINVAL, "Empty conf entry for lastAppliedIndex=%s", lastAppliedIndex));
        return;
    }
    SnapshotMetaBuilder metaBuilder = msgFactory.snapshotMeta().lastIncludedIndex(lastAppliedIndex).lastIncludedTerm(this.lastAppliedTerm).peersList(confEntry.getConf().getPeers().stream().map(Object::toString).collect(toList())).learnersList(confEntry.getConf().getLearners().stream().map(Object::toString).collect(toList()));
    if (confEntry.getOldConf() != null) {
        metaBuilder.oldPeersList(confEntry.getOldConf().getPeers().stream().map(Object::toString).collect(toList())).oldLearnersList(confEntry.getOldConf().getLearners().stream().map(Object::toString).collect(toList()));
    }
    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(org.apache.ignite.raft.jraft.Status) SnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter) SnapshotMetaBuilder(org.apache.ignite.raft.jraft.entity.SnapshotMetaBuilder) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry)

Aggregations

Status (org.apache.ignite.raft.jraft.Status)1 ConfigurationEntry (org.apache.ignite.raft.jraft.conf.ConfigurationEntry)1 SnapshotMetaBuilder (org.apache.ignite.raft.jraft.entity.SnapshotMetaBuilder)1 SnapshotWriter (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter)1