use of org.neo4j.dbms.api.DatabaseManagementService 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();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method startStopDatabase.
private void startStopDatabase() {
DatabaseManagementService managementService = databaseFactory.build();
storageEngineFactory = ((GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME)).getDependencyResolver().resolveDependency(StorageEngineFactory.class);
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled.
@Test
void startWithNotLastTransactionLogHavingZerosInTheEndAndCorruptedLogRecoveryEnabled() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransaction(database);
managementService.shutdown();
long originalLogDataLength;
Path firstLogFile;
try (Lifespan lifespan = new Lifespan(logFiles)) {
LogFile logFile = logFiles.getLogFile();
LogPosition readablePosition = getLastReadablePosition(logFile);
firstLogFile = logFiles.getLogFile().getHighestLogFile();
originalLogDataLength = readablePosition.getByteOffset();
logFile.rotate();
// append zeros in the end of previous file causing illegal suffix
try (StoreFileChannel writeChannel = fileSystem.write(firstLogFile)) {
writeChannel.position(writeChannel.size());
for (int i = 0; i < 10; i++) {
writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
}
}
}
startStopDbRecoveryOfCorruptedLogs();
assertEquals(originalLogDataLength, fileSystem.getFileSize(firstLogFile));
assertThat(logProvider).containsMessages("Recovery required from position LogPosition{logVersion=0, byteOffset=" + (996 + txOffsetAfterStart) + "}").assertExceptionForLogMessage("Fail to read transaction log version 0.").hasMessage("Transaction log files with version 0 has 50 unreadable bytes. Was able to read upto " + (996 + txOffsetAfterStart) + " but " + (1046 + txOffsetAfterStart) + " is available.");
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method startWithoutProblemsIfRotationForcedBeforeFileEndAndCorruptedLogFilesRecoveryEnabled.
@Test
void startWithoutProblemsIfRotationForcedBeforeFileEndAndCorruptedLogFilesRecoveryEnabled() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransaction(database);
managementService.shutdown();
try (Lifespan lifespan = new Lifespan(logFiles)) {
Path originalFile = logFiles.getLogFile().getHighestLogFile();
// in it its current position.
try (StoreFileChannel writeChannel = fileSystem.write(originalFile)) {
writeChannel.position(writeChannel.size());
for (int i = 0; i < 10; i++) {
writeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0 }));
}
}
logFiles.getLogFile().rotate();
}
startStopDbRecoveryOfCorruptedLogs();
assertThat(logProvider).doesNotContainMessage("Fail to read transaction log version 0.");
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruptionVersion.
@Test
void failToRecoverFirstCorruptedTransactionSingleFileNoCheckpointIfFailOnCorruptionVersion() throws IOException {
addCorruptedCommandsToLastLogFile(new CorruptedLogEntryVersionWrapper());
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();
}
}
Aggregations