Search in sources :

Example 21 with StorageEngine

use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.

the class DatabaseFileListingTest method shouldCloseIndexSnapshots.

@Test
void shouldCloseIndexSnapshots() throws Exception {
    // Given
    IndexingService indexingService = mock(IndexingService.class);
    DatabaseLayout databaseLayout = mock(DatabaseLayout.class);
    when(databaseLayout.metadataStore()).thenReturn(mock(Path.class));
    LogFiles logFiles = mock(LogFiles.class);
    filesInStoreDirAre(databaseLayout, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES);
    StorageEngine storageEngine = mock(StorageEngine.class);
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    DatabaseFileListing fileListing = new DatabaseFileListing(databaseLayout, logFiles, indexingService, storageEngine, idGeneratorFactory);
    ResourceIterator<Path> indexSnapshot = indexFilesAre(indexingService, new String[] { "schema/index/my.index" });
    ResourceIterator<StoreFileMetadata> result = fileListing.builder().excludeLogFiles().build();
    // When
    result.close();
    // Then
    verify(indexSnapshot).close();
}
Also used : Path(java.nio.file.Path) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.jupiter.api.Test)

Example 22 with StorageEngine

use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.

the class DbmsDiagnosticsManager method dumpDatabaseDiagnostics.

private static void dumpDatabaseDiagnostics(Database database, Log log, boolean checkStatus) {
    dumpAsSingleMessageWithDbPrefix(log, stringJoiner -> {
        dumpDatabaseSectionName(database, stringJoiner::add);
        if (checkStatus) {
            logDatabaseStatus(database, stringJoiner::add);
            if (!database.isStarted()) {
                return;
            }
        }
        Dependencies databaseResolver = database.getDependencyResolver();
        DbmsInfo dbmsInfo = databaseResolver.resolveDependency(DbmsInfo.class);
        FileSystemAbstraction fs = databaseResolver.resolveDependency(FileSystemAbstraction.class);
        StorageEngineFactory storageEngineFactory = databaseResolver.resolveDependency(StorageEngineFactory.class);
        StorageEngine storageEngine = databaseResolver.resolveDependency(StorageEngine.class);
        DiagnosticsManager.dump(new VersionDiagnostics(dbmsInfo, database.getStoreId()), log, stringJoiner::add);
        DiagnosticsManager.dump(new StoreFilesDiagnostics(storageEngineFactory, fs, database.getDatabaseLayout()), log, stringJoiner::add);
        DiagnosticsManager.dump(new TransactionRangeDiagnostics(database), log, stringJoiner::add);
        storageEngine.dumpDiagnostics(log, stringJoiner::add);
    }, database.getNamedDatabaseId());
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) DbmsInfo(org.neo4j.kernel.impl.factory.DbmsInfo) Dependencies(org.neo4j.collection.Dependencies) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 23 with StorageEngine

use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.

the class KernelTransactionsTest method newKernelTransactions.

private KernelTransactions newKernelTransactions(boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, Config config, StorageReader... otherReaders) throws Throwable {
    Locks locks = mock(Locks.class);
    Locks.Client client = mock(Locks.Client.class);
    when(locks.newClient()).thenReturn(client);
    StorageEngine storageEngine = mock(StorageEngine.class);
    when(storageEngine.newReader()).thenReturn(firstReader, otherReaders);
    when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
    doAnswer(invocation -> {
        Collection<StorageCommand> argument = invocation.getArgument(0);
        argument.add(mock(StorageCommand.class));
        return null;
    }).when(storageEngine).createCommands(anyCollection(), any(ReadableTransactionState.class), any(StorageReader.class), any(CommandCreationContext.class), any(ResourceLocker.class), any(LockTracer.class), anyLong(), any(TxStateVisitor.Decorator.class), any(CursorContext.class), any(MemoryTracker.class));
    return newKernelTransactions(locks, storageEngine, commitProcess, testKernelTransactions, config);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ResourceLocker(org.neo4j.lock.ResourceLocker) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) Locks(org.neo4j.kernel.impl.locking.Locks) LockTracer(org.neo4j.lock.LockTracer) CursorContext(org.neo4j.io.pagecache.context.CursorContext) StorageEngine(org.neo4j.storageengine.api.StorageEngine) MemoryTracker(org.neo4j.memory.MemoryTracker) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext)

Example 24 with StorageEngine

use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.

the class Recovery method performRecovery.

