Search in sources :

Example 11 with EphemeralFileSystemAbstraction

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

the class LabelsAcceptanceTest method oversteppingMaxNumberOfLabelsShouldFailGracefully.

@Test
void oversteppingMaxNumberOfLabelsShouldFailGracefully() throws IOException {
    JobScheduler scheduler = JobSchedulerFactory.createScheduler();
    try (EphemeralFileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();
        Lifespan lifespan = new Lifespan(scheduler);
        PageCache pageCache = new MuninnPageCache(swapper(fileSystem), scheduler, MuninnPageCache.config(1_000))) {
        // Given
        Dependencies dependencies = new Dependencies();
        dependencies.satisfyDependencies(createIdContextFactoryWithMaxedOutLabelTokenIds(fileSystem, scheduler));
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(fileSystem).noOpSystemGraphInitializer().setExternalDependencies(dependencies).impermanent().build();
        GraphDatabaseService graphDatabase = managementService.database(DEFAULT_DATABASE_NAME);
        // When
        try (Transaction tx = graphDatabase.beginTx()) {
            assertThrows(ConstraintViolationException.class, () -> tx.createNode().addLabel(Labels.MY_LABEL));
        }
        managementService.shutdown();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) Dependencies(org.neo4j.collection.Dependencies) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) PageCache(org.neo4j.io.pagecache.PageCache) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) Test(org.junit.jupiter.api.Test)

Example 12 with EphemeralFileSystemAbstraction

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

the class RecoveryWithTokenIndexesIT method recoverDatabaseWithTokenIndexes.

@ParameterizedTest(name = "{0}")
@MethodSource("arguments")
void recoverDatabaseWithTokenIndexes(String name, boolean checkpointIndexes) throws Throwable {
    config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).build();
    EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    GraphDatabaseService db = startDatabase(fs);
    IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
    if (checkpointIndexes) {
        // Checkpoint to not make index creation part of the recovery.
        checkPoint(db);
    }
    int numberOfEntities = 10;
    for (int i = 0; i < numberOfEntities; i++) {
        createEntities(db);
    }
    // Don't flush/checkpoint before taking the snapshot, to make the indexes need to recover (clean crash generation)
    EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
    managementService.shutdown();
    fs.close();
    try (PageCache cache = pageCacheExtension.getPageCache(crashedFs)) {
        DatabaseLayout layout = DatabaseLayout.of(config);
        recoverDatabase(layout, crashedFs, cache);
    }
    db = startDatabase(crashedFs);
    // Verify that the default token indexes still exist
    IndexingTestUtil.assertOnlyDefaultTokenIndexesExists(db);
    awaitIndexesOnline(db);
    try (Transaction tx = db.beginTx()) {
        assertEquals(numberOfEntities, tx.findNodes(label).stream().count());
        assertEquals(numberOfEntities, tx.findRelationships(type).stream().count());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) PageCache(org.neo4j.io.pagecache.PageCache) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with EphemeralFileSystemAbstraction

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

the class TestLogPruning method newDb.

private GraphDatabaseAPI newDb(String logPruning, int rotateEveryNTransactions) {
    this.rotateEveryNTransactions = rotateEveryNTransactions;
    fs = new EphemeralFileSystemAbstraction();
    TestDatabaseManagementServiceBuilder gdf = new TestDatabaseManagementServiceBuilder();
    gdf.setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs));
    DatabaseManagementServiceBuilder builder = gdf.impermanent();
    builder.setConfig(keep_logical_logs, logPruning);
    managementService = builder.build();
    this.db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    files = db.getDependencyResolver().resolveDependency(LogFiles.class);
    return db;
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)

Example 14 with EphemeralFileSystemAbstraction

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

the class DatabaseRecoveryIT method shouldSeeSameIndexUpdatesDuringRecoveryAsFromNormalIndexApplication.

