Search in sources :

Example 1 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class RaftMembershipManager method start.

@Override
public void start() throws IOException {
    this.state = storage.getInitialState();
    long recoverFromIndex = recoverFromIndexSupplier.getAsLong();
    log.info("Membership state before recovery: " + state);
    log.info("Recovering from: " + recoverFromIndex + " to: " + raftLog.appendIndex());
    try (RaftLogCursor cursor = raftLog.getEntryCursor(recoverFromIndex)) {
        while (cursor.next()) {
            append(cursor.index(), cursor.get());
        }
    }
    log.info("Membership state after recovery: " + state);
    updateMemberSets();
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)

Example 2 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class SegmentedRaftLogCursorIT method shouldReturnFalseOnCursorForEntryThatWasPruned.

@Test
public void shouldReturnFalseOnCursorForEntryThatWasPruned() throws Exception {
    //given
    SegmentedRaftLog segmentedRaftLog = createRaftLog(1, "keep_none");
    long firstIndex = segmentedRaftLog.append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
    segmentedRaftLog.append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
    long lastIndex = segmentedRaftLog.append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));
    //when
    segmentedRaftLog.prune(firstIndex);
    RaftLogCursor entryCursor = segmentedRaftLog.getEntryCursor(firstIndex);
    boolean next = entryCursor.next();
    //then
    assertFalse(next);
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 3 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class SegmentedRaftLogCursorIT method shouldReturnFalseOnCursorForEntryThatDoesntExist.

@Test
public void shouldReturnFalseOnCursorForEntryThatDoesntExist() throws Exception {
    //given
    SegmentedRaftLog segmentedRaftLog = createRaftLog(1);
    segmentedRaftLog.append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
    segmentedRaftLog.append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
    long lastIndex = segmentedRaftLog.append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));
    //when
    boolean next;
    try (RaftLogCursor entryCursor = segmentedRaftLog.getEntryCursor(lastIndex + 1)) {
        next = entryCursor.next();
    }
    //then
    assertFalse(next);
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 4 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class SegmentedRaftLogPartialEntryRecoveryTest method shouldNotAppendAtTheEndOfLogFileWithIncompleteEntries.

@Test
public void shouldNotAppendAtTheEndOfLogFileWithIncompleteEntries() throws Throwable {
    // Given
    // we use a RaftLog to create a raft log file and then we will chop some bits off the end
    SegmentedRaftLog raftLog = createRaftLog(100_000);
    raftLog.start();
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    raftLog.stop();
    // We use a temporary RecoveryProtocol to get the file to chop
    RecoveryProtocol recovery = createRecoveryProtocol();
    State recoveryState = recovery.run();
    String logFilename = recoveryState.segments.last().getFilename();
    File logFile = new File(logDirectory, logFilename);
    StoreChannel lastFile = fsRule.get().open(logFile, "rw");
    long currentSize = lastFile.size();
    lastFile.close();
    // When
    // We induce an incomplete entry at the end of the last file
    lastFile = fsRule.get().open(logFile, "rw");
    lastFile.truncate(currentSize - 1);
    lastFile.close();
    // We start the raft log again, on the previous log file with truncated last entry.
    raftLog = createRaftLog(100_000);
    //  Recovery will run here
    raftLog.start();
    // Append an entry
    raftLog.append(new RaftLogEntry(4, new NewLeaderBarrier()));
    // The log should report as containing only the last entry we've appended
    try (RaftLogCursor entryCursor = raftLog.getEntryCursor(0)) {
        // There should be exactly one entry, of type NewLeaderBarrier
        assertTrue(entryCursor.next());
        RaftLogEntry raftLogEntry = entryCursor.get();
        assertEquals(NewLeaderBarrier.class, raftLogEntry.content().getClass());
        assertFalse(entryCursor.next());
    }
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) StoreChannel(org.neo4j.io.fs.StoreChannel) NewLeaderBarrier(org.neo4j.causalclustering.core.consensus.NewLeaderBarrier) File(java.io.File) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 5 with RaftLogCursor

use of org.neo4j.causalclustering.core.consensus.log.RaftLogCursor in project neo4j by neo4j.

the class SegmentedRaftLogCursorIT method shouldReturnTrueOnEntryThatExists.

@Test
public void shouldReturnTrueOnEntryThatExists() throws Exception {
    //given
    SegmentedRaftLog segmentedRaftLog = createRaftLog(1);
    segmentedRaftLog.append(new RaftLogEntry(1, ReplicatedInteger.valueOf(1)));
    segmentedRaftLog.append(new RaftLogEntry(2, ReplicatedInteger.valueOf(2)));
    long lastIndex = segmentedRaftLog.append(new RaftLogEntry(3, ReplicatedInteger.valueOf(3)));
    //when
    boolean next;
    try (RaftLogCursor entryCursor = segmentedRaftLog.getEntryCursor(lastIndex)) {
        next = entryCursor.next();
    }
    //then
    assertTrue(next);
}
Also used : RaftLogCursor(org.neo4j.causalclustering.core.consensus.log.RaftLogCursor) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)7 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)6 Test (org.junit.Test)4 File (java.io.File)1 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1