Search in sources :

Example 6 with PhysicalLogVersionedStoreChannel

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

the class LogMatchers method logEntries.

public static List<LogEntry> logEntries(FileSystemAbstraction fileSystem, String logPath) throws IOException {
    File logFile = new File(logPath);
    StoreChannel fileChannel = fileSystem.open(logFile, "r");
    // Always a header
    LogHeader header = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, true, logFile);
    // Read all log entries
    PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileChannel, header.logVersion, header.logFormatVersion);
    ReadableLogChannel logChannel = new ReadAheadLogChannel(versionedStoreChannel, NO_MORE_CHANNELS);
    LogEntryCursor logEntryCursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
    return Iterables.asList(new IOCursorAsResourceIterable<>(logEntryCursor));
}
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) 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)

Example 7 with PhysicalLogVersionedStoreChannel

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

the class LegacyLogEntryReader method openReadableChannel.

public Pair<LogHeader, IOCursor<LogEntry>> openReadableChannel(File logFile) throws IOException {
    final StoreChannel rawChannel = fs.open(logFile, "r");
    final LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), rawChannel, false, logFile);
    LogEntryReader<ReadableLogChannel> reader = readerFactory.apply(header);
    // this ensures that the last committed txId field in the header is initialized properly
    long lastCommittedTxId = Math.max(BASE_TX_ID, header.lastCommittedTxId);
    final PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(rawChannel, header.logVersion, header.logFormatVersion);
    final ReadableLogChannel readableChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
    final IOCursor<LogEntry> cursor = new LogEntrySortingCursor(reader, readableChannel);
    return Pair.of(new LogHeader(CURRENT_LOG_VERSION, header.logVersion, lastCommittedTxId), cursor);
}
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) 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)

Example 8 with PhysicalLogVersionedStoreChannel

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

the class CheckTxLogsTest method writeContent.

private void writeContent(File log, ThrowingConsumer<TransactionLogWriter, IOException> consumer) throws IOException {
    FileSystemAbstraction fs = ensureLogExists(log);
    try (StoreChannel channel = fs.open(log, "rw");
        LogVersionedStoreChannel versionedChannel = new PhysicalLogVersionedStoreChannel(channel, 0, (byte) 0);
        PhysicalFlushableChannel writableLogChannel = new PhysicalFlushableChannel(versionedChannel)) {
        long offset = channel.size();
        channel.position(offset);
        consumer.accept(new TransactionLogWriter(new LogEntryWriter(writableLogChannel)));
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PhysicalFlushableChannel) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) TransactionLogWriter(org.neo4j.kernel.impl.transaction.log.TransactionLogWriter) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)

Example 9 with PhysicalLogVersionedStoreChannel

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

the class LegacyLogEntryWriter method openWritableChannel.

public LogVersionedStoreChannel openWritableChannel(File file) throws IOException {
    final StoreChannel storeChannel = fs.open(file, "rw");
    final long version = getLegacyLogVersion(file.getName());
    return new PhysicalLogVersionedStoreChannel(storeChannel, version, CURRENT_LOG_VERSION);
}
Also used : LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)

Example 10 with PhysicalLogVersionedStoreChannel

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

the class RecoveryTest method writeSomeData.

private void writeSomeData(File file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor) throws IOException {
    try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystemRule.get().open(file, "rw"), logVersion, CURRENT_LOG_VERSION);
        final PositionAwarePhysicalFlushableChannel writableLogChannel = new PositionAwarePhysicalFlushableChannel(versionedStoreChannel)) {
        writeLogHeader(writableLogChannel, logVersion, 2L);
        Consumer<LogPositionMarker> consumer = marker -> {
            try {
                writableLogChannel.getCurrentPosition(marker);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        };
        LogEntryWriter first = new LogEntryWriter(writableLogChannel);
        visitor.visit(Pair.of(first, consumer));
    }
}
Also used : LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) Assert.fail(org.junit.Assert.fail) DefaultRecoverySPI(org.neo4j.kernel.recovery.DefaultRecoverySPI) BASE_TX_COMMIT_TIMESTAMP(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP) Recovery(org.neo4j.kernel.recovery.Recovery) StorageEngine(org.neo4j.storageengine.api.StorageEngine) LogVersionRepository(org.neo4j.kernel.impl.transaction.log.LogVersionRepository) CURRENT_LOG_VERSION(org.neo4j.kernel.impl.transaction.log.entry.LogVersions.CURRENT_LOG_VERSION) TestDirectory(org.neo4j.test.rule.TestDirectory) DeadSimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.DeadSimpleLogVersionRepository) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) LogEntryStart(org.neo4j.kernel.impl.transaction.log.entry.LogEntryStart) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Matchers.any(org.mockito.Matchers.any) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) Mockito.inOrder(org.mockito.Mockito.inOrder) LogEntry(org.neo4j.kernel.impl.transaction.log.entry.LogEntry) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) Mockito.mock(org.mockito.Mockito.mock) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Pair(org.neo4j.helpers.collection.Pair) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) PositionAwarePhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChannel) NO_MONITOR(org.neo4j.kernel.recovery.PositionToRecoverFrom.NO_MONITOR) InOrder(org.mockito.InOrder) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) OnePhaseCommit(org.neo4j.kernel.impl.transaction.log.entry.OnePhaseCommit) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) File(java.io.File) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) DefaultFileSystemRule(org.neo4j.test.rule.fs.DefaultFileSystemRule) Visitor(org.neo4j.helpers.collection.Visitor) Assert.assertEquals(org.junit.Assert.assertEquals) LogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) PositionAwarePhysicalFlushableChannel(org.neo4j.kernel.impl.transaction.log.PositionAwarePhysicalFlushableChannel) PhysicalLogVersionedStoreChannel(org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) IOException(java.io.IOException) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker)

Aggregations

PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)12 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.LogVersionedStoreChannel)7 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)7 File (java.io.File)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)5 LogHeaderReader.readLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderReader.readLogHeader)5 Test (org.junit.Test)4 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)4 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)4 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)4 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)4 LogHeaderWriter.writeLogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader)3 LogVersionBridge (org.neo4j.kernel.impl.transaction.log.LogVersionBridge)2 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)2 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)2 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1