Search in sources :

Example 6 with LogHeader

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

the class RsdrMain method getLogCursor.

private static IOCursor<LogEntry> getLogCursor(FileSystemAbstraction fileSystem, String fname, NeoStores neoStores) throws IOException {
    File file = new File(neoStores.getStoreDir(), fname);
    StoreChannel fileChannel = fileSystem.open(file, "r");
    LogHeader logHeader = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, false, file);
    console.printf("Logical log version: %s with prev committed tx[%s]%n", logHeader.logVersion, logHeader.lastCommittedTxId);
    PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
    ReadableLogChannel logChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    return new LogEntryCursor(logEntryReader, logChannel);
}
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) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) LogHeaderReader.readLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)

Example 7 with LogHeader

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

the class BackupServiceIT method checkPreviousCommittedTxIdFromLog.

private void checkPreviousCommittedTxIdFromLog(long logVersion, long txId) throws IOException {
    // Assert header of specified log version containing correct txId
    PhysicalLogFiles logFiles = new PhysicalLogFiles(backupDir, fileSystem);
    LogHeader logHeader = LogHeaderReader.readLogHeader(fileSystem, logFiles.getLogFileForVersion(logVersion));
    assertEquals(txId, logHeader.lastCommittedTxId);
}
Also used : LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 8 with LogHeader

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

the class PhysicalLogFile method createLogChannelForVersion.

/**
     * Creates a new channel for the specified version, creating the backing file if it doesn't already exist.
     * If the file exists then the header is verified to be of correct version. Having an existing file there
     * could happen after a previous crash in the middle of rotation, where the new file was created,
     * but the incremented log version changed hadn't made it to persistent storage.
     *
     * @param forVersion log version for the file/channel to create.
     * @return {@link PhysicalLogVersionedStoreChannel} for newly created/opened log file.
     * @throws IOException if there's any I/O related error.
     */
private PhysicalLogVersionedStoreChannel createLogChannelForVersion(long forVersion) throws IOException {
    File toOpen = logFiles.getLogFileForVersion(forVersion);
    StoreChannel storeChannel = fileSystem.open(toOpen, "rw");
    LogHeader header = readLogHeader(headerBuffer, storeChannel, false, toOpen);
    if (header == null) {
        // Either the header is not there in full or the file was new. Don't care
        long lastTxId = lastCommittedId.get();
        writeLogHeader(headerBuffer, forVersion, lastTxId);
        logHeaderCache.putHeader(forVersion, lastTxId);
        storeChannel.writeAll(headerBuffer);
        monitor.opened(toOpen, forVersion, lastTxId, true);
    }
    byte formatVersion = header == null ? CURRENT_LOG_VERSION : header.logFormatVersion;
    return new PhysicalLogVersionedStoreChannel(storeChannel, forVersion, formatVersion);
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) File(java.io.File) 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 9 with LogHeader

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

the class PhysicalLogFile method openForVersion.

public static PhysicalLogVersionedStoreChannel openForVersion(PhysicalLogFiles logFiles, FileSystemAbstraction fileSystem, long version, boolean write) throws IOException {
    final File fileToOpen = logFiles.getLogFileForVersion(version);
    if (!fileSystem.fileExists(fileToOpen)) {
        throw new FileNotFoundException(String.format("File does not exist [%s]", fileToOpen.getCanonicalPath()));
    }
    StoreChannel rawChannel = null;
    try {
        rawChannel = fileSystem.open(fileToOpen, write ? "rw" : "r");
        ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
        LogHeader header = readLogHeader(buffer, rawChannel, true, fileToOpen);
        assert header != null && header.logVersion == version;
        PhysicalLogVersionedStoreChannel result = new PhysicalLogVersionedStoreChannel(rawChannel, version, header.logFormatVersion);
        return result;
    } catch (FileNotFoundException cause) {
        throw Exceptions.withCause(new FileNotFoundException(String.format("File could not be opened [%s]", fileToOpen.getCanonicalPath())), cause);
    } catch (Throwable unexpectedError) {
        if (rawChannel != null) {
            // If we managed to open the file before failing, then close the channel
            try {
                rawChannel.close();
            } catch (IOException e) {
                unexpectedError.addSuppressed(e);
            }
        }
        throw unexpectedError;
    }
}
Also used : StoreChannel(org.neo4j.io.fs.StoreChannel) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) 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 10 with LogHeader

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

the class LogTestUtils method openLogEntryCursor.

private static LogEntryCursor openLogEntryCursor(FileSystemAbstraction fs, File firstFile, LogVersionBridge versionBridge) {
    StoreChannel channel = null;
    try {
        channel = fs.open(firstFile, "r");
        ByteBuffer buffer = ByteBuffer.allocate(LogHeader.LOG_HEADER_SIZE);
        LogHeader header = LogHeaderReader.readLogHeader(buffer, channel, true, firstFile);
        PhysicalLogVersionedStoreChannel logVersionedChannel = new PhysicalLogVersionedStoreChannel(channel, header.logVersion, header.logFormatVersion);
        ReadableLogChannel logChannel = new ReadAheadLogChannel(logVersionedChannel, versionBridge, ReadAheadLogChannel.DEFAULT_READ_AHEAD_SIZE);
        return new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
    } catch (Throwable t) {
        if (channel != null) {
            try {
                channel.close();
            } catch (IOException e) {
                t.addSuppressed(e);
            }
        }
        throw new RuntimeException(t);
    }
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ReadAheadLogChannel(org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel) LogEntryCursor(org.neo4j.kernel.impl.transaction.log.LogEntryCursor) 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)

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