use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class RecoveryCorruptedTransactionLogIT method recoverFirstCorruptedTransactionAfterCheckpointInLastLogFile.
@ParameterizedTest(name = "[{index}] ({0})")
@MethodSource("corruptedLogEntryWriters")
void recoverFirstCorruptedTransactionAfterCheckpointInLastLogFile(String testName, LogEntryWriterWrapper logEntryWriterWrapper) throws IOException {
DatabaseManagementService managementService = databaseFactory.build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
logFiles = buildDefaultLogFiles(getStoreId(database));
generateTransactionsAndRotate(database, 5);
managementService.shutdown();
Path highestLogFile = logFiles.getLogFile().getHighestLogFile();
long originalFileLength = getLastReadablePosition(highestLogFile).getByteOffset();
addCorruptedCommandsToLastLogFile(logEntryWriterWrapper);
long modifiedFileLength = fileSystem.getFileSize(highestLogFile);
assertThat(modifiedFileLength).isGreaterThan(originalFileLength);
startStopDbRecoveryOfCorruptedLogs();
assertThat(logProvider).containsMessages("Fail to read transaction log version 5.", "Fail to read first transaction of log version 5.", "Recovery required from position LogPosition{logVersion=5, byteOffset=" + (569 + HEADER_OFFSET) + "}", "Fail to recover all transactions. " + "Any later transactions after position LogPosition{logVersion=5, byteOffset=" + (569 + HEADER_OFFSET) + "} " + "are unreadable and will be truncated.");
assertEquals(5, logFiles.getLogFile().getHighestLogVersion());
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 + 4 * 192, Files.size(logFiles.getCheckpointFile().getCurrentFile()));
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class LogVersionUpgradeCheckerIT method createGraphDbAndKillIt.
private void createGraphDbAndKillIt() {
DatabaseManagementService managementService = startDatabaseService(false);
final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.createNode(label("FOO"));
tx.createNode(label("BAR"));
tx.commit();
}
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class LogVersionUpgradeCheckerIT method startFromOlderTransactionLogsIfAllowed.
@Test
void startFromOlderTransactionLogsIfAllowed() throws Exception {
createStoreWithLogEntryVersion(KernelVersion.V2_3.version(), true);
// Try to start with upgrading enabled
DatabaseManagementService managementService = startDatabaseService(true);
managementService.database(DEFAULT_DATABASE_NAME);
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class TestTxEntries method testStartEntryWrittenOnceOnRollback.
@Test
void testStartEntryWrittenOnceOnRollback() {
Path storeDir = testDirectory.homePath();
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(fs).impermanent().build();
final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
createSomeTransactions(db);
EphemeralFileSystemAbstraction snapshot = fs.snapshot();
managementService.shutdown();
managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(snapshot).impermanent().build();
managementService.shutdown();
}
use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.
the class CountsComputerTest method skipPopulationWhenNodeAndRelationshipStoresAreEmpty.
@Test
void skipPopulationWhenNodeAndRelationshipStoresAreEmpty() throws IOException {
DatabaseManagementService managementService = dbBuilder.build();
GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
long lastCommittedTransactionId = getLastTxId(db);
managementService.shutdown();
InvocationTrackingProgressReporter progressReporter = new InvocationTrackingProgressReporter();
rebuildCounts(lastCommittedTransactionId, progressReporter);
try (GBPTreeCountsStore store = createCountsStore(matchingBuilder(lastCommittedTransactionId))) {
store.start(NULL, INSTANCE);
softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
store.accept(new AssertEmptyCountStoreVisitor(), NULL);
}
softly.assertThat(progressReporter.isCompleteInvoked()).as("Complete").isTrue();
softly.assertThat(progressReporter.isStartInvoked()).as("Start").isFalse();
}
Aggregations