Search in sources :

Example 1 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.

the class LegacyLogEntryWriterTest method shouldWriteAllTheEntryInACommitToTheFile.

@Test
public void shouldWriteAllTheEntryInACommitToTheFile() throws IOException {
    // given
    final LogVersionedStoreChannel channel = mock(LogVersionedStoreChannel.class);
    final LogEntryWriter logEntryWriter = mock(LogEntryWriter.class);
    final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs, liftToFactory(logEntryWriter));
    final LogEntryStart start = new LogEntryStart(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY, UNSPECIFIED);
    final LogEntryCommand command = new LogEntryCommand(new Command.NodeCommand(nodeRecord, nodeRecord));
    final LogEntryCommit commit = new OnePhaseCommit(42L, 43L);
    // when
    final IOCursor<LogEntry> cursor = mockCursor(start, command, commit);
    writer.writeAllLogEntries(channel, cursor);
    // then
    verify(logEntryWriter, times(1)).writeStartEntry(0, 1, 2L, 3L, EMPTY_ADDITIONAL_ARRAY);
    final TransactionRepresentation expected = new PhysicalTransactionRepresentation(Arrays.asList(command.getXaCommand()));
    verify(logEntryWriter, times(1)).serialize(eq(expected));
    verify(logEntryWriter, times(1)).writeCommitEntry(42L, 43L);
}
Also used : LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Command(org.neo4j.kernel.impl.transaction.command.Command) LogEntryCommand(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand) LogEntryCommit(org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 2 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.

the class LegacyLogsTest method shouldRewriteLogFiles.

@Test
public void shouldRewriteLogFiles() throws IOException {
    // given
    final IOCursor<LogEntry> cursor = mock(IOCursor.class);
    final LogVersionedStoreChannel writeChannel = mock(LogVersionedStoreChannel.class);
    final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42);
    when(fs.listFiles(storeDir, versionedLegacyLogFilesFilter)).thenReturn(new File[] { new File(getLegacyLogFilename(1)) });
    when(reader.openReadableChannel(new File(getLegacyLogFilename(1)))).thenReturn(Pair.of(header, cursor));
    when(writer.openWritableChannel(new File(migrationDir, getLegacyLogFilename(1)))).thenReturn(writeChannel);
    // when
    new LegacyLogs(fs, reader, writer).migrateLogs(storeDir, migrationDir);
    // then
    verify(writer, times(1)).writeLogHeader(writeChannel, header);
    verify(writer, times(1)).writeAllLogEntries(writeChannel, cursor);
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) File(java.io.File) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.Test)

Example 3 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.

the class LegacyLogsTest method transactionInformationRetrievedFromCommitEntries.

@Test
@SuppressWarnings("unchecked")
public void transactionInformationRetrievedFromCommitEntries() throws IOException {
    FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
    File logFile = new File(LegacyLogFilenames.getLegacyLogFilename(1));
    when(fs.listFiles(any(File.class), any(FilenameFilter.class))).thenReturn(new File[] { logFile });
    LegacyLogEntryReader reader = mock(LegacyLogEntryReader.class);
    LogEntry[] entries = new LogEntry[] { start(1), createNode(1), createNode(2), commit(1), start(2), createNode(3), createNode(4), commit(2), start(3), createNode(5), commit(3) };
    when(reader.openReadableChannel(any(File.class))).thenReturn(readableChannel(entries), readableChannel(entries), readableChannel(entries));
    LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
    LegacyLogs legacyLogs = new LegacyLogs(fs, reader, writer);
    assertEquals(newTransactionId(1), getTransactionInformation(legacyLogs, 1));
    assertEquals(newTransactionId(2), getTransactionInformation(legacyLogs, 2));
    assertEquals(newTransactionId(3), getTransactionInformation(legacyLogs, 3));
}
Also used : FilenameFilter(java.io.FilenameFilter) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) File(java.io.File) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Test(org.junit.Test)

Example 4 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.

the class LogEntrySortingCursorTest method shouldBeFineIfThereAreEntriesWithoutACommit.

@Test
public void shouldBeFineIfThereAreEntriesWithoutACommit() throws IOException {
    // given
    final LogEntry start1 = start(3);
    final LogEntry command1 = command();
    final LogEntry start2 = start(3);
    final LogEntry command2 = command();
    final LogEntry commit2 = commit(4);
    when(reader.readLogEntry(channel)).thenReturn(id(start2, 2), id(start1, 1), id(command1, 1), id(command2, 2), id(commit2, 2), null);
    // when
    final LogEntrySortingCursor cursor = new LogEntrySortingCursor(reader, channel);
    // then
    final List<LogEntry> expected = Arrays.asList(start2, command2, commit2);
    assertCursorContains(expected, cursor);
}
Also used : IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Test(org.junit.Test)

Example 5 with LogEntry

use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.

the class LogEntrySortingCursorTest method shouldDoNothingIfTheListIsOrdered.

@Test
public void shouldDoNothingIfTheListIsOrdered() throws IOException {
    // given
    final LogEntry start1 = start(1);
    final LogEntry command1 = command();
    final LogEntry commit1 = commit(2);
    final LogEntry start2 = start(2);
    final LogEntry command2 = command();
    final LogEntry commit2 = commit(3);
    when(reader.readLogEntry(channel)).thenReturn(id(start1, 1), id(command1, 1), id(commit1, 1), id(start2, 2), id(command2, 2), id(commit2, 2), null);
    // when
    final LogEntrySortingCursor cursor = new LogEntrySortingCursor(reader, channel);
    // then
    final List<LogEntry> expected = Arrays.asList(start1, command1, commit1, start2, command2, commit2);
    assertCursorContains(expected, cursor);
}
Also used : IdentifiableLogEntry(org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) Test(org.junit.Test)

Aggregations

LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)44 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)14 LogEntryCommit (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommit)14 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)12 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)12 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)12 Test (org.junit.Test)10 File (java.io.File)9 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)9 LogEntryCommand (org.neo4j.kernel.impl.transaction.log.entry.LogEntryCommand)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)8 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)7 IdentifiableLogEntry (org.neo4j.kernel.impl.transaction.log.entry.IdentifiableLogEntry)7 ArrayList (java.util.ArrayList)6 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)5 StorageCommand (org.neo4j.storageengine.api.StorageCommand)5 IOException (java.io.IOException)4 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4