Search in sources :

Example 1 with PropertyValueRecordSizeCalculator

use of org.neo4j.kernel.impl.store.PropertyValueRecordSizeCalculator 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 2 with PropertyValueRecordSizeCalculator

use of org.neo4j.kernel.impl.store.PropertyValueRecordSizeCalculator in project neo4j by neo4j.

the class CsvInputEstimateCalculationIT method shouldCalculateCorrectEstimatesOnEmptyData.

@Test
void shouldCalculateCorrectEstimatesOnEmptyData() throws Exception {
    // given
    Groups groups = new Groups();
    Collection<DataFactory> nodeData = singletonList(generateData(defaultFormatNodeFileHeader(), new MutableLong(), 0, 0, ":ID", "nodes-1.csv", groups));
    Collection<DataFactory> relationshipData = singletonList(generateData(defaultFormatRelationshipFileHeader(), new MutableLong(), 0, 0, ":START_ID,:TYPE,:END_ID", "rels-1.csv", groups));
    Input input = new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, CsvInput.NO_MONITOR, groups, INSTANCE);
    // when
    Input.Estimates estimates = input.calculateEstimates(new PropertyValueRecordSizeCalculator(LATEST_RECORD_FORMATS.property().getRecordSize(NO_STORE_HEADER), GraphDatabaseInternalSettings.string_block_size.defaultValue(), 0, GraphDatabaseInternalSettings.array_block_size.defaultValue(), 0));
    // then
    assertEquals(0, estimates.numberOfNodes());
    assertEquals(0, estimates.numberOfRelationships());
    assertEquals(0, estimates.numberOfRelationshipProperties());
    assertEquals(0, estimates.numberOfNodeProperties());
    assertEquals(0, estimates.numberOfNodeLabels());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Input(org.neo4j.internal.batchimport.input.Input) Groups(org.neo4j.internal.batchimport.input.Groups) PropertyValueRecordSizeCalculator(org.neo4j.kernel.impl.store.PropertyValueRecordSizeCalculator) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 Input (org.neo4j.internal.batchimport.input.Input)2 PropertyValueRecordSizeCalculator (org.neo4j.kernel.impl.store.PropertyValueRecordSizeCalculator)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Config (org.neo4j.configuration.Config)1 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)1 Groups (org.neo4j.internal.batchimport.input.Groups)1 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)1 MuninnPageCache (org.neo4j.io.pagecache.impl.muninn.MuninnPageCache)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)1 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)1 JobScheduler (org.neo4j.scheduler.JobScheduler)1 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)1