Search in sources :

Example 1 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper 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)

Example 2 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldHandleLargeAmountsOfDuplicateNodeIds.

@Test
public void shouldHandleLargeAmountsOfDuplicateNodeIds() {
    // GIVEN
    IdMapper mapper = mapper(new LongEncoder(), Radix.LONG, EncodingIdMapper.NO_MONITOR);
    long nodeId = 0;
    int high = 10;
    // a list of input ids
    List<Object> ids = new ArrayList<>();
    for (int run = 0; run < 2; run++) {
        for (long i = 0; i < high / 2; i++) {
            ids.add(high - (i + 1));
            ids.add(i);
        }
    }
    // fed to the IdMapper
    for (Object inputId : ids) {
        mapper.put(inputId, nodeId++, Group.GLOBAL);
    }
    // WHEN
    Collector collector = mock(Collector.class);
    mapper.prepare(values(ids.toArray()), collector, NONE);
    // THEN
    verify(collector, times(high)).collectDuplicateNode(any(Object.class), anyLong(), anyString());
    assertEquals(high, count(mapper.leftOverDuplicateNodesIds()));
}
Also used : ArrayList(java.util.ArrayList) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 3 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldDetectCorrectDuplicateInputIdsWhereManyAccidentalInManyGroups.

@Test
public void shouldDetectCorrectDuplicateInputIdsWhereManyAccidentalInManyGroups() {
    // GIVEN
    final ControlledEncoder encoder = new ControlledEncoder(new LongEncoder());
    final int idsPerGroup = 20;
    int groupCount = 5;
    for (int i = 0; i < groupCount; i++) {
        groups.getOrCreate("Group " + i);
    }
    IdMapper mapper = mapper(encoder, Radix.LONG, EncodingIdMapper.NO_MONITOR, ParallelSort.DEFAULT, numberOfCollisions -> new LongCollisionValues(NumberArrayFactories.HEAP, numberOfCollisions, INSTANCE));
    final AtomicReference<Group> group = new AtomicReference<>();
    PropertyValueLookup ids = (nodeId, cursorContext) -> {
        int groupId = toIntExact(nodeId / idsPerGroup);
        if (groupId == groupCount) {
            return null;
        }
        group.set(groups.get(groupId));
        // i.e. all first 10% in each group collides with all other first 10% in each group
        if (nodeId % idsPerGroup < 2) {
            // Let these colliding values encode into the same eId as well,
            // so that they are definitely marked as collisions
            encoder.useThisIdToEncodeNoMatterWhatComesIn(1234567L);
            return nodeId % idsPerGroup;
        }
        // The other 90% will be accidental collisions for something else
        encoder.useThisIdToEncodeNoMatterWhatComesIn((long) (123456 - group.get().id()));
        return nodeId;
    };
    // WHEN
    int count = idsPerGroup * groupCount;
    for (long nodeId = 0; nodeId < count; nodeId++) {
        mapper.put(ids.lookupProperty(nodeId, NULL), nodeId, group.get());
    }
    Collector collector = mock(Collector.class);
    mapper.prepare(ids, collector, NONE);
    // THEN
    verifyNoMoreInteractions(collector);
    for (long nodeId = 0; nodeId < count; nodeId++) {
        assertEquals(nodeId, mapper.get(ids.lookupProperty(nodeId, NULL), group.get()));
    }
    verifyNoMoreInteractions(collector);
    assertFalse(mapper.leftOverDuplicateNodesIds().hasNext());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NO_MONITOR(org.neo4j.internal.batchimport.cache.idmapping.string.EncodingIdMapper.NO_MONITOR) NumberArrayFactories(org.neo4j.internal.batchimport.cache.NumberArrayFactories) Collector(org.neo4j.internal.batchimport.input.Collector) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Groups(org.neo4j.internal.batchimport.input.Groups) Random(java.util.Random) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RandomRule(org.neo4j.test.rule.RandomRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assert.fail(org.junit.Assert.fail) Math.toIntExact(java.lang.Math.toIntExact) ProgressListener(org.neo4j.internal.helpers.progress.ProgressListener) NONE(org.neo4j.internal.helpers.progress.ProgressListener.NONE) Parameterized(org.junit.runners.Parameterized) LongFunction(java.util.function.LongFunction) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collection(java.util.Collection) Set(java.util.Set) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) AtomicLong(java.util.concurrent.atomic.AtomicLong) Factory(org.neo4j.function.Factory) GLOBAL(org.neo4j.internal.batchimport.input.Group.GLOBAL) List(java.util.List) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) Rule(org.junit.Rule) Group(org.neo4j.internal.batchimport.input.Group) Assert.assertFalse(org.junit.Assert.assertFalse) Race(org.neo4j.test.Race) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) PrimitiveLongCollections.count(org.neo4j.collection.PrimitiveLongCollections.count) Group(org.neo4j.internal.batchimport.input.Group) PropertyValueLookup(org.neo4j.internal.batchimport.PropertyValueLookup) Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 4 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldEncodeShortStrings.

@Test
public void shouldEncodeShortStrings() {
    // GIVEN
    IdMapper mapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
    // WHEN
    mapper.put("123", 0, Group.GLOBAL);
    mapper.put("456", 1, Group.GLOBAL);
    mapper.prepare(null, mock(Collector.class), NONE);
    // THEN
    assertEquals(1L, mapper.get("456", Group.GLOBAL));
    assertEquals(0L, mapper.get("123", Group.GLOBAL));
}
Also used : Collector(org.neo4j.internal.batchimport.input.Collector) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Example 5 with IdMapper

use of org.neo4j.internal.batchimport.cache.idmapping.IdMapper in project neo4j by neo4j.

the class EncodingIdMapperTest method shouldSkipNullValues.

@Test
public void shouldSkipNullValues() {
    // GIVEN
    MutableLong highDataIndex = new MutableLong();
    MutableLong highTrackerIndex = new MutableLong();
    EncodingIdMapper.Monitor monitor = new EncodingIdMapper.Monitor() {

        @Override
        public void preparing(long highestSetDataIndex, long highestSetTrackerIndex) {
            highDataIndex.setValue(highestSetDataIndex);
            highTrackerIndex.setValue(highestSetTrackerIndex);
        }
    };
    IdMapper idMapper = mapper(new LongEncoder(), Radix.LONG, monitor);
    long count = 1_000;
    for (long id = 0; id < count; id++) {
        long nodeId = id * 2;
        idMapper.put(id, nodeId, Group.GLOBAL);
    }
    // WHEN
    idMapper.prepare((nodeId, cursorContext) -> {
        throw new RuntimeException("Should not be called");
    }, Collector.EMPTY, NONE);
    // THEN
    assertEquals((count - 1) * 2, highDataIndex.longValue());
    assertEquals(count - 1, highTrackerIndex.longValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) IdMapper(org.neo4j.internal.batchimport.cache.idmapping.IdMapper) Test(org.junit.Test)

Aggregations

IdMapper (org.neo4j.internal.batchimport.cache.idmapping.IdMapper)21 Test (org.junit.Test)19 Collector (org.neo4j.internal.batchimport.input.Collector)16 PropertyValueLookup (org.neo4j.internal.batchimport.PropertyValueLookup)9 ArrayList (java.util.ArrayList)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Group (org.neo4j.internal.batchimport.input.Group)7 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)5 Math.toIntExact (java.lang.Math.toIntExact)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Random (java.util.Random)4 Set (java.util.Set)4 UUID (java.util.UUID)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 LongFunction (java.util.function.LongFunction)4