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