Search in sources :

Example 6 with PhysicalLogFiles

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

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

the class PhysicalLogFilesTest method shouldReturnANegativeValueIfThereAreNoLogFiles.

@Test
public void shouldReturnANegativeValueIfThereAreNoLogFiles() {
    // given
    PhysicalLogFiles files = new PhysicalLogFiles(tmpDirectory, filename, fs);
    final File[] filesOnDisk = new File[] { new File(tmpDirectory, "crap" + DEFAULT_VERSION_SUFFIX + "4"), new File(tmpDirectory, filename) };
    when(fs.listFiles(tmpDirectory)).thenReturn(filesOnDisk);
    // when
    final long highestLogVersion = files.getHighestLogVersion();
    // then
    assertEquals(-1, highestLogVersion);
}
Also used : File(java.io.File) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 8 with PhysicalLogFiles

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

the class PhysicalLogFilesTest method shouldBeAbleToRetrieveTheHighestLogVersion.

@Test
public void shouldBeAbleToRetrieveTheHighestLogVersion() {
    // given
    PhysicalLogFiles files = new PhysicalLogFiles(tmpDirectory, filename, fs);
    final File[] filesOnDisk = new File[] { new File(tmpDirectory, filename + DEFAULT_VERSION_SUFFIX + "1"), new File(tmpDirectory, "crap" + DEFAULT_VERSION_SUFFIX + "4"), new File(tmpDirectory, filename + DEFAULT_VERSION_SUFFIX + "3"), new File(tmpDirectory, filename) };
    when(fs.listFiles(tmpDirectory)).thenReturn(filesOnDisk);
    // when
    final long highestLogVersion = files.getHighestLogVersion();
    // then
    assertEquals(3, highestLogVersion);
}
Also used : File(java.io.File) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Test(org.junit.Test)

Example 9 with PhysicalLogFiles

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

the class LatestCheckPointFinderTest method setUp.

@Before
public void setUp() {
    fsRule.get().mkdirs(directory);
    logFiles = new PhysicalLogFiles(directory, fsRule.get());
    finder = new LatestCheckPointFinder(logFiles, fsRule.get(), reader);
}
Also used : PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) Before(org.junit.Before)

Example 10 with PhysicalLogFiles

use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles 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

PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)53 File (java.io.File)38 Test (org.junit.Test)29 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)29 Command (org.neo4j.kernel.impl.transaction.command.Command)15 IOException (java.io.IOException)14 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)12 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)11 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)9 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)7 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)6 TransactionLogWriter (org.neo4j.kernel.impl.transaction.log.TransactionLogWriter)6 Function (java.util.function.Function)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Rule (org.junit.Rule)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5