Search in sources :

Example 1 with LogHeader

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

the class NeoStoreDataSourceTest method logWithTransactions.

private PhysicalLogFiles logWithTransactions(long logVersion, long headerTxId) throws IOException {
    PhysicalLogFiles files = mock(PhysicalLogFiles.class);
    when(files.getLowestLogVersion()).thenReturn(logVersion);
    when(files.hasAnyEntries(logVersion)).thenReturn(true);
    when(files.versionExists(logVersion)).thenReturn(true);
    when(files.extractHeader(logVersion)).thenReturn(new LogHeader(LogEntryVersion.CURRENT.byteCode(), logVersion, headerTxId));
    return files;
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 2 with LogHeader

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

the class LegacyLogEntryReaderTest method shouldReadTheLogHeaderAndSetCurrentVersionAndABaseTxIdIfNegative.

@Test
public void shouldReadTheLogHeaderAndSetCurrentVersionAndABaseTxIdIfNegative() throws IOException {
    // given
    final LegacyLogEntryReader reader = new LegacyLogEntryReader(fs);
    // when
    final Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(input);
    // then
    // not null cursor
    pair.other().close();
    assertEquals(new LogHeader(CURRENT_LOG_VERSION, 3L, BASE_TX_ID), pair.first());
}
Also used : IOCursor(org.neo4j.cursor.IOCursor) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.Test)

Example 3 with LogHeader

use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader 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 4 with LogHeader

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

the class PhysicalLogFileInformationTest method shouldReadAndCacheFirstCommittedTransactionIdWhenNotCached.

@Test
public void shouldReadAndCacheFirstCommittedTransactionIdWhenNotCached() throws Exception {
    PhysicalLogFileInformation info = new PhysicalLogFileInformation(logFiles, logHeaderCache, transactionIdStore::getLastCommittedTransactionId, logVersionToTimestamp);
    long expected = 5;
    long version = 10L;
    when(logFiles.getHighestLogVersion()).thenReturn(version);
    when(logHeaderCache.getLogHeader(version)).thenReturn(null);
    when(logFiles.versionExists(version)).thenReturn(true);
    when(logFiles.extractHeader(version)).thenReturn(new LogHeader((byte) -1, /*ignored*/
    -1L, /*ignored*/
    expected - 1L));
    when(logFiles.hasAnyEntries(version)).thenReturn(true);
    long firstCommittedTxId = info.getFirstExistingEntryId();
    assertEquals(expected, firstCommittedTxId);
    verify(logHeaderCache, times(1)).putHeader(version, expected - 1);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) PhysicalLogFileInformation(org.neo4j.kernel.impl.transaction.log.PhysicalLogFileInformation) Test(org.junit.Test)

Example 5 with LogHeader

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

the class DumpLogicalLog method dump.

public void dump(String filenameOrDirectory, PrintStream out, Predicate<LogEntry[]> filter, Function<LogEntry, String> serializer) throws IOException {
    File file = new File(filenameOrDirectory);
    printFile(file, out);
    File firstFile;
    LogVersionBridge bridge;
    if (file.isDirectory()) {
        // Use natural log version bridging if a directory is supplied
        final PhysicalLogFiles logFiles = new PhysicalLogFiles(file, fileSystem);
        bridge = new ReaderLogVersionBridge(fileSystem, logFiles) {

            @Override
            public LogVersionedStoreChannel next(LogVersionedStoreChannel channel) throws IOException {
                LogVersionedStoreChannel next = super.next(channel);
                if (next != channel) {
                    printFile(logFiles.getLogFileForVersion(next.getVersion()), out);
                }
                return next;
            }
        };
        firstFile = logFiles.getLogFileForVersion(logFiles.getLowestLogVersion());
    } else {
        // Use no bridging, simple reading this single log file if a file is supplied
        firstFile = file;
        bridge = NO_MORE_CHANNELS;
    }
    StoreChannel fileChannel = fileSystem.open(firstFile, "r");
    ByteBuffer buffer = ByteBuffer.allocateDirect(LOG_HEADER_SIZE);
    LogHeader logHeader;
    try {
        logHeader = readLogHeader(buffer, fileChannel, false, firstFile);
    } catch (IOException ex) {
        out.println("Unable to read timestamp information, no records in logical log.");
        out.println(ex.getMessage());
        fileChannel.close();
        throw ex;
    }
    out.println("Logical log format: " + logHeader.logFormatVersion + " version: " + logHeader.logVersion + " with prev committed tx[" + logHeader.lastCommittedTxId + "]");
    PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
    ReadableClosablePositionAwareChannel logChannel = new ReadAheadLogChannel(channel, bridge, DEFAULT_READ_AHEAD_SIZE);
    LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
    IOCursor<LogEntry> entryCursor = new LogEntryCursor(entryReader, logChannel);
    TransactionLogEntryCursor transactionCursor = new TransactionLogEntryCursor(entryCursor);
    try (IOCursor<LogEntry[]> cursor = filter == null ? transactionCursor : new FilteringIOCursor<>(transactionCursor, filter)) {
        while (cursor.next()) {
            for (LogEntry entry : cursor.get()) {
                out.println(serializer.apply(entry));
            }
        }
    }
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) LogVersionBridge(org.neo4j.kernel.impl.transaction.log.LogVersionBridge) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) TransactionLogEntryCursor(org.neo4j.kernel.impl.transaction.log.TransactionLogEntryCursor) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) ReaderLogVersionBridge(org.neo4j.kernel.impl.transaction.log.ReaderLogVersionBridge) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Aggregations

LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)45 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)18 Test (org.junit.jupiter.api.Test)13 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)12 File (java.io.File)11 StoreChannel (org.neo4j.io.fs.StoreChannel)11 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)11 LogHeaderWriter.writeLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader)10 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)9 Path (java.nio.file.Path)7 Test (org.junit.Test)6 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)6 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)6 IOException (java.io.IOException)5 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)5 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)5 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)4 LogEntryStart (org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart)4 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)4 ByteBuffer (java.nio.ByteBuffer)3