Search in sources :

Example 1 with SnapshotMeta

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

the class FSMCallerTest method testOnSnapshotLoad.

@Test
public void testOnSnapshotLoad() throws Exception {
    final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
    final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(12).lastIncludedTerm(1).build();
    Mockito.when(reader.load()).thenReturn(meta);
    Mockito.when(this.fsm.onSnapshotLoad(reader)).thenReturn(true);
    final CountDownLatch latch = new CountDownLatch(1);
    this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {

        @Override
        public void run(final Status status) {
            assertTrue(status.isOk());
            latch.countDown();
        }

        @Override
        public SnapshotReader start() {
            return reader;
        }
    });
    latch.await();
    assertEquals(this.fsmCaller.getLastAppliedIndex(), 12);
    Mockito.verify(this.fsm).onConfigurationCommitted(Mockito.any());
}
Also used : LoadSnapshotClosure(org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure) Status(org.apache.ignite.raft.jraft.Status) SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 2 with SnapshotMeta

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

the class FSMCallerTest method testOnSnapshotLoadFSMError.

@Test
public void testOnSnapshotLoadFSMError() throws Exception {
    final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
    final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(12).lastIncludedTerm(1).build();
    Mockito.when(reader.load()).thenReturn(meta);
    Mockito.when(this.fsm.onSnapshotLoad(reader)).thenReturn(false);
    final CountDownLatch latch = new CountDownLatch(1);
    this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {

        @Override
        public void run(final Status status) {
            assertFalse(status.isOk());
            assertEquals(-1, status.getCode());
            assertEquals("StateMachine onSnapshotLoad failed", status.getErrorMsg());
            latch.countDown();
        }

        @Override
        public SnapshotReader start() {
            return reader;
        }
    });
    latch.await();
    assertEquals(this.fsmCaller.getLastAppliedIndex(), 10);
}
Also used : LoadSnapshotClosure(org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure) Status(org.apache.ignite.raft.jraft.Status) SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 3 with SnapshotMeta

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

the class SnapshotExecutorImpl method installSnapshot.

@Override
public void installSnapshot(final InstallSnapshotRequest request, final InstallSnapshotResponseBuilder response, final RpcRequestClosure done) {
    final SnapshotMeta meta = request.meta();
    final DownloadingSnapshot ds = new DownloadingSnapshot(request, response, done);
    // as the retry snapshot will replace this one.
    if (!registerDownloadingSnapshot(ds)) {
        LOG.warn("Fail to register downloading snapshot.");
        // This RPC will be responded by the previous session
        return;
    }
    Requires.requireNonNull(this.curCopier, "curCopier");
    try {
        this.curCopier.join();
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        LOG.warn("Install snapshot copy job was canceled.");
        return;
    }
    loadDownloadingSnapshot(ds, meta);
}
Also used : SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta)

Example 4 with SnapshotMeta

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

the class FSMCallerTest method testOnSnapshotLoadStale.

@Test
public void testOnSnapshotLoadStale() throws Exception {
    final SnapshotReader reader = Mockito.mock(SnapshotReader.class);
    final SnapshotMeta meta = opts.getRaftMessagesFactory().snapshotMeta().lastIncludedIndex(5).lastIncludedTerm(1).build();
    Mockito.when(reader.load()).thenReturn(meta);
    final CountDownLatch latch = new CountDownLatch(1);
    this.fsmCaller.onSnapshotLoad(new LoadSnapshotClosure() {

        @Override
        public void run(final Status status) {
            assertFalse(status.isOk());
            assertEquals(RaftError.ESTALE, status.getRaftError());
            latch.countDown();
        }

        @Override
        public SnapshotReader start() {
            return reader;
        }
    });
    latch.await();
    assertEquals(this.fsmCaller.getLastAppliedIndex(), 10);
}
Also used : LoadSnapshotClosure(org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure) Status(org.apache.ignite.raft.jraft.Status) SnapshotReader(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 5 with SnapshotMeta

use of org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta 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);
}
Also used : Status(org.apache.ignite.raft.jraft.Status) SnapshotWriter(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter) SaveSnapshotClosure(org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure) SnapshotMeta(org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta) Test(org.junit.jupiter.api.Test)

Aggregations

SnapshotMeta (org.apache.ignite.raft.jraft.entity.RaftOutter.SnapshotMeta)6 Status (org.apache.ignite.raft.jraft.Status)5 Test (org.junit.jupiter.api.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 LoadSnapshotClosure (org.apache.ignite.raft.jraft.closure.LoadSnapshotClosure)3 SnapshotReader (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotReader)3 SaveSnapshotClosure (org.apache.ignite.raft.jraft.closure.SaveSnapshotClosure)2 SnapshotWriter (org.apache.ignite.raft.jraft.storage.snapshot.SnapshotWriter)2