use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RecordRelationshipTraversalCursorTest method unUseRecord.
protected void unUseRecord(long recordId) {
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
RelationshipRecord relationshipRecord = relationshipStore.getRecord(recordId, new RelationshipRecord(-1), RecordLoad.FORCE, CursorContext.NULL);
relationshipRecord.setInUse(false);
relationshipStore.updateRecord(relationshipRecord, CursorContext.NULL);
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RelationshipChainVisitor method visitRelationships.
private void visitRelationships(long nodeId, long relationshipId, Visitor visitor) {
while (!isNull(relationshipId)) {
RelationshipRecord relationship = relationshipStore.apply(relationshipId);
visitor.relationship(relationship);
relationshipId = relationship.getNextRel(nodeId);
}
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RelationshipLockHelperTest method avoidTakingDuplicateLocks.
@Test
void avoidTakingDuplicateLocks() {
MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
MutableLongSet idsToDelete = LongSets.mutable.empty();
MutableLongBag expectedLocks = LongBags.mutable.empty();
idsToDelete.add(1);
RelationshipRecord record = new RelationshipRecord(1);
record.initialize(true, 1, 2, 3, 4, 5, 7, 7, 5, false, false);
var proxy = mock(RecordAccess.RecordProxy.class);
when(proxy.forReadingLinkage()).thenAnswer(invocation -> record);
proxies.put(1, proxy);
RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), 2, relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
List<ActiveLock> activeLocks = locks.activeLocks().collect(Collectors.toList());
assertThat(activeLocks).hasSize(4).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 1)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 2)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 5)).contains(new ActiveLock(ResourceTypes.RELATIONSHIP, LockType.EXCLUSIVE, -1, 7));
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RelationshipLockHelperTest method shouldTakeAllRelevantLocksForDeletion.
@ParameterizedTest
@ValueSource(ints = { 1, 10, 100, 1000 })
void shouldTakeAllRelevantLocksForDeletion(int numNodes) {
// Given
MutableLongObjectMap<RecordAccess.RecordProxy<RelationshipRecord, Void>> proxies = LongObjectMaps.mutable.empty();
MutableLongBag expectedLocks = LongBags.mutable.empty();
MutableLongSet idsToDelete = LongSets.mutable.empty();
int maxId = numNodes * 10;
for (int i = 0; i < numNodes; i++) {
long id = random.nextInt(maxId);
if (idsToDelete.add(id)) {
VolatileRelationshipRecord record = new VolatileRelationshipRecord(id, expectedLocks, maxId);
var proxy = mock(RecordAccess.RecordProxy.class);
when(proxy.forReadingLinkage()).thenAnswer(invocation -> new RelationshipRecord(record.maybeChange()));
proxies.put(id, proxy);
}
}
RecordAccess<RelationshipRecord, Void> relRecords = mock(RecordAccess.class);
when(relRecords.getOrLoad(Mockito.anyLong(), Mockito.any(), Mockito.any())).thenAnswer(invocation -> proxies.get(invocation.getArgument(0)));
TrackingResourceLocker locks = new TrackingResourceLocker(random, NO_MONITOR).withStrictAssertionsOn(ResourceTypes.RELATIONSHIP);
// When
RelationshipLockHelper.lockRelationshipsInOrder(idsAsBatch(idsToDelete), NULL_REFERENCE.longValue(), relRecords, locks, CursorContext.NULL, EmptyMemoryTracker.INSTANCE);
// Then
assertThat(locks.getExclusiveLocks(ResourceTypes.RELATIONSHIP).toSortedArray()).containsExactly(expectedLocks.toSet().toSortedArray());
}
use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.
the class RecordRelationshipTraversalCursorTest method createRelationship.
protected static RelationshipRecord createRelationship(long id, long nextRelationship, RelationshipSpec relationshipSpec) {
RelationshipRecord relationship = new RelationshipRecord(id);
relationship.initialize(true, NO_NEXT_PROPERTY.intValue(), getFirstNode(relationshipSpec.direction), getSecondNode(relationshipSpec.direction), relationshipSpec.type, NO_NEXT_RELATIONSHIP.intValue(), nextRelationship, NO_NEXT_RELATIONSHIP.intValue(), nextRelationship, false, false);
return relationship;
}
Aggregations