Search in sources :

Example 6 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class RecordStorageReaderRelTypesAndDegreeTest method testRelationshipTypesForDenseNode.

protected void testRelationshipTypesForDenseNode(LongConsumer nodeChanger, Set<TestRelType> expectedTypes) throws Exception {
    int inRelCount = randomRelCount();
    int outRelCount = randomRelCount();
    int loopRelCount = randomRelCount();
    long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
    nodeChanger.accept(nodeId);
    StorageNodeCursor cursor = newCursor(nodeId);
    assertEquals(expectedTypes, relTypes(cursor));
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 7 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class RecordStorageReaderRelTypesAndDegreeTest method testDegreeByDirectionForDenseNodeWithPartiallyDeletedRelGroupChain.

protected void testDegreeByDirectionForDenseNodeWithPartiallyDeletedRelGroupChain(TestRelType... typesToDelete) throws Exception {
    int inRelCount = randomRelCount();
    int outRelCount = randomRelCount();
    int loopRelCount = randomRelCount();
    long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
    StorageNodeCursor cursor = newCursor(nodeId);
    for (TestRelType type : typesToDelete) {
        markRelGroupNotInUse(nodeId, type);
        switch(type) {
            case IN:
                inRelCount = 0;
                break;
            case OUT:
                outRelCount = 0;
                break;
            case LOOP:
                loopRelCount = 0;
                break;
            default:
                throw new IllegalArgumentException("Unknown type: " + type);
        }
    }
    assertEquals(outRelCount + loopRelCount, degreeForDirection(cursor, OUTGOING));
    assertEquals(inRelCount + loopRelCount, degreeForDirection(cursor, INCOMING));
    assertEquals(inRelCount + outRelCount + loopRelCount, degreeForDirection(cursor, BOTH));
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 8 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class RecordStorageReaderRelTypesAndDegreeTest method testDegreesForDenseNodeWithPartiallyDeletedRelChains.

protected void testDegreesForDenseNodeWithPartiallyDeletedRelChains(boolean modifyInChain, boolean modifyOutChain, boolean modifyLoopChain) throws Exception {
    int inRelCount = randomRelCount();
    int outRelCount = randomRelCount();
    int loopRelCount = randomRelCount();
    long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
    StorageNodeCursor cursor = newCursor(nodeId);
    if (modifyInChain) {
        markRandomRelsInGroupNotInUse(nodeId, IN);
    }
    if (modifyOutChain) {
        markRandomRelsInGroupNotInUse(nodeId, OUT);
    }
    if (modifyLoopChain) {
        markRandomRelsInGroupNotInUse(nodeId, LOOP);
    }
    Set<TestDegreeItem> expectedDegrees = new HashSet<>(asList(new TestDegreeItem(relTypeId(OUT), outRelCount, 0), new TestDegreeItem(relTypeId(IN), 0, inRelCount), new TestDegreeItem(relTypeId(LOOP), loopRelCount, loopRelCount)));
    Set<TestDegreeItem> actualDegrees = degrees(cursor);
    assertEquals(expectedDegrees, actualDegrees);
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) HashSet(java.util.HashSet)

Example 9 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class GraphStoreFixture method nodeAsUpdates.

public EntityUpdates nodeAsUpdates(long nodeId) {
    try (StorageReader storeReader = storageEngine.newReader();
        StorageNodeCursor nodeCursor = storeReader.allocateNodeCursor(NULL);
        StoragePropertyCursor propertyCursor = storeReader.allocatePropertyCursor(NULL, INSTANCE)) {
        nodeCursor.single(nodeId);
        long[] labels;
        if (!nodeCursor.next() || !nodeCursor.hasProperties() || (labels = nodeCursor.labels()).length == 0) {
            return null;
        }
        nodeCursor.properties(propertyCursor);
        EntityUpdates.Builder update = EntityUpdates.forEntity(nodeId, true).withTokens(labels);
        while (propertyCursor.next()) {
            update.added(propertyCursor.propertyKey(), propertyCursor.propertyValue());
        }
        return update.build();
    }
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) EntityUpdates(org.neo4j.storageengine.api.EntityUpdates) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 10 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.

@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
    // given
    StubStorageCursors data = new StubStorageCursors();
    int numNodes = 10;
    MutableLongSet relevantNodeIds = LongSets.mutable.empty();
    for (int i = 0; i < numNodes; i++) {
        int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
        data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
        if (labelId == LABEL) {
            relevantNodeIds.add(i);
        }
    }
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), false, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    GeneratedIndexUpdates updates = sender.batches.get(0);
    updates.completeBatch();
    for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
        assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
    }
    assertThat(relevantNodeIds.isEmpty()).isTrue();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)12 Test (org.junit.jupiter.api.Test)8 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)7 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 CursorEntityIdIterator (org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator)5 StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)5 HashSet (java.util.HashSet)4 Value (org.neo4j.values.storable.Value)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1