Search in sources :

Example 76 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class RecoveryIT method failRecoveryWithMissingStoreFileAndIdFile.

@Test
void failRecoveryWithMissingStoreFileAndIdFile() throws Exception {
    GraphDatabaseAPI database = createDatabase();
    generateSomeData(database);
    DatabaseLayout layout = database.databaseLayout();
    managementService.shutdown();
    // Recovery should not be attempted on any store with missing store files, even if other recoverable files are missing as well.
    fileSystem.deleteFileOrThrow(layout.nodeStore());
    fileSystem.deleteFileOrThrow(layout.idLabelTokenStore());
    GraphDatabaseAPI restartedDb = createDatabase();
    try {
        DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
        assertTrue(failure.isPresent());
        assertThat(failure.get().getCause()).hasMessageContainingAll("neostore.nodestore.db", "is(are) missing and recovery is not possible");
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) Test(org.junit.jupiter.api.Test)

Example 77 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class RecoveryIT method cancelRecoveryInTheMiddle.

@Test
void cancelRecoveryInTheMiddle() throws Throwable {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    RecoveryHelpers.removeLastCheckpointRecordFromLastLogFile(databaseLayout, fileSystem);
    assertTrue(isRecoveryRequired(layout));
    Monitors monitors = new Monitors();
    var guardExtensionFactory = new GlobalGuardConsumerTestExtensionFactory();
    var recoveryMonitor = new RecoveryMonitor() {

        private final AtomicBoolean reverseCompleted = new AtomicBoolean();

        private final AtomicBoolean recoveryCompleted = new AtomicBoolean();

        @Override
        public void reverseStoreRecoveryCompleted(long lowestRecoveredTxId) {
            try {
                guardExtensionFactory.getProvidedGuardConsumer().globalGuard.stop();
            } catch (Exception e) {
            // do nothing
            }
            reverseCompleted.set(true);
        }

        @Override
        public void recoveryCompleted(int numberOfRecoveredTransactions, long recoveryTimeInMilliseconds) {
            recoveryCompleted.set(true);
        }

        public boolean isReverseCompleted() {
            return reverseCompleted.get();
        }

        public boolean isRecoveryCompleted() {
            return recoveryCompleted.get();
        }
    };
    monitors.addMonitorListener(recoveryMonitor);
    var service = new TestDatabaseManagementServiceBuilder(layout.getNeo4jLayout()).addExtension(guardExtensionFactory).setMonitors(monitors).build();
    try {
        var database = service.database(layout.getDatabaseName());
        assertTrue(recoveryMonitor.isReverseCompleted());
        assertFalse(recoveryMonitor.isRecoveryCompleted());
        assertFalse(guardExtensionFactory.getProvidedGuardConsumer().globalGuard.isAvailable());
        assertFalse(database.isAvailable(0));
        var e = assertThrows(Exception.class, database::beginTx);
        assertThat(getRootCause(e)).isInstanceOf(DatabaseStartAbortedException.class);
    } finally {
        service.shutdown();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Monitors(org.neo4j.monitoring.Monitors) DatabaseStartAbortedException(org.neo4j.dbms.database.DatabaseStartAbortedException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 78 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class RecoveryIT method resetCheckpointVersionOnMissingLogFilesWhenValueIsDefinitelyWrong.

@Test
void resetCheckpointVersionOnMissingLogFilesWhenValueIsDefinitelyWrong() throws Exception {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    removeTransactionLogs();
    assertTrue(isRecoveryRequired(layout));
    MetaDataStore.setRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, -42, layout.getDatabaseName(), NULL);
    recoverDatabase();
    assertFalse(isRecoveryRequired(layout));
    assertEquals(0, MetaDataStore.getRecord(pageCache, layout.metadataStore(), CHECKPOINT_LOG_VERSION, layout.getDatabaseName(), NULL));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 79 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class RecoveryIT method recoverDatabaseWithoutOneIdFile.

@Test
void recoverDatabaseWithoutOneIdFile() throws Throwable {
    GraphDatabaseAPI db = createDatabase();
    generateSomeData(db);
    DatabaseLayout layout = db.databaseLayout();
    managementService.shutdown();
    fileSystem.deleteFileOrThrow(layout.idRelationshipStore());
    assertTrue(isRecoveryRequired(layout));
    performRecovery(fileSystem, pageCache, EMPTY, defaults(), layout, INSTANCE);
    assertFalse(isRecoveryRequired(layout));
    assertTrue(fileSystem.fileExists(layout.idRelationshipStore()));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Test(org.junit.jupiter.api.Test)

Example 80 with DatabaseLayout

use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.

the class RecoveryIT method failRecoveryWithMissingStoreFile.

@Test
void failRecoveryWithMissingStoreFile() throws Exception {
    GraphDatabaseAPI database = createDatabase();
    generateSomeData(database);
    DatabaseLayout layout = database.databaseLayout();
    managementService.shutdown();
    fileSystem.deleteFileOrThrow(layout.nodeStore());
    GraphDatabaseAPI restartedDb = createDatabase();
    try {
        DatabaseStateService dbStateService = restartedDb.getDependencyResolver().resolveDependency(DatabaseStateService.class);
        var failure = dbStateService.causeOfFailure(restartedDb.databaseId());
        assertTrue(failure.isPresent());
        assertThat(failure.get().getCause()).hasMessageContainingAll("neostore.nodestore.db", "is(are) missing and recovery is not possible");
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DatabaseStateService(org.neo4j.dbms.DatabaseStateService) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)108 Test (org.junit.jupiter.api.Test)66 Path (java.nio.file.Path)51 Config (org.neo4j.configuration.Config)35 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)24 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)19 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)17 PageCache (org.neo4j.io.pagecache.PageCache)17 IOException (java.io.IOException)16 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)16 Transaction (org.neo4j.graphdb.Transaction)13 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)10 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)9 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)9 CommandFailedException (org.neo4j.cli.CommandFailedException)8 ExecutionContext (org.neo4j.cli.ExecutionContext)8 PageCacheTracer (org.neo4j.io.pagecache.tracing.PageCacheTracer)8 StorageEngineFactory (org.neo4j.storageengine.api.StorageEngineFactory)8 Closeable (java.io.Closeable)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7