Search in sources :

Example 31 with LogHeader

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

the class LegacyLogs method migrateLogs.

public void migrateLogs(File storeDir, File migrationDir) throws IOException {
    File[] logFiles = fs.listFiles(storeDir, versionedLegacyLogFilesFilter);
    for (File file : logFiles) {
        final Pair<LogHeader, IOCursor<LogEntry>> pair = reader.openReadableChannel(file);
        final LogHeader header = pair.first();
        try (IOCursor<LogEntry> cursor = pair.other();
            LogVersionedStoreChannel channel = writer.openWritableChannel(new File(migrationDir, file.getName()))) {
            writer.writeLogHeader(channel, header);
            writer.writeAllLogEntries(channel, cursor);
        }
    }
}
Also used : IOCursor(org.neo4j.cursor.IOCursor) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) File(java.io.File) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 32 with LogHeader

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

the class PhysicalLogFile method accept.

@Override
public void accept(LogHeaderVisitor visitor) throws IOException {
    // Start from the where we're currently at and go backwards in time (versions)
    long logVersion = logFiles.getHighestLogVersion();
    long highTransactionId = lastCommittedId.get();
    while (logFiles.versionExists(logVersion)) {
        Long previousLogLastTxId = logHeaderCache.getLogHeader(logVersion);
        if (previousLogLastTxId == null) {
            LogHeader header = readLogHeader(fileSystem, logFiles.getLogFileForVersion(logVersion), false);
            if (header != null) {
                assert logVersion == header.logVersion;
                logHeaderCache.putHeader(header.logVersion, header.lastCommittedTxId);
                previousLogLastTxId = header.lastCommittedTxId;
            }
        }
        if (previousLogLastTxId != null) {
            long lowTransactionId = previousLogLastTxId + 1;
            LogPosition position = LogPosition.start(logVersion);
            if (!visitor.visit(position, lowTransactionId, highTransactionId)) {
                break;
            }
            highTransactionId = previousLogLastTxId;
        }
        logVersion--;
    }
}
Also used : LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader)

Example 33 with LogHeader

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

the class PhysicalLogFileTest method shouldOpenInFreshDirectoryAndFinallyAddHeader.

@Test
public void shouldOpenInFreshDirectoryAndFinallyAddHeader() throws Exception {
    // GIVEN
    String name = "log";
    LifeSupport life = new LifeSupport();
    FileSystemAbstraction fs = fileSystemRule.get();
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
    life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, mock(Monitor.class), new LogHeaderCache(10)));
    // WHEN
    life.start();
    life.shutdown();
    // THEN
    File file = new PhysicalLogFiles(directory.directory(), name, fs).getLogFileForVersion(1L);
    LogHeader header = readLogHeader(fs, file);
    assertEquals(1L, header.logVersion);
    assertEquals(5L, header.lastCommittedTxId);
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.Test)

Example 34 with LogHeader

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

the class LogTestUtils method filterNeostoreLogicalLog.

public static File filterNeostoreLogicalLog(FileSystemAbstraction fileSystem, File file, final LogHook<LogEntry> filter) throws IOException {
    filter.file(file);
    File tempFile = new File(file.getAbsolutePath() + ".tmp");
    fileSystem.deleteFile(tempFile);
    try (StoreChannel in = fileSystem.open(file, "r");
        StoreChannel out = fileSystem.open(tempFile, "rw")) {
        LogHeader logHeader = transferLogicalLogHeader(in, out, ByteBuffer.allocate(LOG_HEADER_SIZE));
        PhysicalLogVersionedStoreChannel outChannel = new PhysicalLogVersionedStoreChannel(out, logHeader.logVersion, logHeader.logFormatVersion);
        PhysicalLogVersionedStoreChannel inChannel = new PhysicalLogVersionedStoreChannel(in, logHeader.logVersion, logHeader.logFormatVersion);
        ReadableLogChannel inBuffer = new ReadAheadLogChannel(inChannel, LogVersionBridge.NO_MORE_CHANNELS);
        LogEntryReader<ReadableLogChannel> entryReader = new VersionAwareLogEntryReader<>();
        LogEntry entry;
        while ((entry = entryReader.readLogEntry(inBuffer)) != null) {
            if (filter.test(entry)) {
            // TODO allright, write to outBuffer
            }
        }
    }
    return tempFile;
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) File(java.io.File) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry)

Example 35 with LogHeader

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

the class LegacyLogEntryWriterTest method shouldWriteTheHeaderInTheFile.

@Test
public void shouldWriteTheHeaderInTheFile() throws IOException {
    // given
    final LegacyLogEntryWriter writer = new LegacyLogEntryWriter(fs);
    final File output = new File(getLegacyLogFilename(3));
    final LogHeader header = new LogHeader(CURRENT_LOG_VERSION, 1, 42L);
    // when
    try (LogVersionedStoreChannel channel = writer.openWritableChannel(output)) {
        writer.writeLogHeader(channel, header);
    }
    // then
    assertEquals(header, readLogHeader(fs, output));
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) File(java.io.File) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) Test(org.junit.Test)

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