Search in sources :

Example 31 with VersionAwareLogEntryReader

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

the class MigrationTestUtils method removeCheckPointFromTxLog.

public static void removeCheckPointFromTxLog(FileSystemAbstraction fileSystem, File workingDirectory) throws IOException {
    PhysicalLogFiles logFiles = new PhysicalLogFiles(workingDirectory, fileSystem);
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    LatestCheckPointFinder finder = new LatestCheckPointFinder(logFiles, fileSystem, logEntryReader);
    LatestCheckPointFinder.LatestCheckPoint latestCheckPoint = finder.find(logFiles.getHighestLogVersion());
    if (latestCheckPoint.commitsAfterCheckPoint) {
        // done already
        return;
    }
    // let's assume there is at least a checkpoint
    assertNotNull(latestCheckPoint.checkPoint);
    LogPosition logPosition = latestCheckPoint.checkPoint.getLogPosition();
    File logFile = logFiles.getLogFileForVersion(logPosition.getLogVersion());
    fileSystem.truncate(logFile, logPosition.getByteOffset());
}
Also used : LatestCheckPointFinder(org.neo4j.kernel.recovery.LatestCheckPointFinder) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) File(java.io.File) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 32 with VersionAwareLogEntryReader

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

the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.

private LogPosition getLastReadablePosition(Path logFile) throws IOException {
    VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    LogFile txLogFile = logFiles.getLogFile();
    long logVersion = txLogFile.getLogVersion(logFile);
    LogPosition startPosition = txLogFile.extractHeader(logVersion).getStartPosition();
    try (ReadableLogChannel reader = openTransactionFileChannel(logVersion, startPosition)) {
        while (entryReader.readLogEntry(reader) != null) {
        // scroll to the end of readable entries
        }
    } catch (IncompleteLogHeaderException e) {
        return new LogPosition(logVersion, 0);
    }
    return entryReader.lastPosition();
}
Also used : LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) IncompleteLogHeaderException(org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 33 with VersionAwareLogEntryReader

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

the class RecoveryCorruptedTransactionLogIT method getLastReadablePosition.

private LogPosition getLastReadablePosition(LogFile logFile) throws IOException {
    VersionAwareLogEntryReader entryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    LogPosition startPosition = logFile.extractHeader(logFiles.getLogFile().getHighestLogVersion()).getStartPosition();
    try (ReadableLogChannel reader = logFile.getReader(startPosition)) {
        while (entryReader.readLogEntry(reader) != null) {
        // scroll to the end of readable entries
        }
    }
    return entryReader.lastPosition();
}
Also used : ReadableLogChannel(org.neo4j.kernel.impl.transaction.log.ReadableLogChannel) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 34 with VersionAwareLogEntryReader

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

the class LogVersionUpgradeCheckerIT method appendCheckpoint.

private void appendCheckpoint(byte logEntryVersion, boolean removeCheckpointFile) throws IOException {
    VersionAwareLogEntryReader logEntryReader = new VersionAwareLogEntryReader(StorageEngineFactory.defaultStorageEngine().commandReaderFactory());
    LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystem, pageCache).withLogEntryReader(logEntryReader).withStoreId(StoreId.UNKNOWN).build();
    if (removeCheckpointFile) {
        for (Path file : fileSystem.listFiles(logFiles.logFilesDirectory(), path -> path.getFileName().toString().startsWith(CHECKPOINT_FILE_PREFIX))) {
            fileSystem.deleteFile(file);
        }
    }
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogFile logFile = logFiles.getLogFile();
        TransactionLogWriter transactionLogWriter = logFile.getTransactionLogWriter();
        var channel = transactionLogWriter.getChannel();
        LogPosition logPosition = transactionLogWriter.getCurrentPosition();
        // Fake record
        channel.put(logEntryVersion).put(LEGACY_CHECK_POINT).putLong(logPosition.getLogVersion()).putLong(logPosition.getByteOffset());
        logFile.flush();
    }
}
Also used : Path(java.nio.file.Path) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Lifespan(org.neo4j.kernel.lifecycle.Lifespan)

