Search in sources :

Example 1 with LatestCheckPointFinder

use of org.neo4j.kernel.recovery.LatestCheckPointFinder in project neo4j by neo4j.

the class UpgradableDatabase method checkCleanShutDownByCheckPoint.

private Result checkCleanShutDownByCheckPoint(File storeDirectory) {
    // check version
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDirectory, fs);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    LatestCheckPointFinder latestCheckPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    try {
        LatestCheckPoint latestCheckPoint = latestCheckPointFinder.find(logFiles.getHighestLogVersion());
        if (!latestCheckPoint.commitsAfterCheckPoint) {
            return new Result(Result.Outcome.ok, null, null);
        }
    } catch (IOException e) {
    // ignore exception and return db not cleanly shutdown
    }
    return new Result(Result.Outcome.storeNotCleanlyShutDown, null, null);
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) LatestCheckPoint(org.neo4j.kernel.recovery.LatestCheckPointFinder.LatestCheckPoint) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IOException(java.io.IOException) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Result(org.neo4j.kernel.impl.storemigration.StoreVersionCheck.Result)

Example 2 with LatestCheckPointFinder

use of org.neo4j.kernel.recovery.LatestCheckPointFinder 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 3 with LatestCheckPointFinder

use of org.neo4j.kernel.recovery.LatestCheckPointFinder 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 4 with LatestCheckPointFinder

use of org.neo4j.kernel.recovery.LatestCheckPointFinder in project neo4j by neo4j.

the class TransactionLogCatchUpWriterTest method verifyCheckpointInLog.

private void verifyCheckpointInLog() throws IOException {
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
    PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
    final LatestCheckPointFinder checkPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint checkPoint = checkPointFinder.find(0);
    assertNotNull(checkPoint.checkPoint);
    assertTrue(checkPoint.commitsAfterCheckPoint);
}
Also used : RecordStorageCommandReaderFactory(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageCommandReaderFactory) LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 5 with LatestCheckPointFinder

use of org.neo4j.kernel.recovery.LatestCheckPointFinder in project neo4j by neo4j.

the class NeoStoreDataSource method buildRecovery.

private void buildRecovery(final FileSystemAbstraction fileSystemAbstraction, TransactionIdStore transactionIdStore, LogVersionRepository logVersionRepository, Recovery.Monitor recoveryMonitor, PositionToRecoverFrom.Monitor positionMonitor, final PhysicalLogFiles logFiles, final StartupStatisticsProvider startupStatistics, StorageEngine storageEngine, LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader, LogicalTransactionStore logicalTransactionStore) {
    final LatestCheckPointFinder checkPointFinder = new LatestCheckPointFinder(logFiles, fileSystemAbstraction, logEntryReader);
    Recovery.SPI spi = new DefaultRecoverySPI(storageEngine, logFiles, fileSystemAbstraction, logVersionRepository, checkPointFinder, transactionIdStore, logicalTransactionStore, positionMonitor);
    Recovery recovery = new Recovery(spi, recoveryMonitor);
    monitors.addMonitorListener(new Recovery.Monitor() {

        @Override
        public void recoveryCompleted(int numberOfRecoveredTransactions) {
            startupStatistics.setNumberOfRecoveredTransactions(numberOfRecoveredTransactions);
        }
    });
    life.add(recovery);
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) DefaultRecoverySPI(org.neo4j.kernel.recovery.DefaultRecoverySPI) Recovery(org.neo4j.kernel.recovery.Recovery)

Aggregations

LatestCheckPointFinder (org.neo4j.kernel.recovery.LatestCheckPointFinder)8 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)7 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)7 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)6 File (java.io.File)4 IOException (java.io.IOException)4 DefaultRecoverySPI (org.neo4j.kernel.recovery.DefaultRecoverySPI)4 Recovery (org.neo4j.kernel.recovery.Recovery)4 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)3 LogFile (org.neo4j.kernel.impl.transaction.log.LogFile)3 LogHeaderCache (org.neo4j.kernel.impl.transaction.log.LogHeaderCache)3 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)3 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)3 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)3 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)3 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)3 StorageEngine (org.neo4j.storageengine.api.StorageEngine)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Consumer (java.util.function.Consumer)2 Test (org.junit.Test)2