use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.
the class RecoveryIT method failToStartDatabaseWithTransactionLogsInLegacyLocation.
@Test
void failToStartDatabaseWithTransactionLogsInLegacyLocation() throws Exception {
GraphDatabaseAPI database = createDatabase();
generateSomeData(database);
managementService.shutdown();
LogFiles logFiles = buildLogFiles();
Path[] txLogFiles = fileSystem.listFiles(logFiles.logFilesDirectory(), path -> path.getFileName().toString().startsWith(DEFAULT_NAME));
txLogFiles = ArrayUtil.concat(txLogFiles, logFiles.getCheckpointFile().getDetachedCheckpointFiles());
Path databasesDirectory = databaseLayout.getNeo4jLayout().databasesDirectory();
DatabaseLayout legacyLayout = Neo4jLayout.ofFlat(databasesDirectory).databaseLayout(databaseLayout.getDatabaseName());
LegacyTransactionLogsLocator logsLocator = new LegacyTransactionLogsLocator(Config.defaults(), legacyLayout);
Path transactionLogsDirectory = logsLocator.getTransactionLogsDirectory();
assertNotNull(txLogFiles);
assertTrue(txLogFiles.length > 0);
for (Path logFile : txLogFiles) {
fileSystem.moveToDirectory(logFile, transactionLogsDirectory);
}
AssertableLogProvider logProvider = new AssertableLogProvider();
builder.setInternalLogProvider(logProvider);
GraphDatabaseAPI restartedDb = createDatabase();
try {
DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
assertTrue(failure.isPresent());
assertThat(failure.get()).hasRootCauseMessage("Transaction logs are missing and recovery is not possible.");
assertThat(logProvider.serialize()).contains(txLogFiles[0].getFileName().toString());
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.
the class StoreUpgradeOnStartupTest method shouldAbortOnNonCleanlyShutdown.
@Test
public void shouldAbortOnNonCleanlyShutdown() throws Throwable {
// given
removeCheckPointFromTxLog(fileSystem, workingDatabaseLayout.databaseDirectory());
GraphDatabaseAPI database = createGraphDatabaseService();
try {
DatabaseStateService databaseStateService = database.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(databaseStateService.causeOfFailure(database.databaseId()).isPresent());
assertThat(getRootCause(databaseStateService.causeOfFailure(database.databaseId()).get())).isInstanceOf(StoreUpgrader.UnableToUpgradeException.class);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.
the class DatabaseFailureIT method startWhenDefaultDatabaseFailedToStart.
@Test
void startWhenDefaultDatabaseFailedToStart() throws IOException {
managementService.shutdown();
FileUtils.deleteDirectory(databaseLayout.getTransactionLogsDirectory());
database = startDatabase();
DatabaseStateService databaseStateService = database.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(databaseStateService.causeOfFailure(database.databaseId()).isPresent());
assertFalse(databaseStateService.causeOfFailure(NAMED_SYSTEM_DATABASE_ID).isPresent());
}
use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method doNotTruncateNewerTransactionLogFileWhenFailOnError.
@Test
void doNotTruncateNewerTransactionLogFileWhenFailOnError() throws IOException {
DatabaseManagementService managementService1 = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService1.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
for (int i = 0; i < 10; i++) {
generateTransaction(database);
}
managementService1.shutdown();
removeLastCheckpointRecordFromLastLogFile();
addRandomBytesToLastLogFile(this::randomInvalidVersionsBytes);
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(db.databaseId()).isPresent());
assertThat(dbStateService.causeOfFailure(db.databaseId()).get()).hasRootCauseInstanceOf(UnsupportedLogVersionException.class);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.dbms.DatabaseStateService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption.
@Test
void failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruption() throws IOException {
addCorruptedCommandsToLastLogFile(new CorruptedLogEntryWrapper());
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
try {
DatabaseStateService dbStateService = db.getDependencyResolver().resolveDependency(DatabaseStateService.class);
assertTrue(dbStateService.causeOfFailure(db.databaseId()).isPresent());
assertThat(dbStateService.causeOfFailure(db.databaseId()).get()).hasRootCauseInstanceOf(NegativeArraySizeException.class);
} finally {
managementService.shutdown();
}
}
Aggregations