/**
 * Performs recovery of database described by provided layout.
 *
 * @param fs database filesystem
 * @param pageCache page cache used to perform database recovery.
 * @param tracers underlying operation tracers
 * @param config custom configuration
 * @param databaseLayout database to recover layout.
 * @param storageEngineFactory {@link StorageEngineFactory} for the storage to recover.
 * @param logProvider log provider
 * @param globalMonitors global server monitors
 * @param extensionFactories extension factories for extensions that should participate in recovery
 * @param providedLogFiles log files from database
 * @param forceRunRecovery to force recovery to run even if the usual checks indicates that it's not required.
 * In specific cases, like after store copy there's always a need for doing a recovery or at least to start the db, checkpoint and shut down,
 * even if the normal "is recovery required" checks says that recovery isn't required.
 * @throws IOException on any unexpected I/O exception encountered during recovery.
 */
public static void performRecovery(FileSystemAbstraction fs, PageCache pageCache, DatabaseTracers tracers, Config config, DatabaseLayout databaseLayout, StorageEngineFactory storageEngineFactory, boolean forceRunRecovery, LogProvider logProvider, Monitors globalMonitors, Iterable<ExtensionFactory<?>> extensionFactories, Optional<LogFiles> providedLogFiles, RecoveryStartupChecker startupChecker, MemoryTracker memoryTracker, Clock clock) throws IOException {
    Log recoveryLog = logProvider.getLog(Recovery.class);
    if (!forceRunRecovery && !isRecoveryRequired(fs, pageCache, databaseLayout, storageEngineFactory, config, providedLogFiles, memoryTracker)) {
        return;
    }
    checkAllFilesPresence(databaseLayout, fs, pageCache, storageEngineFactory);
    LifeSupport recoveryLife = new LifeSupport();
    Monitors monitors = new Monitors(globalMonitors, logProvider);
    DatabasePageCache databasePageCache = new DatabasePageCache(pageCache, IOController.DISABLED);
    SimpleLogService logService = new SimpleLogService(logProvider);
    VersionAwareLogEntryReader logEntryReader = new VersionAwareLogEntryReader(storageEngineFactory.commandReaderFactory());
    DatabaseReadOnlyChecker readOnlyChecker = writable();
    DatabaseSchemaState schemaState = new DatabaseSchemaState(logProvider);
    JobScheduler scheduler = JobSchedulerFactory.createInitialisedScheduler();
    VersionContextSupplier versionContextSupplier = EmptyVersionContextSupplier.EMPTY;
    DatabaseHealth databaseHealth = new DatabaseHealth(PanicEventGenerator.NO_OP, recoveryLog);
    TokenHolders tokenHolders = new TokenHolders(new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_PROPERTY_KEY), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_LABEL), new DelegatingTokenHolder(new ReadOnlyTokenCreator(), TYPE_RELATIONSHIP_TYPE));
    RecoveryCleanupWorkCollector recoveryCleanupCollector = new GroupingRecoveryCleanupWorkCollector(scheduler, INDEX_CLEANUP, INDEX_CLEANUP_WORK, databaseLayout.getDatabaseName());
    DatabaseExtensions extensions = instantiateRecoveryExtensions(databaseLayout, fs, config, logService, databasePageCache, scheduler, DbmsInfo.TOOL, monitors, tokenHolders, recoveryCleanupCollector, readOnlyChecker, extensionFactories, tracers.getPageCacheTracer());
    DefaultIndexProviderMap indexProviderMap = new DefaultIndexProviderMap(extensions, config);
    StorageEngine storageEngine = storageEngineFactory.instantiate(fs, databaseLayout, config, databasePageCache, tokenHolders, schemaState, getConstraintSemantics(), indexProviderMap, NO_LOCK_SERVICE, new DefaultIdGeneratorFactory(fs, recoveryCleanupCollector, databaseLayout.getDatabaseName()), new DefaultIdController(), databaseHealth, logService.getInternalLogProvider(), recoveryCleanupCollector, tracers.getPageCacheTracer(), true, readOnlyChecker, memoryTracker);
    // Schema indexes
    FullScanStoreView fullScanStoreView = new FullScanStoreView(NO_LOCK_SERVICE, storageEngine::newReader, config, scheduler);
    IndexStoreViewFactory indexStoreViewFactory = new IndexStoreViewFactory(config, storageEngine::newReader, NO_LOCKS, fullScanStoreView, NO_LOCK_SERVICE, logProvider);
    IndexStatisticsStore indexStatisticsStore = new IndexStatisticsStore(databasePageCache, databaseLayout, recoveryCleanupCollector, readOnlyChecker, tracers.getPageCacheTracer());
    IndexingService indexingService = Database.buildIndexingService(storageEngine, schemaState, indexStoreViewFactory, indexStatisticsStore, config, scheduler, indexProviderMap, tokenHolders, logProvider, logProvider, monitors.newMonitor(IndexingService.Monitor.class), tracers.getPageCacheTracer(), memoryTracker, databaseLayout.getDatabaseName(), readOnlyChecker);
    MetadataProvider metadataProvider = storageEngine.metadataProvider();
    Dependencies dependencies = new Dependencies();
    dependencies.satisfyDependencies(databaseLayout, config, databasePageCache, fs, logProvider, tokenHolders, schemaState, getConstraintSemantics(), NO_LOCK_SERVICE, databaseHealth, new DefaultIdGeneratorFactory(fs, recoveryCleanupCollector, databaseLayout.getDatabaseName()), new DefaultIdController(), readOnlyChecker, versionContextSupplier, logService, metadataProvider);
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(logEntryReader).withConfig(config).withDependencies(dependencies).withMemoryTracker(memoryTracker).build();
    boolean failOnCorruptedLogFiles = config.get(GraphDatabaseInternalSettings.fail_on_corrupted_log_files);
    validateStoreId(logFiles, storageEngine.getStoreId(), config);
    TransactionMetadataCache metadataCache = new TransactionMetadataCache();
    PhysicalLogicalTransactionStore transactionStore = new PhysicalLogicalTransactionStore(logFiles, metadataCache, logEntryReader, monitors, failOnCorruptedLogFiles);
    BatchingTransactionAppender transactionAppender = new BatchingTransactionAppender(logFiles, LogRotation.NO_ROTATION, metadataCache, metadataProvider, databaseHealth);
    LifeSupport schemaLife = new LifeSupport();
    schemaLife.add(storageEngine.schemaAndTokensLifecycle());
    schemaLife.add(indexingService);
    var doParallelRecovery = config.get(GraphDatabaseInternalSettings.do_parallel_recovery);
    TransactionLogsRecovery transactionLogsRecovery = transactionLogRecovery(fs, metadataProvider, monitors.newMonitor(RecoveryMonitor.class), monitors.newMonitor(RecoveryStartInformationProvider.Monitor.class), logFiles, storageEngine, transactionStore, metadataProvider, schemaLife, databaseLayout, failOnCorruptedLogFiles, recoveryLog, startupChecker, tracers.getPageCacheTracer(), memoryTracker, doParallelRecovery);
    CheckPointerImpl.ForceOperation forceOperation = new DefaultForceOperation(indexingService, storageEngine);
    var checkpointAppender = logFiles.getCheckpointFile().getCheckpointAppender();
    CheckPointerImpl checkPointer = new CheckPointerImpl(metadataProvider, RecoveryThreshold.INSTANCE, forceOperation, LogPruning.NO_PRUNING, checkpointAppender, databaseHealth, logProvider, tracers, IOController.DISABLED, new StoreCopyCheckPointMutex(), versionContextSupplier, clock);
    recoveryLife.add(scheduler);
    recoveryLife.add(recoveryCleanupCollector);
    recoveryLife.add(extensions);
    recoveryLife.add(indexProviderMap);
    recoveryLife.add(storageEngine);
    recoveryLife.add(new MissingTransactionLogsCheck(databaseLayout, config, fs, logFiles, recoveryLog));
    recoveryLife.add(logFiles);
    recoveryLife.add(transactionLogsRecovery);
    recoveryLife.add(transactionAppender);
    recoveryLife.add(checkPointer);
    try {
        recoveryLife.start();
        if (databaseHealth.isHealthy()) {
            checkPointer.forceCheckPoint(new SimpleTriggerInfo("Recovery completed."));
        }
    } finally {
        recoveryLife.shutdown();
    }
}
Also used : DatabaseHealth(org.neo4j.monitoring.DatabaseHealth) CheckPointerImpl(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointerImpl) SimpleLogService(org.neo4j.logging.internal.SimpleLogService) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) BatchingTransactionAppender(org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender) RecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector) GroupingRecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.GroupingRecoveryCleanupWorkCollector) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StorageEngineFactory.selectStorageEngine(org.neo4j.storageengine.api.StorageEngineFactory.selectStorageEngine) DatabasePageCache(org.neo4j.dbms.database.DatabasePageCache) VersionContextSupplier(org.neo4j.io.pagecache.context.VersionContextSupplier) EmptyVersionContextSupplier(org.neo4j.io.pagecache.context.EmptyVersionContextSupplier) DefaultIdController(org.neo4j.internal.id.DefaultIdController) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) DatabaseSchemaState(org.neo4j.kernel.impl.api.DatabaseSchemaState) FullScanStoreView(org.neo4j.kernel.impl.transaction.state.storeview.FullScanStoreView) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) StoreCopyCheckPointMutex(org.neo4j.kernel.impl.transaction.log.checkpoint.StoreCopyCheckPointMutex) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) Dependencies(org.neo4j.collection.Dependencies) TokenHolders(org.neo4j.token.TokenHolders) DelegatingTokenHolder(org.neo4j.token.DelegatingTokenHolder) JobScheduler(org.neo4j.scheduler.JobScheduler) PhysicalLogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore) NullLog(org.neo4j.logging.NullLog) Log(org.neo4j.logging.Log) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) DatabaseExtensions(org.neo4j.kernel.extension.DatabaseExtensions) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) GroupingRecoveryCleanupWorkCollector(org.neo4j.index.internal.gbptree.GroupingRecoveryCleanupWorkCollector) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) MetadataProvider(org.neo4j.storageengine.api.MetadataProvider) Monitors(org.neo4j.monitoring.Monitors) DefaultForceOperation(org.neo4j.kernel.database.DefaultForceOperation) ReadOnlyTokenCreator(org.neo4j.token.ReadOnlyTokenCreator)

