use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter 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);
}
use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter in project ignite-3 by apache.
the class LocalSnapshotStorageTest method testCreateOpen.
@Test
public void testCreateOpen() throws Exception {
SnapshotWriter writer = this.snapshotStorage.create();
assertNotNull(writer);
RaftOutter.SnapshotMeta wroteMeta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(this.lastSnapshotIndex + 1).lastIncludedTerm(1).build();
((LocalSnapshotWriter) writer).saveMeta(wroteMeta);
writer.addFile("data");
assertEquals(1, this.snapshotStorage.getRefs(this.lastSnapshotIndex).get());
writer.close();
// release old
assertEquals(0, this.snapshotStorage.getRefs(this.lastSnapshotIndex).get());
// ref new
assertEquals(1, this.snapshotStorage.getRefs(this.lastSnapshotIndex + 1).get());
SnapshotReader reader = this.snapshotStorage.open();
assertNotNull(reader);
assertTrue(reader.listFiles().contains("data"));
RaftOutter.SnapshotMeta readMeta = reader.load();
assertEquals(wroteMeta, readMeta);
assertEquals(2, this.snapshotStorage.getRefs(this.lastSnapshotIndex + 1).get());
reader.close();
assertEquals(1, this.snapshotStorage.getRefs(this.lastSnapshotIndex + 1).get());
}
use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotSave.
@Test
public void testOnSnapshotSave() throws Exception {
final SnapshotWriter writer = Mockito.mock(SnapshotWriter.class);
Mockito.when(this.logManager.getConfiguration(10)).thenReturn(TestUtils.getConfEntry("localhost:8081,localhost:8082,localhost:8083", "localhost:8081"));
final SaveSnapshotClosure done = new SaveSnapshotClosure() {
@Override
public void run(final Status status) {
}
@Override
public SnapshotWriter start(final SnapshotMeta meta) {
assertEquals(10, meta.lastIncludedIndex());
return writer;
}
};
this.fsmCaller.onSnapshotSave(done);
this.fsmCaller.flush();
Mockito.verify(this.fsm).onSnapshotSave(writer, done);
}
use of org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter in project ignite-3 by apache.
the class FSMCallerTest method testOnSnapshotSaveEmptyConf.
@Test
public void testOnSnapshotSaveEmptyConf() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
this.fsmCaller.onSnapshotSave(new SaveSnapshotClosure() {
@Override
public void run(final Status status) {
assertFalse(status.isOk());
assertEquals("Empty conf entry for lastAppliedIndex=10", status.getErrorMsg());
latch.countDown();
}
@Override
public SnapshotWriter start(final SnapshotMeta meta) {
return null;
}
});
latch.await();
}
Aggregations