Search in sources :

Example 16 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class PageCacheStressTest method run.

public void run() throws Exception {
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
        try (PageCache pageCacheUnderTest = new MuninnPageCache(swapperFactory, jobScheduler, config(numberOfCachePages).pageCacheTracer(tracer))) {
            PageCacheStresser pageCacheStresser = new PageCacheStresser(numberOfPages, numberOfThreads, workingDirectory);
            pageCacheStresser.stress(pageCacheUnderTest, tracer, condition);
        }
    }
}
Also used : ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) JobScheduler(org.neo4j.scheduler.JobScheduler) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PageCache(org.neo4j.io.pagecache.PageCache) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)

Example 17 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler 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 18 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldNotOpenStoreWithNodesOrRelationshipsInIt.

@Test
void shouldNotOpenStoreWithNodesOrRelationshipsInIt() throws Throwable {
    Config config = Config.defaults();
    // GIVEN
    someDataInTheDatabase(config);
    // WHEN
    DirectoryNotEmptyException exception = assertThrows(DirectoryNotEmptyException.class, () -> {
        try (JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
            RecordFormats recordFormats = selectForConfig(Config.defaults(), NullLogProvider.getInstance());
            try (BatchingNeoStores store = batchingNeoStores(fileSystem, databaseLayout, recordFormats, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, Config.defaults(), jobScheduler, PageCacheTracer.NULL, INSTANCE)) {
                store.createNew();
            }
        }
    });
    assertThat(exception.getMessage()).contains("already contains");
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) Config(org.neo4j.configuration.Config) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 19 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class BatchingNeoStoresTest method shouldRespectDbConfig.

@Test
void shouldRespectDbConfig() throws Exception {
    // GIVEN
    int size = 10;
    Config config = Config.newBuilder().set(GraphDatabaseInternalSettings.array_block_size, size).set(GraphDatabaseInternalSettings.string_block_size, size).build();
    // WHEN
    RecordFormats recordFormats = LATEST_RECORD_FORMATS;
    int headerSize = recordFormats.dynamic().getRecordHeaderSize();
    try (JobScheduler jobScheduler = new ThreadPoolJobScheduler();
        BatchingNeoStores store = batchingNeoStores(fileSystem, databaseLayout, recordFormats, Configuration.DEFAULT, NullLogService.getInstance(), EMPTY, config, jobScheduler, PageCacheTracer.NULL, INSTANCE)) {
        store.createNew();
        // THEN
        assertEquals(size + headerSize, store.getPropertyStore().getArrayStore().getRecordSize());
        assertEquals(size + headerSize, store.getPropertyStore().getStringStore().getRecordSize());
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ForcedSecondaryUnitRecordFormats(org.neo4j.kernel.impl.store.format.ForcedSecondaryUnitRecordFormats) Config(org.neo4j.configuration.Config) RecordFormatSelector.selectForConfig(org.neo4j.kernel.impl.store.format.RecordFormatSelector.selectForConfig) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Test(org.junit.jupiter.api.Test)

Example 20 with ThreadPoolJobScheduler

use of org.neo4j.test.scheduler.ThreadPoolJobScheduler in project neo4j by neo4j.

the class GBPTreeBootstrapperTest method setupTest.

private void setupTest(TestSetup testSetup) {
    this.layout = testSetup.layout;
    this.scheduler = new ThreadPoolJobScheduler();
    this.pageCache = StandalonePageCacheFactory.createPageCache(fs, scheduler, testSetup.pageSize);
    this.zipName = testSetup.zipName;
    this.storeFile = dir.file(STORE);
    this.zipFile = dir.file(zipName);
}
Also used : ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler)

Aggregations

ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)26 JobScheduler (org.neo4j.scheduler.JobScheduler)15 Test (org.junit.jupiter.api.Test)14 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 PageCache (org.neo4j.io.pagecache.PageCache)9 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)8 Path (java.nio.file.Path)7 Config (org.neo4j.configuration.Config)7 IOException (java.io.IOException)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 Transaction (org.neo4j.graphdb.Transaction)4 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)4 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)4 SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)4 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)4 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Input (org.neo4j.internal.batchimport.input.Input)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 StandalonePageCacheFactory.createPageCache (org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory.createPageCache)3