Search in sources :

Example 81 with RelationshipRecord

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);
}
Also used : RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 82 with RelationshipRecord

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);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 83 with RelationshipRecord

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));
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ActiveLock(org.neo4j.lock.ActiveLock) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 84 with RelationshipRecord

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());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 85 with RelationshipRecord

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;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Aggregations

RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)207 Test (org.junit.Test)73 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)69 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)43 Test (org.junit.jupiter.api.Test)34 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)30 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)19 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)14 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)12 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)12 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)12 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)11 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)9 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6