Search in sources :

Example 21 with EphemeralFileSystemAbstraction

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

the class RollbackIdLeakIT method nonClean.

private DbRestarter nonClean() {
    return new DbRestarter() {

        private DatabaseManagementService dbms;

        private EphemeralFileSystemAbstraction fsSnapshot;

        @Override
        public GraphDatabaseService start() {
            return start(fs);
        }

        @Override
        public GraphDatabaseService restart() {
            fsSnapshot = fs.snapshot();
            dbms.shutdown();
            return start(fsSnapshot);
        }

        @Override
        public void close() throws IOException {
            dbms.shutdown();
            fsSnapshot.close();
        }

        private GraphDatabaseService start(EphemeralFileSystemAbstraction fs) {
            dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(fs).build();
            return dbms.database(DEFAULT_DATABASE_NAME);
        }
    };
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 22 with EphemeralFileSystemAbstraction

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

the class RandomPageCacheTestHarness method runIteration.

@SuppressWarnings("unchecked")
private void runIteration(long timeout, TimeUnit unit) throws Exception {
    assert filePageSize % recordFormat.getRecordSize() == 0 : "File page size must be a multiple of the record size";
    if (!fixedRandomSeed) {
        randomSeed = ThreadLocalRandom.current().nextLong();
    }
    FileSystemAbstraction fs = this.fs;
    Path[] files = buildFileNames();
    RandomAdversary adversary = new RandomAdversary(mischiefRate, failureRate, errorRate);
    adversary.setProbabilityFactor(0.0);
    if (useAdversarialIO) {
        adversary.setSeed(randomSeed);
        fs = new AdversarialFileSystemAbstraction(adversary, fs);
    }
    PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
    JobScheduler jobScheduler = new ThreadPoolJobScheduler();
    MuninnPageCache cache = new MuninnPageCache(swapperFactory, jobScheduler, MuninnPageCache.config(cachePageCount).pageCacheTracer(tracer));
    if (filePageSize == 0) {
        filePageSize = cache.pageSize();
    }
    cache.setPrintExceptionsOnClose(false);
    Map<Path, PagedFile> fileMap = new HashMap<>(files.length);
    for (int i = 0; i < Math.min(files.length, initialMappedFiles); i++) {
        Path file = files[i];
        fileMap.put(file, cache.map(file, filePageSize, DEFAULT_DATABASE_NAME));
    }
    plan = plan(cache, files, fileMap);
    AtomicBoolean stopSignal = new AtomicBoolean();
    Callable<Void> planRunner = new PlanRunner(plan, stopSignal, profiler);
    Future<Void>[] futures = new Future[concurrencyLevel];
    for (int i = 0; i < concurrencyLevel; i++) {
        futures[i] = executorService.submit(planRunner);
    }
    if (preparation != null) {
        preparation.run(cache, this.fs, plan.getFilesTouched());
    }
    adversary.setProbabilityFactor(1.0);
    plan.start();
    long deadlineMillis = System.currentTimeMillis() + unit.toMillis(timeout);
    long now;
    try {
        for (Future<Void> future : futures) {
            now = System.currentTimeMillis();
            if (deadlineMillis < now) {
                throw new TimeoutException();
            }
            future.get(deadlineMillis - now, TimeUnit.MILLISECONDS);
        }
        adversary.setProbabilityFactor(0.0);
        runVerificationPhase(cache);
    } finally {
        stopSignal.set(true);
        adversary.setProbabilityFactor(0.0);
        try {
            for (Future<Void> future : futures) {
                future.get(10, TimeUnit.SECONDS);
            }
        } catch (InterruptedException | TimeoutException e) {
            for (Future<Void> future : futures) {
                future.cancel(true);
            }
            throw new RuntimeException(e);
        }
        try {
            plan.close();
            cache.close();
            jobScheduler.close();
            if (this.fs instanceof EphemeralFileSystemAbstraction) {
                this.fs.close();
                this.fs = new EphemeralFileSystemAbstraction();
            } else {
                for (Path file : files) {
                    Files.delete(file);
                }
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}
Also used : AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) HashMap(java.util.HashMap) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) UncheckedIOException(java.io.UncheckedIOException) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) TimeoutException(java.util.concurrent.TimeoutException) Path(java.nio.file.Path) JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) PagedFile(org.neo4j.io.pagecache.PagedFile) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RandomAdversary(org.neo4j.adversaries.RandomAdversary) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Future(java.util.concurrent.Future) AdversarialFileSystemAbstraction(org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)

Example 23 with EphemeralFileSystemAbstraction

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

the class SingleFilePageSwapperTest method setUp.

@BeforeEach
void setUp() {
    path = Path.of("file").normalize();
    ephemeralFileSystem = new EphemeralFileSystemAbstraction();
    fileSystem = new DefaultFileSystemAbstraction();
    threadRegistryFactory = new ThreadRegistryFactory();
    operationExecutor = Executors.newSingleThreadExecutor(threadRegistryFactory);
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with EphemeralFileSystemAbstraction

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

the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.

/**
 * Reading a node command might leave a node record which referred to
 * labels in one or more dynamic records as marked as heavy even if that
 * node already had references to dynamic records, changed in a transaction,
 * but had no labels on that node changed within that same transaction.
 * Now defensively only marks as heavy if there were one or more dynamic
 * records provided when providing the record object with the label field
 * value. This would give the opportunity to load the dynamic records the
 * next time that record would be ensured heavy.
 */
@Test
void shouldRecoverNodeWithDynamicLabelRecords() {
    // GIVEN
    managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(filesystem).impermanent().build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    Node node;
    Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
    try (Transaction tx = database.beginTx()) {
        node = tx.createNode(labels);
        tx.commit();
    }
    // WHEN
    try (Transaction tx = database.beginTx()) {
        node = tx.getNodeById(node.getId());
        node.setProperty("prop", "value");
        tx.commit();
    }
    EphemeralFileSystemAbstraction snapshot = filesystem.snapshot();
    managementService.shutdown();
    managementService = new TestDatabaseManagementServiceBuilder().setFileSystem(snapshot).impermanent().build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
    // THEN
    try (Transaction tx = database.beginTx()) {
        node = tx.getNodeById(node.getId());
        for (Label label : labels) {
            assertTrue(node.hasLabel(label));
        }
    }
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) Test(org.junit.jupiter.api.Test)

Example 25 with EphemeralFileSystemAbstraction

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

the class RecoveryRequiredCheckerTest method createSomeDataAndCrash.

private static EphemeralFileSystemAbstraction createSomeDataAndCrash(Path store, Config config) throws IOException {
    try (EphemeralFileSystemAbstraction ephemeralFs = new EphemeralFileSystemAbstraction()) {
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(store).setFileSystem(ephemeralFs).setConfig(config).build();
        final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
        try (Transaction tx = db.beginTx()) {
            tx.createNode();
            tx.commit();
        }
        EphemeralFileSystemAbstraction snapshot = ephemeralFs.snapshot();
        managementService.shutdown();
        return snapshot;
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

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