Search in sources :

Example 6 with ThreadPoolJobScheduler

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

the class CsvInputEstimateCalculationIT method shouldCalculateCorrectEstimates.

@Test
void shouldCalculateCorrectEstimates() throws Exception {
    // given a couple of input files of various layouts
    Input input = generateData();
    RecordFormats format = LATEST_RECORD_FORMATS;
    Input.Estimates estimates = input.calculateEstimates(new PropertyValueRecordSizeCalculator(format.property().getRecordSize(NO_STORE_HEADER), GraphDatabaseInternalSettings.string_block_size.defaultValue(), 0, GraphDatabaseInternalSettings.array_block_size.defaultValue(), 0));
    // when
    Config config = Config.defaults();
    FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
    try (JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        new ParallelBatchImporter(databaseLayout, fs, PageCacheTracer.NULL, PBI_CONFIG, NullLogService.getInstance(), INVISIBLE, EMPTY, config, format, ImportLogic.NO_MONITOR, jobScheduler, Collector.EMPTY, LogFilesInitializer.NULL, IndexImporterFactory.EMPTY, EmptyMemoryTracker.INSTANCE).doImport(input);
        // then compare estimates with actual disk sizes
        SingleFilePageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory(fs);
        try (PageCache pageCache = new MuninnPageCache(swapperFactory, jobScheduler, MuninnPageCache.config(1000));
            NeoStores stores = new StoreFactory(databaseLayout, config, new DefaultIdGeneratorFactory(fs, immediate(), databaseLayout.getDatabaseName()), pageCache, fs, NullLogProvider.getInstance(), PageCacheTracer.NULL, writable()).openAllNeoStores()) {
            assertRoughlyEqual(estimates.numberOfNodes(), stores.getNodeStore().getNumberOfIdsInUse());
            assertRoughlyEqual(estimates.numberOfRelationships(), stores.getRelationshipStore().getNumberOfIdsInUse());
            assertRoughlyEqual(estimates.numberOfNodeProperties() + estimates.numberOfRelationshipProperties(), calculateNumberOfProperties(stores));
        }
        long measuredPropertyStorage = propertyStorageSize();
        long estimatedPropertyStorage = estimates.sizeOfNodeProperties() + estimates.sizeOfRelationshipProperties();
        assertThat(estimatedPropertyStorage).as("Estimated property storage size of %s must be within 10%% of the measured size of %s.", bytesToString(estimatedPropertyStorage), bytesToString(measuredPropertyStorage)).isCloseTo(measuredPropertyStorage, withPercentage(10.0));
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) ParallelBatchImporter(org.neo4j.internal.batchimport.ParallelBatchImporter) Input(org.neo4j.internal.batchimport.input.Input) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) NeoStores(org.neo4j.kernel.impl.store.NeoStores) SingleFilePageSwapperFactory(org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PropertyValueRecordSizeCalculator(org.neo4j.kernel.impl.store.PropertyValueRecordSizeCalculator) PageCache(org.neo4j.io.pagecache.PageCache) MuninnPageCache(org.neo4j.io.pagecache.impl.muninn.MuninnPageCache) Test(org.junit.jupiter.api.Test)

Example 7 with ThreadPoolJobScheduler

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

the class ConfigurableStandalonePageCacheFactoryTest method mustAutomaticallyStartEvictionThread.

@Test
void mustAutomaticallyStartEvictionThread() throws Exception {
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        Path file = testDirectory.homePath().resolve("a").normalize();
        fs.write(file).close();
        try (PageCache cache = ConfigurableStandalonePageCacheFactory.createPageCache(fs, jobScheduler, PageCacheTracer.NULL);
            PagedFile pf = cache.map(file, 4096, DEFAULT_DATABASE_NAME);
            PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_WRITE_LOCK, CursorContext.NULL)) {
            // If the eviction thread has not been started, then this test will block forever.
            for (int i = 0; i < 10_000; i++) {
                assertTrue(cursor.next());
                cursor.putInt(42);
            }
        }
    }
}
Also used : ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) JobScheduler(org.neo4j.scheduler.JobScheduler) Path(java.nio.file.Path) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) PagedFile(org.neo4j.io.pagecache.PagedFile) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) PageCache(org.neo4j.io.pagecache.PageCache) PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.jupiter.api.Test)

