Search in sources :

Example 1 with DatabaseAvailability

use of org.neo4j.kernel.availability.DatabaseAvailability in project neo4j by neo4j.

the class Database method init.

/**
 * Initialize the database, and bring it to a state where its version can be examined, and it can be
 * upgraded if necessary.
 */
@Override
public synchronized void init() {
    if (initialized) {
        return;
    }
    try {
        databaseDependencies = new Dependencies(globalDependencies);
        ioController = ioControllerService.createIOController(databaseConfig, clock);
        databasePageCache = new DatabasePageCache(globalPageCache, ioController);
        databaseMonitors = new Monitors(parentMonitors, internalLogProvider);
        life = new LifeSupport();
        life.add(new LockerLifecycleAdapter(fileLockerService.createDatabaseLocker(fs, databaseLayout)));
        life.add(databaseConfig);
        databaseHealth = databaseHealthFactory.newInstance();
        databaseAvailability = new DatabaseAvailability(databaseAvailabilityGuard, transactionStats, clock, getAwaitActiveTransactionDeadlineMillis());
        databaseDependencies.satisfyDependency(this);
        databaseDependencies.satisfyDependency(ioController);
        databaseDependencies.satisfyDependency(readOnlyDatabaseChecker);
        databaseDependencies.satisfyDependency(databaseLayout);
        databaseDependencies.satisfyDependency(startupController);
        databaseDependencies.satisfyDependency(databaseConfig);
        databaseDependencies.satisfyDependency(databaseMonitors);
        databaseDependencies.satisfyDependency(databaseLogService);
        databaseDependencies.satisfyDependency(databasePageCache);
        databaseDependencies.satisfyDependency(tokenHolders);
        databaseDependencies.satisfyDependency(databaseFacade);
        databaseDependencies.satisfyDependency(kernelTransactionFactory);
        databaseDependencies.satisfyDependency(databaseHealth);
        databaseDependencies.satisfyDependency(storeCopyCheckPointMutex);
        databaseDependencies.satisfyDependency(transactionStats);
        databaseDependencies.satisfyDependency(locks);
        databaseDependencies.satisfyDependency(databaseAvailabilityGuard);
        databaseDependencies.satisfyDependency(databaseAvailability);
        databaseDependencies.satisfyDependency(idGeneratorFactory);
        databaseDependencies.satisfyDependency(idController);
        databaseDependencies.satisfyDependency(lockService);
        databaseDependencies.satisfyDependency(versionContextSupplier);
        databaseDependencies.satisfyDependency(tracers.getDatabaseTracer());
        databaseDependencies.satisfyDependency(tracers.getPageCacheTracer());
        databaseDependencies.satisfyDependency(storageEngineFactory);
        recoveryCleanupWorkCollector = RecoveryCleanupWorkCollector.immediate();
        databaseDependencies.satisfyDependency(recoveryCleanupWorkCollector);
        life.add(new PageCacheLifecycle(databasePageCache));
        life.add(initializeExtensions(databaseDependencies));
        DatabaseLayoutWatcher watcherService = watcherServiceFactory.apply(databaseLayout);
        life.add(watcherService);
        databaseDependencies.satisfyDependency(watcherService);
        otherDatabasePool = otherMemoryPool.newDatabasePool(namedDatabaseId.name(), 0, null);
        life.add(onShutdown(() -> otherDatabasePool.close()));
        otherDatabaseMemoryTracker = otherDatabasePool.getPoolMemoryTracker();
        databaseDependencies.satisfyDependency(new DatabaseMemoryTrackers(otherDatabaseMemoryTracker));
        eventListeners.databaseCreate(namedDatabaseId);
        initialized = true;
    } catch (Throwable e) {
        handleStartupFailure(e);
    }
}
Also used : DatabaseLayoutWatcher(org.neo4j.io.fs.watcher.DatabaseLayoutWatcher) LockerLifecycleAdapter(org.neo4j.kernel.internal.locker.LockerLifecycleAdapter) Monitors(org.neo4j.monitoring.Monitors) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DatabaseAvailability(org.neo4j.kernel.availability.DatabaseAvailability) Dependencies(org.neo4j.collection.Dependencies) DatabasePageCache(org.neo4j.dbms.database.DatabasePageCache) PageCacheLifecycle(org.neo4j.kernel.impl.pagecache.PageCacheLifecycle)

Example 2 with DatabaseAvailability

use of org.neo4j.kernel.availability.DatabaseAvailability in project neo4j by neo4j.

the class DatabaseAvailabilityIT method notConfusingMessageOnDatabaseNonAvailability.

@Test
void notConfusingMessageOnDatabaseNonAvailability() {
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    DatabaseManager<?> databaseManager = getDatabaseManager(dependencyResolver);
    DatabaseContext databaseContext = databaseManager.getDatabaseContext(defaultNamedDatabaseId).get();
    DatabaseAvailability databaseAvailability = databaseContext.database().getDependencyResolver().resolveDependency(DatabaseAvailability.class);
    databaseAvailability.stop();
    TransactionFailureException exception = assertThrows(TransactionFailureException.class, () -> database.beginTx());
    assertEquals("Timeout waiting for database to become available and allow new transactions. Waited 1s. 1 reasons for blocking: Database unavailable.", exception.getMessage());
}
Also used : DatabaseContext(org.neo4j.dbms.database.DatabaseContext) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) DatabaseAvailability(org.neo4j.kernel.availability.DatabaseAvailability) DependencyResolver(org.neo4j.common.DependencyResolver) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseAvailability (org.neo4j.kernel.availability.DatabaseAvailability)2 Test (org.junit.jupiter.api.Test)1 Dependencies (org.neo4j.collection.Dependencies)1 DependencyResolver (org.neo4j.common.DependencyResolver)1 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)1 DatabasePageCache (org.neo4j.dbms.database.DatabasePageCache)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 DatabaseLayoutWatcher (org.neo4j.io.fs.watcher.DatabaseLayoutWatcher)1 PageCacheLifecycle (org.neo4j.kernel.impl.pagecache.PageCacheLifecycle)1 LockerLifecycleAdapter (org.neo4j.kernel.internal.locker.LockerLifecycleAdapter)1 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)1 Monitors (org.neo4j.monitoring.Monitors)1