Search in sources :

Example 1 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class AbstractDatabaseManager method startDatabase.

protected void startDatabase(NamedDatabaseId namedDatabaseId, DB context) {
    try {
        log.info("Starting '%s'.", namedDatabaseId);
        Database database = context.database();
        database.start();
    } catch (Throwable t) {
        throw new DatabaseManagementException(format("An error occurred! Unable to start `%s`.", namedDatabaseId), t);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) Database(org.neo4j.kernel.database.Database)

Example 2 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class AbstractDatabaseManager method stopDatabase.

protected void stopDatabase(NamedDatabaseId namedDatabaseId, DB context) {
    try {
        log.info("Stopping '%s'.", namedDatabaseId);
        Database database = context.database();
        database.stop();
        log.info("Stopped '%s' successfully.", namedDatabaseId);
    } catch (Throwable t) {
        log.error("Error stopping '%s'.", namedDatabaseId);
        throw new DatabaseManagementException(format("An error occurred! Unable to stop `%s`.", namedDatabaseId), t);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) Database(org.neo4j.kernel.database.Database)

Example 3 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class AbstractDatabaseManager method forEachDatabase.

private void forEachDatabase(BiConsumer<NamedDatabaseId, DB> consumer, boolean systemDatabaseLast, String operationName) {
    var snapshot = systemDatabaseLast ? databasesSnapshot().descendingMap().entrySet() : databasesSnapshot().entrySet();
    DatabaseManagementException dbmsExceptions = null;
    for (var entry : snapshot) {
        NamedDatabaseId namedDatabaseId = entry.getKey();
        DB context = entry.getValue();
        try {
            consumer.accept(namedDatabaseId, context);
        } catch (Throwable t) {
            var dbmsException = new DatabaseManagementException(format("An error occurred! Unable to %s the database `%s`.", operationName, namedDatabaseId), t);
            dbmsExceptions = Exceptions.chain(dbmsExceptions, dbmsException);
        }
    }
    if (dbmsExceptions != null) {
        throw dbmsExceptions;
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId)

Example 4 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class DefaultDatabaseManagerTest method shouldThrowIfUpgradingNonExistingDatabase.

@Test
void shouldThrowIfUpgradingNonExistingDatabase() {
    // Given
    NamedDatabaseId namedDatabaseId = DatabaseIdFactory.from("foo", UUID.randomUUID());
    GlobalModule mock = mock(GlobalModule.class, RETURNS_MOCKS);
    DefaultDatabaseManager databaseManager = new DefaultDatabaseManager(mock, mock(AbstractEditionModule.class));
    // Then
    DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
    assertThat(e).hasMessage("Database not found: " + namedDatabaseId);
}
Also used : GlobalModule(org.neo4j.graphdb.factory.module.GlobalModule) DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) AbstractEditionModule(org.neo4j.graphdb.factory.module.edition.AbstractEditionModule) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Example 5 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class DefaultDatabaseManagerUpgradeIT method upgradeDatabaseMustThrowOnFailure.

@Test
void upgradeDatabaseMustThrowOnFailure() {
    // Given
    RuntimeException expectedException = new RuntimeException("Dammit Leroy!");
    useThrowingMigrationLogProvider(expectedException);
    createDbms();
    GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
    DefaultDatabaseManager databaseManager = getDatabaseManager(db);
    RecordStoreVersionCheck check = new RecordStoreVersionCheck(fs, getPageCache(db), databaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
    assertFalse(db.isAvailable(100), "Expected database to have failed during startup because we don't allow upgrade.");
    // When
    NamedDatabaseId namedDatabaseId = db.databaseId();
    DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
    // Then
    assertThat(e).hasMessage("Failed to upgrade " + namedDatabaseId);
    assertThat(e).hasRootCause(expectedException);
    assertFalse(db.isAvailable(100), "Expected database to be available after upgrade");
    assertTrue(MigrationTestUtils.checkNeoStoreHasFormatVersion(check, StandardV3_4.RECORD_FORMATS), "Expected store not upgraded.");
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) RecordStoreVersionCheck(org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)7 Database (org.neo4j.kernel.database.Database)3 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)3 Test (org.junit.jupiter.api.Test)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 DatabaseNotFoundException (org.neo4j.dbms.api.DatabaseNotFoundException)1 KernelException (org.neo4j.exceptions.KernelException)1 QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)1 GlobalModule (org.neo4j.graphdb.factory.module.GlobalModule)1 AbstractEditionModule (org.neo4j.graphdb.factory.module.edition.AbstractEditionModule)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 RecordStoreVersionCheck (org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck)1