Search in sources :

Example 71 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class TransactionRecordStateTest method manuallyCountRelationships.

private static int manuallyCountRelationships(RecordChangeSet recordChangeSet, long nodeId, long firstRelId) {
    int count = 0;
    long relId = firstRelId;
    while (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        count++;
        RelationshipRecord record = recordChangeSet.getRelRecords().getOrLoad(relId, null, NULL).forReadingData();
        relId = record.getFirstNode() == nodeId ? record.getFirstNextRel() : record.getSecondNextRel();
    }
    return count;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 72 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class TransactionRecordStateTest method assertDenseRelationshipCounts.

private static void assertDenseRelationshipCounts(TransactionRecordState tx, RecordChangeSet recordChangeSet, long nodeId, int type, int outCount, int inCount) {
    RecordProxy<RelationshipGroupRecord, Integer> proxy = getRelationshipGroup(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null, NULL).forReadingData(), type);
    assertNotNull(proxy);
    RelationshipGroupRecord group = proxy.forReadingData();
    assertNotNull(group);
    RelationshipRecord rel;
    long relId = group.getFirstOut();
    if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        rel = recordChangeSet.getRelRecords().getOrLoad(relId, null, NULL).forReadingData();
        // count is stored in the back pointer of the first relationship in the chain
        assertEquals(outCount, plusFromGroupDegreesStore(tx, rel.getFirstPrevRel(), group, RelationshipDirection.OUTGOING, recordChangeSet, nodeId), "Stored relationship count for OUTGOING differs");
        assertEquals(outCount, manuallyCountRelationships(recordChangeSet, nodeId, relId), "Manually counted relationships for OUTGOING differs");
    }
    relId = group.getFirstIn();
    if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        rel = recordChangeSet.getRelRecords().getOrLoad(relId, null, NULL).forReadingData();
        assertEquals(inCount, plusFromGroupDegreesStore(tx, rel.getSecondPrevRel(), group, RelationshipDirection.INCOMING, recordChangeSet, nodeId), "Stored relationship count for INCOMING differs");
        assertEquals(inCount, manuallyCountRelationships(recordChangeSet, nodeId, relId), "Manually counted relationships for INCOMING differs");
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 73 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class RelationshipStoreConsistentReadTest method createExistingRecord.

@Override
protected RelationshipRecord createExistingRecord(boolean light) {
    RelationshipRecord record = new RelationshipRecord(ID);
    record.initialize(true, 0, FIRST_NODE, SECOND_NODE, TYPE, FIRST_PREV_REL, FIRST_NEXT_REL, SECOND_PREV_REL, SECOND_NEXT_REL, true, true);
    return record;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 74 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class FullCheckIntegrationTest method shouldHandleNegativeRelationshipPointers.

@Test
void shouldHandleNegativeRelationshipPointers() throws Exception {
    // given
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            long node = next.node();
            long otherNode = next.node();
            long rel = next.relationship();
            tx.create(new NodeRecord(node).initialize(false, NO_NEXT_PROPERTY.intValue(), false, rel, 0));
            tx.create(new NodeRecord(otherNode).initialize(false, NO_NEXT_PROPERTY.intValue(), false, rel, 0));
            RelationshipRecord relationship = new RelationshipRecord(rel);
            relationship.setLinks(node, otherNode, C);
            // Set some negative pointers
            relationship.setFirstNextRel(-3);
            relationship.setFirstPrevRel(-4);
            relationship.setSecondNextRel(-5);
            relationship.setSecondPrevRel(-6);
            tx.create(relationship);
            tx.incrementRelationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, 1);
            tx.incrementRelationshipCount(ANY_LABEL, C, ANY_LABEL, 1);
        }
    });
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.RELATIONSHIP, expectedNumberOfErrorsForNegativeRelationshipPointerInconsistency()).andThatsAllFolks();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 75 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class RelationshipChainCheckerTest method shouldReportReferencesOtherNodes.

private void shouldReportReferencesOtherNodes(boolean forward, Consumer<RelationshipRecord> vandal, Consumer<RelationshipConsistencyReport> expectedReport) throws Exception {
    long[] relationshipIds = new long[20];
    try (Transaction tx = db.beginTx()) {
        Node[] nodes = new Node[] { tx.getNodeById(nodeId1), tx.getNodeById(nodeId2), tx.getNodeById(nodeId3) };
        for (int i = 0; i < relationshipIds.length; i++) {
            Node node1 = nodes[i % nodes.length];
            Node node2 = nodes[(i + 1) % nodes.length];
            Node startNode = forward ? node1 : node2;
            Node endNode = forward ? node2 : node1;
            Relationship relationship = endNode.createRelationshipTo(startNode, TYPE);
            relationshipIds[i] = relationship.getId();
        }
        tx.commit();
    }
    RelationshipStore relationshipStore = context(numberOfThreads()).neoStores.getRelationshipStore();
    RelationshipRecord arbitraryRelationship = relationshipStore.getRecord(relationshipIds[relationshipIds.length / 2], relationshipStore.newRecord(), NORMAL, CursorContext.NULL);
    vandal.accept(arbitraryRelationship);
    relationshipStore.updateRecord(arbitraryRelationship, CursorContext.NULL);
    // when
    check();
    // then
    expect(RelationshipConsistencyReport.class, expectedReport);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) 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