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;
}
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();
}
}
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();
}
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);
}
}
}
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);
}
Aggregations