Search in sources :

Example 36 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class KernelReadTracerTxStateTest method shouldTracePropertyAccess.

@Test
void shouldTracePropertyAccess() throws Exception {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
        long n = tx.dataWrite().nodeCreate();
        int name = tx.token().propertyKey("name");
        tx.dataWrite().nodeSetProperty(n, name, Values.stringValue("Bosse"));
        // when
        propertyCursor.setTracer(tracer);
        tx.dataRead().singleNode(n, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.properties(propertyCursor);
        assertTrue(propertyCursor.next());
        tracer.assertEvents(OnProperty(name));
        assertFalse(propertyCursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 37 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class NodeTransactionStateTestBase method shouldSeeNewNodePropertyInTransaction.

@Test
void shouldSeeNewNodePropertyInTransaction() throws Exception {
    long nodeId;
    String propKey1 = "prop1";
    String propKey2 = "prop2";
    try (KernelTransaction tx = beginTransaction()) {
        nodeId = tx.dataWrite().nodeCreate();
        int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
        int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")));
        assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")));
        try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
            PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
            tx.dataRead().singleNode(nodeId, node);
            assertTrue(node.next(), "should access node");
            node.properties(property);
            IntObjectHashMap<Value> foundProperties = IntObjectHashMap.newMap();
            while (property.next()) {
                assertNull(foundProperties.put(property.propertyKey(), property.propertyValue()), "should only find each property once");
            }
            assertThat(foundProperties).hasSize(2);
            assertThat(foundProperties.get(prop1)).isEqualTo(stringValue("hello"));
            assertThat(foundProperties.get(prop2)).isEqualTo(stringValue("world"));
            assertFalse(node.next(), "should only find one node");
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.longValue(org.neo4j.values.storable.Values.longValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 38 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class NodeWriteTestBase method shouldSetAndReadLargeByteArrayPropertyToNode.

@Test
void shouldSetAndReadLargeByteArrayPropertyToNode() throws Exception {
    // Given
    int prop;
    long node = createNode();
    Value largeByteArray = Values.of(new byte[100_000]);
    // When
    try (KernelTransaction tx = beginTransaction()) {
        prop = tx.token().propertyKeyGetOrCreateForName(propertyKey);
        assertThat(tx.dataWrite().nodeSetProperty(node, prop, largeByteArray)).isEqualTo(NO_VALUE);
        tx.commit();
    }
    // Then
    try (KernelTransaction tx = beginTransaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
        tx.dataRead().singleNode(node, nodeCursor);
        assertTrue(nodeCursor.next());
        nodeCursor.properties(propertyCursor);
        assertTrue(propertyCursor.next());
        assertEquals(propertyCursor.propertyKey(), prop);
        assertThat(propertyCursor.propertyValue()).isEqualTo(largeByteArray);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 39 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class FulltextIndexTransactionState method updateSearcher.

private void updateSearcher(QueryContext context, CursorContext cursorContext, MemoryTracker memoryTracker) throws Exception {
    Read read = context.getRead();
    CursorFactory cursors = context.cursors();
    ReadableTransactionState state = context.getTransactionStateOrNull();
    // Clear this, so we don't filter out entities who have had their changes reversed since last time.
    modifiedEntityIdsInThisTransaction.clear();
    writer.resetWriterState();
    try (NodeCursor nodeCursor = visitingNodes ? cursors.allocateFullAccessNodeCursor(cursorContext) : null;
        RelationshipScanCursor relationshipCursor = visitingNodes ? null : cursors.allocateRelationshipScanCursor(cursorContext);
        PropertyCursor propertyCursor = cursors.allocateFullAccessPropertyCursor(cursorContext, memoryTracker)) {
        state.accept(txStateVisitor.init(read, nodeCursor, relationshipCursor, propertyCursor));
    }
    currentSearcher = writer.getNearRealTimeSearcher();
    toCloseLater.add(currentSearcher);
    lastUpdateRevision = state.getDataRevision();
}
Also used : Read(org.neo4j.internal.kernel.api.Read) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 40 with PropertyCursor

use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.

the class SchemaCalculator method scanEverythingBelongingToNodes.

private void scanEverythingBelongingToNodes(NodeMappings nodeMappings, CursorContext cursorContext, MemoryTracker memoryTracker) {
    try (NodeCursor nodeCursor = cursors.allocateNodeCursor(cursorContext);
        PropertyCursor propertyCursor = cursors.allocatePropertyCursor(cursorContext, memoryTracker)) {
        dataRead.allNodesScan(nodeCursor);
        while (nodeCursor.next()) {
            // each node
            SortedLabels labels = SortedLabels.from(nodeCursor.labels());
            nodeCursor.properties(propertyCursor);
            MutableIntSet propertyIds = IntSets.mutable.empty();
            while (propertyCursor.next()) {
                Value currentValue = propertyCursor.propertyValue();
                int propertyKeyId = propertyCursor.propertyKey();
                Pair<SortedLabels, Integer> key = Pair.of(labels, propertyKeyId);
                updateValueTypeInMapping(currentValue, key, nodeMappings.labelSetANDNodePropertyKeyIdToValueType);
                propertyIds.add(propertyKeyId);
            }
            propertyCursor.close();
            MutableIntSet oldPropertyKeySet = nodeMappings.labelSetToPropertyKeys.getOrDefault(labels, emptyPropertyIdSet);
            // find out which old properties we did not visited and mark them as nullable
            if (oldPropertyKeySet == emptyPropertyIdSet) {
                if (propertyIds.size() == 0) {
                    // Even if we find property key on other nodes with those labels, set all of them nullable
                    nodeMappings.nullableLabelSets.add(labels);
                }
                propertyIds.addAll(oldPropertyKeySet);
            } else {
                MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
                currentPropertyIdsHelperSet.addAll(propertyIds);
                // only the brand new ones in propIds now
                propertyIds.removeAll(oldPropertyKeySet);
                // only the old ones that are not on the new node
                oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);
                propertyIds.addAll(oldPropertyKeySet);
                propertyIds.forEach(id -> {
                    Pair<SortedLabels, Integer> key = Pair.of(labels, id);
                    nodeMappings.labelSetANDNodePropertyKeyIdToValueType.get(key).setNullable();
                });
                propertyIds.addAll(currentPropertyIdsHelperSet);
            }
            nodeMappings.labelSetToPropertyKeys.put(labels, propertyIds);
        }
    }
}
Also used : MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Value(org.neo4j.values.storable.Value) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Aggregations

PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)48 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)33 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)30 Test (org.junit.jupiter.api.Test)29 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)16 Write (org.neo4j.internal.kernel.api.Write)7 TokenRead (org.neo4j.internal.kernel.api.TokenRead)4 Value (org.neo4j.values.storable.Value)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 MutableIntSet (org.eclipse.collections.api.set.primitive.MutableIntSet)2 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)2 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1