Search in sources :

Example 26 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class RecoveryRequiredCheckerTest method recoverBrokenStoreWithConfig.

private void recoverBrokenStoreWithConfig(Config config) throws IOException {
    try (EphemeralFileSystemAbstraction ephemeralFs = createSomeDataAndCrash(storeDir, config);
        PageCache pageCache = pageCacheExtension.getPageCache(ephemeralFs)) {
        RecoveryRequiredChecker recoveryChecker = getRecoveryChecker(ephemeralFs, pageCache, storageEngineFactory, config);
        assertThat(recoveryChecker.isRecoveryRequiredAt(DatabaseLayout.of(config), INSTANCE)).isEqualTo(true);
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setFileSystem(ephemeralFs).setConfig(config).build();
        managementService.shutdown();
        assertThat(recoveryChecker.isRecoveryRequiredAt(databaseLayout, INSTANCE)).isEqualTo(false);
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) PageCache(org.neo4j.io.pagecache.PageCache)

Example 27 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class IndexedIdGeneratorRecoverabilityTest method simpleCrashTest.

@Test
void simpleCrashTest() throws Exception {
    final EphemeralFileSystemAbstraction snapshot;
    final long id1;
    final long id2;
    try (IdGenerator freelist = instantiateFreelist()) {
        id1 = freelist.nextId(NULL);
        id2 = freelist.nextId(NULL);
        markUsed(freelist, id1, id2);
        freelist.checkpoint(NULL);
        markDeleted(freelist, id1, id2);
        pageCache.flushAndForce();
        snapshot = fs.snapshot();
    }
    try (PageCache newPageCache = getPageCache(snapshot);
        IdGenerator freelist = instantiateFreelist()) {
        markDeleted(freelist, id1, id2);
        // Recovery is completed ^^^
        freelist.start(NO_FREE_IDS, NULL);
        markFree(freelist, id1, id2);
        final ImmutableLongSet reused = LongSets.immutable.of(freelist.nextId(NULL), freelist.nextId(NULL));
        assertEquals(LongSets.immutable.of(id1, id2), reused, "IDs are not reused");
    } finally {
        snapshot.close();
    }
}
Also used : ImmutableLongSet(org.eclipse.collections.api.set.primitive.ImmutableLongSet) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) IdGenerator(org.neo4j.internal.id.IdGenerator) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.jupiter.api.Test)

Example 28 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class ConsistencyCheckWithCorruptGBPTreeIT method createIndex.

@BeforeAll
void createIndex() throws Exception {
    final EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    fs.mkdirs(neo4jHome);
    dbmsAction(neo4jHome, fs, NATIVE_BTREE10, // Data
    db -> {
        indexWithStringData(db, label);
        databaseLayout = ((GraphDatabaseAPI) db).databaseLayout();
    }, // Config
    builder -> {
    });
    sourceSnapshot = fs.snapshot();
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 29 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class PageCacheSlowTest method mustNotRunOutOfSwapperAllocationSpace.

@Test
void mustNotRunOutOfSwapperAllocationSpace() throws Exception {
    assumeTrue(fs instanceof EphemeralFileSystemAbstraction, "This test is file system agnostic, and too slow on a real file system");
    configureStandardPageCache();
    profiler.profile();
    Path file = file("a");
    int iterations = Short.MAX_VALUE * 3;
    for (int i = 0; i < iterations; i++) {
        try (PagedFile pagedFile = pageCache.map(file, filePageSize, DEFAULT_DATABASE_NAME)) {
            try (PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK, NULL)) {
                assertTrue(cursor.next());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 30 with EphemeralFileSystemAbstraction

use of org.neo4j.io.fs.EphemeralFileSystemAbstraction in project neo4j by neo4j.

the class SchemaAcceptanceTest method crashDuringIndexPopulationOfConstraint.

/**
 * This test describes a problem where if you crash during index population
 * when creating a constraint the constraint will never be created but the
 * index will and after next startup only the index will be there.
 *
 * We need to specifically drop the index in separate transaction to be
 * able to create the constraint again.
 *
 * A better behaviour would be that the index is never created and is not
 * present after crash.
 */
@Test
void crashDuringIndexPopulationOfConstraint() throws InterruptedException {
    // Given
    trapPopulation.set(true);
    otherThreadRule.execute(() -> {
        try (Transaction tx = db.beginTx()) {
            tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
            tx.commit();
        }
        return null;
    });
    // When
    // Crashing during index population of index backing a constraint
    populationScanFinished.await();
    EphemeralFileSystemAbstraction crash = fs.snapshot();
    populationScanFinished.release();
    // Then
    // On next startup
    controller.restartDbms(builder -> {
        builder.setFileSystem(crash);
        return builder;
    });
    // the index is online but constraint is missing... which is sub-optimal
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(1, TimeUnit.HOURS);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        Iterable<ConstraintDefinition> constraints = tx.schema().getConstraints();
        Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
        assertThat(count(constraints)).isEqualTo(0);
        assertThat(count(indexes)).isEqualTo(1);
        indexes.forEach(index -> assertThat(getIndexState(tx, index)).isEqualTo(ONLINE));
        tx.commit();
    }
    // and we cannot drop the constraint because it was never created
    {
        QueryExecutionException e = assertThrows(QueryExecutionException.class, () -> {
            try (Transaction tx = db.beginTx()) {
                tx.execute("DROP CONSTRAINT `" + nameA + "`");
                tx.commit();
            }
        });
        assertThat(e).hasRootCauseInstanceOf(NoSuchConstraintException.class);
    }
    // and we cannot re-create the constraint because index is blocking us
    {
        ConstraintViolationException e = assertThrows(ConstraintViolationException.class, () -> {
            try (Transaction tx = db.beginTx()) {
                tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
                tx.commit();
            }
        });
        assertThat(e).hasRootCauseInstanceOf(IndexWithNameAlreadyExistsException.class);
    }
    // dropping the index in separate transaction
    try (Transaction tx = db.beginTx()) {
        tx.schema().getIndexByName(nameA).drop();
        tx.commit();
    }
    // we can finally create the constraint again.
    try (Transaction tx = db.beginTx()) {
        tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName(nameA).create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        Iterable<ConstraintDefinition> constraints = tx.schema().getConstraints();
        Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
        assertThat(count(constraints)).isEqualTo(1);
        assertThat(count(indexes)).isEqualTo(1);
        indexes.forEach(index -> assertThat(getIndexState(tx, index)).isEqualTo(ONLINE));
        tx.commit();
    }
}
Also used : NoSuchConstraintException(org.neo4j.kernel.api.exceptions.schema.NoSuchConstraintException) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) IndexWithNameAlreadyExistsException(org.neo4j.kernel.api.exceptions.schema.IndexWithNameAlreadyExistsException) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)30 Test (org.junit.jupiter.api.Test)17 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 PageCache (org.neo4j.io.pagecache.PageCache)9 Path (java.nio.file.Path)7 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)7 Transaction (org.neo4j.graphdb.Transaction)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RepeatedTest (org.junit.jupiter.api.RepeatedTest)2 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)2 Dependencies (org.neo4j.collection.Dependencies)2 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)2 Label (org.neo4j.graphdb.Label)2 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2