Example 35 with VersionAwareLogEntryReader

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

the class Database method start.

/**
 * Start the database and make it ready for transaction processing.
 * A database will automatically recover itself, if necessary, when started.
 * If the store files are obsolete (older than oldest supported version), then start will throw an exception.
 */
@Override
public synchronized void start() {
    if (started) {
        return;
    }
    // Ensure we're initialized
    init();
    try {
        // Upgrade the store before we begin
        upgradeStore(databaseConfig, databasePageCache, otherDatabaseMemoryTracker);
        // Check the tail of transaction logs and validate version
        LogEntryReader logEntryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
        LogFiles logFiles = getLogFiles(logEntryReader);
        databaseMonitors.addMonitorListener(new LoggingLogFileMonitor(msgLog));
        databaseMonitors.addMonitorListener(new LoggingLogTailScannerMonitor(internalLogProvider.getLog(AbstractLogTailScanner.class)));
        databaseMonitors.addMonitorListener(new ReverseTransactionCursorLoggingMonitor(internalLogProvider.getLog(ReversedSingleFileTransactionCursor.class)));
        var pageCacheTracer = tracers.getPageCacheTracer();
        boolean storageExists = storageEngineFactory.storageExists(fs, databaseLayout, databasePageCache);
        validateStoreAndTxLogs(logFiles, pageCacheTracer, storageExists);
        performRecovery(fs, databasePageCache, tracers, databaseConfig, databaseLayout, storageEngineFactory, false, internalLogProvider, databaseMonitors, extensionFactories, Optional.of(logFiles), new RecoveryStartupChecker(startupController, namedDatabaseId), otherDatabaseMemoryTracker, clock);
        // Build all modules and their services
        DatabaseSchemaState databaseSchemaState = new DatabaseSchemaState(internalLogProvider);
        idController.initialize(() -> kernelModule.kernelTransactions().get());
        storageEngine = storageEngineFactory.instantiate(fs, databaseLayout, databaseConfig, databasePageCache, tokenHolders, databaseSchemaState, constraintSemantics, indexProviderMap, lockService, idGeneratorFactory, idController, databaseHealth, internalLogProvider, recoveryCleanupWorkCollector, pageCacheTracer, !storageExists, readOnlyDatabaseChecker, otherDatabaseMemoryTracker);
        MetadataProvider metadataProvider = storageEngine.metadataProvider();
        databaseDependencies.satisfyDependency(metadataProvider);
        // Recreate the logFiles after storage engine to get access to dependencies
        logFiles = getLogFiles(logEntryReader);
        life.add(storageEngine);
        life.add(storageEngine.schemaAndTokensLifecycle());
        life.add(logFiles);
        // Token indexes
        FullScanStoreView fullScanStoreView = new FullScanStoreView(lockService, storageEngine::newReader, databaseConfig, scheduler);
        IndexStoreViewFactory indexStoreViewFactory = new IndexStoreViewFactory(databaseConfig, storageEngine::newReader, locks, fullScanStoreView, lockService, internalLogProvider);
        // Schema indexes
        IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(databasePageCache, databaseLayout, recoveryCleanupWorkCollector, readOnlyDatabaseChecker, pageCacheTracer);
        IndexingService indexingService = buildIndexingService(storageEngine, databaseSchemaState, indexStoreViewFactory, indexStatisticsStore, pageCacheTracer, otherDatabaseMemoryTracker);
        databaseDependencies.satisfyDependency(storageEngine.countsAccessor());
        versionContextSupplier.init(metadataProvider::getLastClosedTransactionId);
        CheckPointerImpl.ForceOperation forceOperation = new DefaultForceOperation(indexingService, storageEngine);
        DatabaseTransactionLogModule transactionLogModule = buildTransactionLogs(logFiles, databaseConfig, internalLogProvider, scheduler, forceOperation, logEntryReader, metadataProvider, databaseMonitors, databaseDependencies);
        databaseTransactionEventListeners = new DatabaseTransactionEventListeners(databaseFacade, transactionEventListeners, namedDatabaseId);
        life.add(databaseTransactionEventListeners);
        final DatabaseKernelModule kernelModule = buildKernel(logFiles, transactionLogModule.transactionAppender(), indexingService, databaseSchemaState, storageEngine, metadataProvider, metadataProvider, databaseAvailabilityGuard, clock, indexStatisticsStore, leaseService);
        kernelModule.satisfyDependencies(databaseDependencies);
        // Do these assignments last so that we can ensure no cyclical dependencies exist
        this.kernelModule = kernelModule;
        databaseDependencies.satisfyDependency(databaseSchemaState);
        databaseDependencies.satisfyDependency(logEntryReader);
        databaseDependencies.satisfyDependency(storageEngine);
        databaseDependencies.satisfyDependency(indexingService);
        databaseDependencies.satisfyDependency(indexStoreViewFactory);
        databaseDependencies.satisfyDependency(indexStatisticsStore);
        databaseDependencies.satisfyDependency(indexProviderMap);
        databaseDependencies.satisfyDependency(forceOperation);
        databaseDependencies.satisfyDependency(new DatabaseEntityCounters(this.idGeneratorFactory, databaseDependencies.resolveDependency(CountsAccessor.class)));
        var providerSpi = QueryEngineProvider.spi(internalLogProvider, databaseMonitors, scheduler, life, getKernel(), databaseConfig);
        this.executionEngine = QueryEngineProvider.initialize(databaseDependencies, databaseFacade, engineProvider, isSystem(), providerSpi);
        this.checkpointerLifecycle = new CheckpointerLifecycle(transactionLogModule.checkPointer(), databaseHealth, ioController);
        life.add(databaseHealth);
        life.add(databaseAvailabilityGuard);
        life.add(databaseAvailability);
        life.setLast(checkpointerLifecycle);
        databaseDependencies.resolveDependency(DbmsDiagnosticsManager.class).dumpDatabaseDiagnostics(this);
        life.start();
        registerUpgradeListener();
        eventListeners.databaseStart(namedDatabaseId);
        /*
             * At this point recovery has completed and the database is ready for use. Whatever panic might have
             * happened before has been healed. So we can safely set the kernel health to ok.
             * This right now has any real effect only in the case of internal restarts (for example, after a store copy).
             * Standalone instances will have to be restarted by the user, as is proper for all database panics.
             */
        databaseHealth.healed();
        started = true;
        postStartupInit(storageExists);
    } catch (Throwable e) {
        handleStartupFailure(e);
    }
}
Also used : CheckPointerImpl(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointerImpl) RecoveryStartupChecker(org.neo4j.kernel.recovery.RecoveryStartupChecker) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) DbmsDiagnosticsManager(org.neo4j.kernel.diagnostics.providers.DbmsDiagnosticsManager) ReverseTransactionCursorLoggingMonitor(org.neo4j.kernel.impl.transaction.log.reverse.ReverseTransactionCursorLoggingMonitor) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) FullScanStoreView(org.neo4j.kernel.impl.transaction.state.storeview.FullScanStoreView) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LoggingLogFileMonitor(org.neo4j.kernel.impl.transaction.log.LoggingLogFileMonitor) CheckpointerLifecycle(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckpointerLifecycle) LoggingLogTailScannerMonitor(org.neo4j.kernel.recovery.LoggingLogTailScannerMonitor) DatabaseEntityCounters(org.neo4j.kernel.impl.store.stats.DatabaseEntityCounters) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) DatabaseTransactionEventListeners(org.neo4j.kernel.internal.event.DatabaseTransactionEventListeners)

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