Search in sources :

Example 26 with LogEntry

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

the class BaseLogStorageTest method testLoadWithConfigManager.

@Test
public void testLoadWithConfigManager() {
    assertTrue(this.confManager.getLastConfiguration().isEmpty());
    final LogEntry confEntry1 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
    confEntry1.setId(new LogId(99, 1));
    confEntry1.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082").listPeers());
    final LogEntry confEntry2 = new LogEntry(EnumOutter.EntryType.ENTRY_TYPE_CONFIGURATION);
    confEntry2.setId(new LogId(100, 2));
    confEntry2.setPeers(JRaftUtils.getConfiguration("localhost:8081,localhost:8082,localhost:8083").listPeers());
    assertTrue(this.logStorage.appendEntry(confEntry1));
    assertEquals(1, this.logStorage.appendEntries(Arrays.asList(confEntry2)));
    // reload log storage.
    if (this.logStorage instanceof RocksDBLogStorage) {
        this.logStorage.shutdown();
        this.logStorage = newLogStorage();
        this.logStorage.init(newLogStorageOptions());
        ConfigurationEntry conf = this.confManager.getLastConfiguration();
        assertNotNull(conf);
        assertFalse(conf.isEmpty());
        assertEquals("localhost:8081,localhost:8082,localhost:8083", conf.getConf().toString());
        conf = this.confManager.get(99);
        assertNotNull(conf);
        assertFalse(conf.isEmpty());
        assertEquals("localhost:8081,localhost:8082", conf.getConf().toString());
    }
}
Also used : LogId(org.apache.ignite.raft.jraft.entity.LogId) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BaseStorageTest(org.apache.ignite.raft.jraft.storage.BaseStorageTest) Test(org.junit.jupiter.api.Test)

Example 27 with LogEntry

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

the class LogManagerTest method testAppendOneEntry.

@Test
public void testAppendOneEntry() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final LogEntry entry = TestUtils.mockEntry(1, 1);
    final List<LogEntry> entries = new ArrayList<>();
    entries.add(entry);
    this.logManager.appendEntries(entries, new LogManager.StableClosure() {

        @Override
        public void run(final Status status) {
            assertTrue(status.isOk());
            latch.countDown();
        }
    });
    latch.await();
    assertEquals(1, this.logManager.getFirstLogIndex());
    assertEquals(1, this.logManager.getLastLogIndex());
    assertEquals(entry, this.logManager.getEntry(1));
    assertEquals(1, this.logManager.getLastLogIndex(true));
    LogId lastLogId = this.logManager.getLastLogId(true);
    assertEquals(1, lastLogId.getIndex());
    lastLogId = this.logManager.getLastLogId(false);
    assertEquals(1, lastLogId.getIndex());
    assertTrue(this.logManager.checkConsistency().isOk());
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) LogManager(org.apache.ignite.raft.jraft.storage.LogManager) LogId(org.apache.ignite.raft.jraft.entity.LogId) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BaseStorageTest(org.apache.ignite.raft.jraft.storage.BaseStorageTest) Test(org.junit.jupiter.api.Test)

Example 28 with LogEntry

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

the class LogManagerTest method mockAddEntries.

private List<LogEntry> mockAddEntries() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final List<LogEntry> mockEntries = TestUtils.mockEntries(10);
    this.logManager.appendEntries(new ArrayList<>(mockEntries), new LogManager.StableClosure() {

        @Override
        public void run(final Status status) {
            assertTrue(status.isOk());
            latch.countDown();
        }
    });
    latch.await();
    return mockEntries;
}
Also used : Status(org.apache.ignite.raft.jraft.Status) CountDownLatch(java.util.concurrent.CountDownLatch) LogManager(org.apache.ignite.raft.jraft.storage.LogManager) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry)

Example 29 with LogEntry

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

the class LogManagerTest method testSetAppliedId2.

@Test
public void testSetAppliedId2() throws Exception {
    final List<LogEntry> mockEntries = mockAddEntries();
    for (int i = 0; i < 10; i++) {
        // it's in memory
        assertEquals(mockEntries.get(i), this.logManager.getEntryFromMemory(i + 1));
    }
    // waiting for setDiskId()
    Thread.sleep(200);
    this.logManager.setAppliedId(new LogId(10, 10));
    for (int i = 0; i < 10; i++) {
        assertNull(this.logManager.getEntryFromMemory(i + 1));
        assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
    }
}
Also used : LogId(org.apache.ignite.raft.jraft.entity.LogId) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BaseStorageTest(org.apache.ignite.raft.jraft.storage.BaseStorageTest) Test(org.junit.jupiter.api.Test)

Example 30 with LogEntry

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

the class LogManagerTest method testAppendEntries.

@Test
public void testAppendEntries() throws Exception {
    final List<LogEntry> mockEntries = mockAddEntries();
    assertEquals(1, this.logManager.getFirstLogIndex());
    assertEquals(10, this.logManager.getLastLogIndex());
    for (int i = 0; i < 10; i++) {
        assertEquals(mockEntries.get(i), this.logManager.getEntry(i + 1));
    }
    assertEquals(10, this.logManager.getLastLogIndex(true));
    LogId lastLogId = this.logManager.getLastLogId(true);
    assertEquals(10, lastLogId.getIndex());
    lastLogId = this.logManager.getLastLogId(false);
    assertEquals(10, lastLogId.getIndex());
    assertTrue(this.logManager.checkConsistency().isOk());
}
Also used : LogId(org.apache.ignite.raft.jraft.entity.LogId) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) BaseStorageTest(org.apache.ignite.raft.jraft.storage.BaseStorageTest) Test(org.junit.jupiter.api.Test)

Aggregations

LogEntry (org.apache.ignite.raft.jraft.entity.LogEntry)48 LogId (org.apache.ignite.raft.jraft.entity.LogId)26 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)12 Status (org.apache.ignite.raft.jraft.Status)11 BaseStorageTest (org.apache.ignite.raft.jraft.storage.BaseStorageTest)11 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 LogManager (org.apache.ignite.raft.jraft.storage.LogManager)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 ConfigurationEntry (org.apache.ignite.raft.jraft.conf.ConfigurationEntry)6 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)6 ByteBuffer (java.nio.ByteBuffer)5 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)5 ConfigurationManager (org.apache.ignite.raft.jraft.conf.ConfigurationManager)4 RaftOptions (org.apache.ignite.raft.jraft.option.RaftOptions)4 EventHandler (com.lmax.disruptor.EventHandler)3 EventTranslator (com.lmax.disruptor.EventTranslator)3 RingBuffer (com.lmax.disruptor.RingBuffer)3 List (java.util.List)3