Search in sources :

Example 46 with RelationshipScanCursor

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

the class ManagedTestCursors method allocateRelationshipScanCursor.

@Override
public RelationshipScanCursor allocateRelationshipScanCursor(CursorContext cursorContext) {
    RelationshipScanCursor n = cursors.allocateRelationshipScanCursor(cursorContext);
    allCursors.add(n);
    return n;
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor)

Example 47 with RelationshipScanCursor

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

the class KernelReadTracerTxStateTest method shouldTraceSingleRelationship.

@Test
void shouldTraceSingleRelationship() throws Exception {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(tx.cursorContext())) {
        long n1 = tx.dataWrite().nodeCreate();
        long n2 = tx.dataWrite().nodeCreate();
        long r = tx.dataWrite().relationshipCreate(n1, tx.token().relationshipTypeGetOrCreateForName("R"), n2);
        // when
        cursor.setTracer(tracer);
        tx.dataRead().singleRelationship(r, cursor);
        assertTrue(cursor.next());
        tracer.assertEvents(OnRelationship(r));
        long deleted = tx.dataWrite().relationshipCreate(n1, tx.token().relationshipTypeGetOrCreateForName("R"), n2);
        tx.dataWrite().relationshipDelete(deleted);
        tx.dataRead().singleRelationship(deleted, cursor);
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) Test(org.junit.jupiter.api.Test)

Example 48 with RelationshipScanCursor

use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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 49 with RelationshipScanCursor

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

the class SchemaCalculator method scanEverythingBelongingToRelationships.

private void scanEverythingBelongingToRelationships(RelationshipMappings relMappings, CursorContext cursorContext, MemoryTracker memoryTracker) {
    try (RelationshipScanCursor relationshipScanCursor = cursors.allocateRelationshipScanCursor(cursorContext);
        PropertyCursor propertyCursor = cursors.allocatePropertyCursor(cursorContext, memoryTracker)) {
        dataRead.allRelationshipsScan(relationshipScanCursor);
        while (relationshipScanCursor.next()) {
            int typeId = relationshipScanCursor.type();
            relationshipScanCursor.properties(propertyCursor);
            MutableIntSet propertyIds = IntSets.mutable.empty();
            while (propertyCursor.next()) {
                int propertyKey = propertyCursor.propertyKey();
                Value currentValue = propertyCursor.propertyValue();
                Pair<Integer, Integer> key = Pair.of(typeId, propertyKey);
                updateValueTypeInMapping(currentValue, key, relMappings.relationshipTypeIdANDPropertyTypeIdToValueType);
                propertyIds.add(propertyKey);
            }
            propertyCursor.close();
            MutableIntSet oldPropertyKeySet = relMappings.relationshipTypeIdToPropertyKeys.getOrDefault(typeId, 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 rels with this type, set all of them nullable
                    relMappings.nullableRelationshipTypes.add(typeId);
                }
                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 rel
                oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);
                propertyIds.addAll(oldPropertyKeySet);
                propertyIds.forEach(id -> {
                    Pair<Integer, Integer> key = Pair.of(typeId, id);
                    relMappings.relationshipTypeIdANDPropertyTypeIdToValueType.get(key).setNullable();
                });
                propertyIds.addAll(currentPropertyIdsHelperSet);
            }
            relMappings.relationshipTypeIdToPropertyKeys.put(typeId, propertyIds);
        }
    }
}
Also used : RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Value(org.neo4j.values.storable.Value) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor)

Example 50 with RelationshipScanCursor

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

the class PathValueBuilderTest method builder.

private static PathValueBuilder builder(AnyValue... values) {
    DbAccess dbAccess = mock(DbAccess.class);
    RelationshipScanCursor cursors = mock(RelationshipScanCursor.class);
    Map<Long, RelationshipValue> relMap = new HashMap<>();
    for (AnyValue value : values) {
        if (value instanceof NodeValue) {
            NodeValue nodeValue = (NodeValue) value;
            when(dbAccess.nodeById(nodeValue.id())).thenReturn(nodeValue);
        } else if (value instanceof RelationshipValue) {
            RelationshipValue relationshipValue = (RelationshipValue) value;
            relMap.put(relationshipValue.id(), relationshipValue);
        } else {
            throw new AssertionError("invalid input");
        }
        Mockito.doAnswer((Answer<Void>) invocationOnMock -> {
            long id = invocationOnMock.getArgument(0);
            RelationshipScanCursor cursor = invocationOnMock.getArgument(1);
            RelationshipValue rel = relMap.get(id);
            when(cursor.sourceNodeReference()).thenReturn(rel.startNode().id());
            when(cursor.targetNodeReference()).thenReturn(rel.endNode().id());
            return null;
        }).when(dbAccess).singleRelationship(anyLong(), any(RelationshipScanCursor.class));
    }
    return new PathValueBuilder(dbAccess, cursors);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) EMPTY_MAP(org.neo4j.values.virtual.VirtualValues.EMPTY_MAP) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) NodeValue(org.neo4j.values.virtual.NodeValue) HashMap(java.util.HashMap) Mockito.when(org.mockito.Mockito.when) Values.stringValue(org.neo4j.values.storable.Values.stringValue) VirtualValues.list(org.neo4j.values.virtual.VirtualValues.list) EMPTY_LIST(org.neo4j.values.virtual.VirtualValues.EMPTY_LIST) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) EMPTY_TEXT_ARRAY(org.neo4j.values.storable.Values.EMPTY_TEXT_ARRAY) DbAccess(org.neo4j.cypher.internal.runtime.DbAccess) Map(java.util.Map) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) PathValue(org.neo4j.values.virtual.PathValue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) VirtualValues(org.neo4j.values.virtual.VirtualValues) Mockito.mock(org.mockito.Mockito.mock) NodeValue(org.neo4j.values.virtual.NodeValue) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) HashMap(java.util.HashMap) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) DbAccess(org.neo4j.cypher.internal.runtime.DbAccess)

Aggregations

RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)53 Test (org.junit.jupiter.api.Test)40 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)28 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)16 Write (org.neo4j.internal.kernel.api.Write)16 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)8 ExecutorService (java.util.concurrent.ExecutorService)7 LongList (org.eclipse.collections.api.list.primitive.LongList)7 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Read (org.neo4j.internal.kernel.api.Read)4 Future (java.util.concurrent.Future)3 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 TokenRead (org.neo4j.internal.kernel.api.TokenRead)3 KernelException (org.neo4j.exceptions.KernelException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1