use of org.neo4j.dbms.api.DatabaseManagementService 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.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method repetitiveRecoveryOfCorruptedLogs.
@Test
void repetitiveRecoveryOfCorruptedLogs() throws IOException {
DatabaseManagementService service = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) service.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransactionsAndRotate(database, 4, false);
service.shutdown();
removeLastCheckpointRecordFromLastLogFile();
int expectedRecoveredTransactions = 7;
while (expectedRecoveredTransactions > 0) {
truncateBytesFromLastLogFile(1 + random.nextInt(10));
startStopDbRecoveryOfCorruptedLogs();
int numberOfRecoveredTransactions = recoveryMonitor.getNumberOfRecoveredTransactions();
assertEquals(expectedRecoveredTransactions, numberOfRecoveredTransactions);
expectedRecoveredTransactions--;
removeLastCheckpointRecordFromLastLogFile();
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method truncateNewerTransactionLogFileWhenForced.
@Test
void truncateNewerTransactionLogFileWhenForced() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
TransactionIdStore transactionIdStore = getTransactionIdStore(database);
long numberOfClosedTransactionsAfterStartup = transactionIdStore.getLastClosedTransactionId();
logFiles = buildDefaultLogFiles(getStoreId(database));
for (int i = 0; i < 10; i++) {
generateTransaction(database);
}
long numberOfTransactionsToRecover = transactionIdStore.getLastClosedTransactionId() - numberOfClosedTransactionsAfterStartup;
managementService.shutdown();
removeLastCheckpointRecordFromLastLogFile();
Supplier<Byte> randomBytesSupplier = this::randomInvalidVersionsBytes;
BytesCaptureSupplier capturingSupplier = new BytesCaptureSupplier(randomBytesSupplier);
addRandomBytesToLastLogFile(capturingSupplier);
assertFalse(recoveryMonitor.wasRecoveryRequired());
startStopDbRecoveryOfCorruptedLogs();
try {
assertEquals(numberOfTransactionsToRecover, recoveryMonitor.getNumberOfRecoveredTransactions());
assertTrue(recoveryMonitor.wasRecoveryRequired());
assertThat(logProvider).containsMessages("Fail to read transaction log version 0.", "Fail to read transaction log version 0. Last valid transaction start offset is: " + (5548 + txOffsetAfterStart) + ".");
} catch (Throwable t) {
throw new RuntimeException("Generated random bytes: " + capturingSupplier.getCapturedBytes(), t);
}
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method recoverNotAFirstCorruptedTransactionMultipleFilesNoCheckpoints.
@ParameterizedTest(name = "[{index}] ({0})")
@MethodSource("corruptedLogEntryWriters")
void recoverNotAFirstCorruptedTransactionMultipleFilesNoCheckpoints(String testName, LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
TransactionIdStore transactionIdStore = getTransactionIdStore(database);
long lastClosedTransactionBeforeStart = transactionIdStore.getLastClosedTransactionId();
generateTransactionsAndRotate(database, 3);
for (int i = 0; i < 7; i++) {
generateTransaction(database);
}
long numberOfTransactions = transactionIdStore.getLastClosedTransactionId() - lastClosedTransactionBeforeStart;
managementService.shutdown();
Path highestLogFile = logFiles.getLogFile().getHighestLogFile();
long originalFileLength = getLastReadablePosition(highestLogFile).getByteOffset();
removeLastCheckpointRecordFromLastLogFile();
addCorruptedCommandsToLastLogFile(logEntryWriterWrapper);
long modifiedFileLength = fileSystem.getFileSize(highestLogFile);
assertThat(modifiedFileLength).isGreaterThan(originalFileLength);
startStopDbRecoveryOfCorruptedLogs();
assertThat(logProvider).containsMessages("Fail to read transaction log version 3.", "Recovery required from position LogPosition{logVersion=0, byteOffset=" + txOffsetAfterStart + "}", "Fail to recover all transactions.", "Any later transaction after LogPosition{logVersion=3, byteOffset=" + (4552 + HEADER_OFFSET) + "} are unreadable and will be truncated.");
assertEquals(3, logFiles.getLogFile().getHighestLogVersion());
assertEquals(numberOfTransactions, recoveryMonitor.getNumberOfRecoveredTransactions());
assertEquals(originalFileLength, fileSystem.getFileSize(highestLogFile));
// 2 shutdowns will create a checkpoint and recovery that will be triggered by removing tx logs for default db
// during the setup and starting db as part of the test
assertEquals(CURRENT_FORMAT_LOG_HEADER_SIZE + 3 * 192, Files.size(logFiles.getCheckpointFile().getCurrentFile()));
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method evenTruncateNewerTransactionLogFile.
@Test
void evenTruncateNewerTransactionLogFile() throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
TransactionIdStore transactionIdStore = getTransactionIdStore(database);
long lastClosedTransactionBeforeStart = transactionIdStore.getLastClosedTransactionId();
for (int i = 0; i < 10; i++) {
generateTransaction(database);
}
long numberOfClosedTransactions = getTransactionIdStore(database).getLastClosedTransactionId() - lastClosedTransactionBeforeStart;
managementService.shutdown();
removeLastCheckpointRecordFromLastLogFile();
addRandomBytesToLastLogFile(this::randomNonZeroBytes);
startStopDbRecoveryOfCorruptedLogs();
assertEquals(numberOfClosedTransactions, recoveryMonitor.getNumberOfRecoveredTransactions());
}
Aggregations