Example 25 with StorageEngine

use of org.neo4j.storageengine.api.StorageEngine in project neo4j by neo4j.

the class KernelTransactionFactory method kernelTransactionWithInternals.

private static Instances kernelTransactionWithInternals(LoginContext loginContext) {
    StorageEngine storageEngine = mock(StorageEngine.class);
    StorageReader storageReader = mock(StorageReader.class);
    when(storageEngine.newReader()).thenReturn(storageReader);
    when(storageEngine.newCommandCreationContext(any())).thenReturn(mock(CommandCreationContext.class));
    Dependencies dependencies = new Dependencies();
    dependencies.satisfyDependency(mock(GraphDatabaseFacade.class));
    KernelTransactionImplementation transaction = new KernelTransactionImplementation(Config.defaults(), mock(DatabaseTransactionEventListeners.class), mock(ConstraintIndexCreator.class), mock(GlobalProcedures.class), mock(InternalTransactionCommitProcess.class), mock(TransactionMonitor.class), mock(Pool.class), Clocks.nanoClock(), new AtomicReference<>(CpuClock.NOT_AVAILABLE), mock(DatabaseTracers.class, RETURNS_MOCKS), storageEngine, any -> CanWrite.INSTANCE, EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock(SchemaState.class), mockedTokenHolders(), mock(IndexingService.class), mock(IndexStatisticsStore.class), dependencies, new TestDatabaseIdRepository().defaultDatabase(), LeaseService.NO_LEASES, MemoryPools.NO_TRACKING, DatabaseReadOnlyChecker.writable(), TransactionExecutionMonitor.NO_OP, CommunitySecurityLog.NULL_LOG, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
    transaction.initialize(0, 0, new NoOpClient(), KernelTransaction.Type.IMPLICIT, loginContext.authorize(LoginContext.IdLookup.EMPTY, DEFAULT_DATABASE_NAME, CommunitySecurityLog.NULL_LOG), 0L, 1L, EMBEDDED_CONNECTION);
    return new Instances(transaction);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) DatabaseTracers(org.neo4j.kernel.database.DatabaseTracers) DbmsRuntimeRepository(org.neo4j.dbms.database.DbmsRuntimeRepository) StorageEngine(org.neo4j.storageengine.api.StorageEngine) TestDatabaseIdRepository(org.neo4j.kernel.database.TestDatabaseIdRepository) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) CommandCreationContext(org.neo4j.storageengine.api.CommandCreationContext) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaState(org.neo4j.internal.schema.SchemaState) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) DatabaseTransactionEventListeners(org.neo4j.kernel.internal.event.DatabaseTransactionEventListeners) Pool(org.neo4j.collection.pool.Pool) Dependencies(org.neo4j.collection.Dependencies) InternalTransactionCommitProcess(org.neo4j.kernel.impl.api.InternalTransactionCommitProcess) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Aggregations

StorageEngine (org.neo4j.storageengine.api.StorageEngine)30 IOException (java.io.IOException)9 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)9 PhysicalLogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.PhysicalLogicalTransactionStore)8 TransactionMetadataCache (org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache)8 Test (org.junit.Test)7 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)7 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)7 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)7 Test (org.junit.jupiter.api.Test)6 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)6 TestableTransactionAppender (org.neo4j.kernel.impl.transaction.log.TestableTransactionAppender)6 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)6 Dependencies (org.neo4j.collection.Dependencies)5 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)4 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)4 Log (org.neo4j.logging.Log)4 File (java.io.File)3