Search in sources :

Example 91 with DatabaseManagementService

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

Example 92 with DatabaseManagementService

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();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StorageEngineFactory(org.neo4j.storageengine.api.StorageEngineFactory) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 93 with DatabaseManagementService

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.");
}
Also used : Path(java.nio.file.Path) LogFile(org.neo4j.kernel.impl.transaction.log.files.LogFile) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with DatabaseManagementService

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.");
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with DatabaseManagementService

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

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