Search in sources :

Example 1 with DatabaseStateService

use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.

the class DatabaseStartupTest method startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure.

@Test
void startDatabaseWithoutStoreFilesAndWithTransactionLogFilesFailure() throws IOException {
    // Create a store
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DatabaseLayout databaseLayout = db.databaseLayout();
    try (Transaction tx = db.beginTx()) {
        tx.createNode();
        tx.commit();
    }
    managementService.shutdown();
    fs.deleteRecursively(databaseLayout.databaseDirectory());
    // Try to start
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    try {
        db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
        assertFalse(db.isAvailable(10));
        DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        Optional<Throwable> cause = dbStateService.causeOfFailure(db.databaseId());
        assertTrue(cause.isPresent());
        assertThat(cause.get()).hasStackTraceContaining("Fail to start '" + db.databaseId() + "' since transaction logs were found, while database ");
    } finally {
        managementService.shutdown();
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 2 with DatabaseStateService

use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.

the class DatabaseShutdownTest method shouldShutdownCorrectlyWhenCheckPointingOnShutdownFails.

@Test
void shouldShutdownCorrectlyWhenCheckPointingOnShutdownFails() {
    TestDatabaseManagementServiceBuilderWithFailingPageCacheFlush factory = new TestDatabaseManagementServiceBuilderWithFailingPageCacheFlush(databaseLayout.databaseDirectory(), fs);
    DatabaseManagementService managementService = factory.build();
    GraphDatabaseAPI databaseService = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    DatabaseStateService dbStateService = databaseService.getDependencyResolver().resolveDependency(DatabaseStateService.class);
    factory.setFailFlush(true);
    managementService.shutdown();
    assertTrue(dbStateService.causeOfFailure(databaseService.databaseId()).isPresent());
    assertEquals(LifecycleStatus.SHUTDOWN, factory.getDatabaseStatus());
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 3 with DatabaseStateService

use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.

the class DatabaseManagementServiceFactory method startDatabaseServer.

private static void startDatabaseServer(GlobalModule globalModule, LifeSupport globalLife, Log internalLog, DatabaseManager<?> databaseManager, DatabaseManagementService managementService) {
    RuntimeException startupException = null;
    try {
        databaseManager.initialiseSystemDatabase();
        globalLife.start();
        DatabaseStateService databaseStateService = globalModule.getGlobalDependencies().resolveDependency(DatabaseStateService.class);
        verifySystemDatabaseStart(databaseManager, databaseStateService);
    } catch (Throwable throwable) {
        String message = "Error starting Neo4j database server at " + globalModule.getNeo4jLayout().databasesDirectory();
        startupException = new RuntimeException(message, throwable);
        internalLog.error(message, throwable);
    } finally {
        if (startupException != null) {
            try {
                managementService.shutdown();
            } catch (Throwable shutdownError) {
                startupException.addSuppressed(shutdownError);
            }
        }
    }
    if (startupException != null) {
        internalLog.error("Failed to start database server.", startupException);
        throw startupException;
    }
}
Also used : DatabaseStateService(org.neo4j.dbms.DatabaseStateService)

Example 4 with DatabaseStateService

use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.

the class RecordFormatMigrationIT method assertDefaultDatabaseFailed.

private Throwable assertDefaultDatabaseFailed(GraphDatabaseAPI database) {
    assertThrows(Throwable.class, database::beginTx);
    DatabaseStateService dbStateService = getDatabaseStateService(database);
    var failure = dbStateService.causeOfFailure(database.databaseId());
    return failure.orElseThrow(() -> new AssertionError(format("No failure found for database %s", database.databaseId().name())));
}
Also used : DatabaseStateService(org.neo4j.dbms.DatabaseStateService)

Example 5 with DatabaseStateService

use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.

the class RecoveryIT method failToStartDatabaseWithRemovedTransactionLogs.

@Test
void failToStartDatabaseWithRemovedTransactionLogs() throws Throwable {
    GraphDatabaseAPI database = createDatabase();
    generateSomeData(database);
    managementService.shutdown();
    removeTransactionLogs();
    GraphDatabaseAPI restartedDb = createDatabase();
    try {
        DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
        assertTrue(failure.isPresent());
        assertThat(getRootCause(failure.get()).getMessage()).contains("Transaction logs are missing and recovery is not possible.");
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseStateService (org.neo4j.dbms.DatabaseStateService)16 Test (org.junit.jupiter.api.Test)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)13 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)8 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)6 Transaction (org.neo4j.graphdb.Transaction)4 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)3 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 PageCache (org.neo4j.io.pagecache.PageCache)3 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)3 StoreUpgrader (org.neo4j.kernel.impl.storemigration.StoreUpgrader)3 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)3 Path (java.nio.file.Path)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1