Search in sources :

Example 1 with VersionAwareLogEntryReader

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

the class RecoveryTest method recover.

private boolean recover(PhysicalLogFiles logFiles) {
    LifeSupport life = new LifeSupport();
    Recovery.Monitor monitor = mock(Recovery.Monitor.class);
    final AtomicBoolean recoveryRequired = new AtomicBoolean();
    try {
        StorageEngine storageEngine = mock(StorageEngine.class);
        final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
        LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystemRule.get(), reader);
        TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
        LogHeaderCache logHeaderCache = new LogHeaderCache(10);
        LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 50, () -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository, mock(PhysicalLogFile.Monitor.class), logHeaderCache));
        LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, metadataCache, reader);
        life.add(new Recovery(new DefaultRecoverySPI(storageEngine, logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore, NO_MONITOR) {

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
                recoveryRequired.set(true);
                return super.startRecovery();
            }
        }, monitor));
        life.start();
    } finally {
        life.shutdown();
    }
    return recoveryRequired.get();
}
Also used : PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) DefaultRecoverySPI(org.neo4j.kernel.recovery.DefaultRecoverySPI) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Recovery(org.neo4j.kernel.recovery.Recovery) IOException(java.io.IOException) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)

Example 2 with VersionAwareLogEntryReader

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

the class RecoveryTest method shouldSeeThatACleanDatabaseShouldNotRequireRecovery.

@Test
public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception {
    final PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), "log", fileSystemRule.get());
    File file = logFiles.getLogFileForVersion(logVersion);
    writeSomeData(file, new Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException>() {

        @Override
        public boolean visit(Pair<LogEntryWriter, Consumer<LogPositionMarker>> pair) throws IOException {
            LogEntryWriter writer = pair.first();
            Consumer<LogPositionMarker> consumer = pair.other();
            LogPositionMarker marker = new LogPositionMarker();
            // last committed tx
            consumer.accept(marker);
            writer.writeStartEntry(0, 1, 2L, 3L, new byte[0]);
            writer.writeCommitEntry(4L, 5L);
            // check point
            consumer.accept(marker);
            writer.writeCheckPointEntry(marker.newPosition());
            return true;
        }
    });
    LifeSupport life = new LifeSupport();
    Recovery.Monitor monitor = mock(Recovery.Monitor.class);
    try {
        StorageEngine storageEngine = mock(StorageEngine.class);
        final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
        LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystemRule.get(), reader);
        TransactionMetadataCache metadataCache = new TransactionMetadataCache(100);
        LogHeaderCache logHeaderCache = new LogHeaderCache(10);
        LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 50, () -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository, mock(PhysicalLogFile.Monitor.class), logHeaderCache));
        LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, metadataCache, reader);
        life.add(new Recovery(new DefaultRecoverySPI(storageEngine, logFiles, fileSystemRule.get(), logVersionRepository, finder, transactionIdStore, txStore, NO_MONITOR) {

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
                fail("Recovery should not be required");
                // <-- to satisfy the compiler
                return null;
            }
        }, monitor));
        life.start();
        verifyZeroInteractions(monitor);
    } finally {
        life.shutdown();
    }
}
Also used : DefaultRecoverySPI(org.neo4j.kernel.recovery.DefaultRecoverySPI) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Recovery(org.neo4j.kernel.recovery.Recovery) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) LogPositionMarker(org.neo4j.kernel.impl.transaction.log.LogPositionMarker) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Consumer(java.util.function.Consumer) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogEntryWriter(org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter) Pair(org.neo4j.helpers.collection.Pair) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) IOException(java.io.IOException) IOException(java.io.IOException) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Test(org.junit.Test)

Example 3 with VersionAwareLogEntryReader

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

the class HighAvailabilitySlavesTest method shouldSupportConcurrentConsumptionOfSlaves.

@Test
public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception {
    // Given
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(clusterMembersOfSize(1000), mock(Cluster.class), new DefaultSlaveFactory(NullLogProvider.getInstance(), new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0));
    // When
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executor.submit(slavesConsumingRunnable(haSlaves));
    }
    executor.shutdown();
    executor.awaitTermination(30, SECONDS);
    // Then
    int slavesCount = 0;
    LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", LifeSupport.class);
    for (Lifecycle lifecycle : life.getLifecycleInstances()) {
        if (lifecycle instanceof Slave) {
            slavesCount++;
        }
    }
    // One instance is master
    assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Slave(org.neo4j.kernel.ha.com.master.Slave) Monitors(org.neo4j.kernel.monitoring.Monitors) ExecutorService(java.util.concurrent.ExecutorService) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 4 with VersionAwareLogEntryReader

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

Example 5 with VersionAwareLogEntryReader

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

Aggregations

VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)39 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)18 ReadableLogChannel (org.neo4j.kernel.impl.transaction.log.ReadableLogChannel)9 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)9 IOException (java.io.IOException)8 ReadAheadLogChannel (org.neo4j.kernel.impl.transaction.log.ReadAheadLogChannel)8 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)8 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)8 File (java.io.File)7 Test (org.junit.Test)7 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)7 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)7 LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)7 LogEntryCursor (org.neo4j.kernel.impl.transaction.log.LogEntryCursor)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)5 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)5 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4