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();
}
}
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());
}
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;
}
}
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())));
}
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();
}
}
Aggregations