Search in sources :

Example 96 with DatabaseManagementService

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()));
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 97 with DatabaseManagementService

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();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 98 with DatabaseManagementService

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();
}
Also used : DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 99 with DatabaseManagementService

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();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 100 with DatabaseManagementService

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();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)155 Test (org.junit.jupiter.api.Test)100 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)79 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)61 Transaction (org.neo4j.graphdb.Transaction)60 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)56 Path (java.nio.file.Path)37 Node (org.neo4j.graphdb.Node)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Label (org.neo4j.graphdb.Label)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)8 Config (org.neo4j.configuration.Config)7 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)6