Example 8 with ThreadPoolJobScheduler

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

the class GBPTreePartialCreateFuzzIT method main.

static void main(String[] args) throws Exception {
    // Just start and immediately close. The process spawning this subprocess will kill it in the middle of all this
    Path file = Path.of(args[0]);
    try (FileSystemAbstraction fs = new DefaultFileSystemAbstraction();
        JobScheduler jobScheduler = new ThreadPoolJobScheduler()) {
        SingleFilePageSwapperFactory swapper = new SingleFilePageSwapperFactory(fs);
        try (PageCache pageCache = new MuninnPageCache(swapper, jobScheduler, config(10))) {
            fs.deleteFile(file);
            new GBPTreeBuilder<>(pageCache, file, longLayout().build()).build().close();
        }
    }
}
Also used : Path(java.nio.file.Path) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) JobScheduler(org.neo4j.scheduler.JobScheduler) 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 9 with ThreadPoolJobScheduler

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

the class StoreUpgraderInterruptionTestIT method setUpLabelScanStore.

@Before
public void setUpLabelScanStore() {
    jobScheduler = new ThreadPoolJobScheduler();
    neo4jLayout = Neo4jLayout.of(directory.homePath());
    workingDatabaseLayout = neo4jLayout.databaseLayout(DEFAULT_DATABASE_NAME);
    prepareDirectory = directory.directory("prepare");
    legacyTransactionLogsLocator = new LegacyTransactionLogsLocator(Config.defaults(), workingDatabaseLayout);
    pageCache = pageCacheRule.getPageCache(fs);
    baselineFormat = RecordFormatSelector.selectForVersion(version);
    successorFormat = RecordFormatSelector.findLatestFormatInFamily(baselineFormat).orElse(baselineFormat);
}
Also used : LegacyTransactionLogsLocator(org.neo4j.kernel.impl.storemigration.LegacyTransactionLogsLocator) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Before(org.junit.Before)

Example 10 with ThreadPoolJobScheduler

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

the class NodeImporterTest method shouldHandleLargeAmountsOfLabels.

@Test
void shouldHandleLargeAmountsOfLabels() throws IOException {
    // given
    IdMapper idMapper = mock(IdMapper.class);
    JobScheduler scheduler = new ThreadPoolJobScheduler();
    try (Lifespan life = new Lifespan(scheduler);
        BatchingNeoStores stores = BatchingNeoStores.batchingNeoStoresWithExternalPageCache(fs, pageCache, NULL, layout, Standard.LATEST_RECORD_FORMATS, Configuration.DEFAULT, NullLogService.getInstance(), AdditionalInitialIds.EMPTY, Config.defaults(), INSTANCE)) {
        stores.createNew();
        // when
        int numberOfLabels = 50;
        long nodeId = 0;
        try (NodeImporter importer = new NodeImporter(stores, idMapper, new DataImporter.Monitor(), NULL, INSTANCE)) {
            importer.id(nodeId);
            String[] labels = new String[numberOfLabels];
            for (int i = 0; i < labels.length; i++) {
                labels[i] = "Label" + i;
            }
            importer.labels(labels);
            importer.endOfEntity();
        }
        // then
        NodeStore nodeStore = stores.getNodeStore();
        NodeRecord record = nodeStore.getRecord(nodeId, nodeStore.newRecord(), RecordLoad.NORMAL, CursorContext.NULL);
        long[] labels = NodeLabelsField.parseLabelsField(record).get(nodeStore, CursorContext.NULL);
        assertEquals(numberOfLabels, labels.length);
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) BatchingNeoStores(org.neo4j.internal.batchimport.store.BatchingNeoStores) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) ThreadPoolJobScheduler(org.neo4j.test.scheduler.ThreadPoolJobScheduler) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.jupiter.api.Test)

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