@Test
void shouldSeeSameIndexUpdatesDuringRecoveryAsFromNormalIndexApplication() throws Exception {
    // Previously indexes weren't really participating in recovery, instead there was an after-phase
    // where nodes that was changed during recovery were reindexed. Do be able to do this reindexing
    // the index had to support removing arbitrary entries based on node id alone. Lucene can do this,
    // but at least at the time of writing this not the native index. For this the recovery process
    // was changed to rewind neostore back to how it looked at the last checkpoint and then replay
    // transactions from that point, including indexes. This test verifies that there's no mismatch
    // between applying transactions normally and recovering them after a crash, index update wise.
    // given
    Path storeDir = directory.absolutePath();
    EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    UpdateCapturingIndexProvider updateCapturingIndexProvider = new UpdateCapturingIndexProvider(IndexProvider.EMPTY, new HashMap<>());
    GraphDatabaseAPI db = startDatabase(storeDir, fs, updateCapturingIndexProvider);
    Label label = TestLabels.LABEL_ONE;
    String key1 = "key1";
    String key2 = "key2";
    try (Transaction tx = db.beginTx()) {
        tx.schema().indexFor(label).on(key1).create();
        tx.schema().indexFor(label).on(key1).on(key2).create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(10, SECONDS);
        tx.commit();
    }
    checkPoint(db);
    produceRandomNodePropertyAndLabelUpdates(db, random.intBetween(20, 40), label, key1, key2);
    checkPoint(db);
    Map<Long, Collection<IndexEntryUpdate<?>>> updatesAtLastCheckPoint = updateCapturingIndexProvider.snapshot();
    // when
    produceRandomNodePropertyAndLabelUpdates(db, random.intBetween(40, 100), label, key1, key2);
    // Snapshot
    flush(db);
    EphemeralFileSystemAbstraction crashedFs = fs.snapshot();
    Map<Long, Collection<IndexEntryUpdate<?>>> updatesAtCrash = updateCapturingIndexProvider.snapshot();
    // Crash and start anew
    UpdateCapturingIndexProvider recoveredUpdateCapturingIndexProvider = new UpdateCapturingIndexProvider(IndexProvider.EMPTY, updatesAtLastCheckPoint);
    long lastCommittedTxIdBeforeRecovered = lastCommittedTxId(db);
    managementService.shutdown();
    fs.close();
    db = startDatabase(storeDir, crashedFs, recoveredUpdateCapturingIndexProvider);
    long lastCommittedTxIdAfterRecovered = lastCommittedTxId(db);
    Map<Long, Collection<IndexEntryUpdate<?>>> updatesAfterRecovery = recoveredUpdateCapturingIndexProvider.snapshot();
    // then
    assertEquals(lastCommittedTxIdBeforeRecovered, lastCommittedTxIdAfterRecovered);
    assertSameUpdates(updatesAtCrash, updatesAfterRecovery);
    managementService.shutdown();
    crashedFs.close();
}
Also used : Path(java.nio.file.Path) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) Label(org.neo4j.graphdb.Label) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test)

Example 15 with EphemeralFileSystemAbstraction

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

the class AuthProceduresIT method setup.

@BeforeEach
void setup() throws InvalidAuthTokenException {
    fs = new EphemeralFileSystemAbstraction();
    DatabaseManagementServiceBuilder graphDatabaseFactory = new TestDatabaseManagementServiceBuilder().setFileSystem(fs).impermanent().setConfig(GraphDatabaseSettings.auth_enabled, true);
    managementService = graphDatabaseFactory.build();
    db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    systemDb = (GraphDatabaseAPI) managementService.database(SYSTEM_DATABASE_NAME);
    authManager = db.getDependencyResolver().resolveDependency(BasicSystemGraphRealm.class);
    assertSuccess(login("neo4j", "neo4j"), "ALTER CURRENT USER SET PASSWORD FROM 'neo4j' TO 'temp'");
    assertSuccess(login("neo4j", "temp"), "ALTER CURRENT USER SET PASSWORD FROM 'temp' TO 'neo4j'");
    admin = login("neo4j", "neo4j");
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) BasicSystemGraphRealm(org.neo4j.server.security.systemgraph.BasicSystemGraphRealm) BeforeEach(org.junit.jupiter.api.BeforeEach)

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