Search in sources :

Example 31 with RelationshipRecord

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

the class RelationshipChainExplorer method expandChain.

private RecordSet<RelationshipRecord> expandChain(RelationshipRecord record, long nodeId, RelationshipChainDirection direction) {
    RecordSet<RelationshipRecord> chain = new RecordSet<>();
    chain.add(record);
    RelationshipRecord currentRecord = record;
    long nextRelId = direction.fieldFor(nodeId, currentRecord).relOf(currentRecord);
    while (currentRecord.inUse() && !direction.fieldFor(nodeId, currentRecord).endOfChain(currentRecord)) {
        currentRecord = recordStore.getRecord(nextRelId, recordStore.newRecord(), FORCE);
        chain.add(currentRecord);
        nextRelId = direction.fieldFor(nodeId, currentRecord).relOf(currentRecord);
    }
    return chain;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 32 with RelationshipRecord

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

the class StorageLayer method relationshipVisit.

@Override
public <EXCEPTION extends Exception> void relationshipVisit(long relationshipId, RelationshipVisitor<EXCEPTION> relationshipVisitor) throws EntityNotFoundException, EXCEPTION {
    // TODO Please don't create a record for this, it's ridiculous
    RelationshipRecord record = relationshipStore.getRecord(relationshipId, relationshipStore.newRecord(), CHECK);
    if (!record.inUse()) {
        throw new EntityNotFoundException(EntityType.RELATIONSHIP, relationshipId);
    }
    relationshipVisitor.visit(relationshipId, record.getType(), record.getFirstNode(), record.getSecondNode());
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 33 with RelationshipRecord

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

the class StorageLayer method degreeRelationshipsInGroup.

@Override
public int degreeRelationshipsInGroup(StorageStatement storeStatement, long nodeId, long groupId, Direction direction, Integer relType) {
    RelationshipRecord relationshipRecord = relationshipStore.newRecord();
    RelationshipGroupRecord relationshipGroupRecord = relationshipGroupStore.newRecord();
    return countRelationshipsInGroup(groupId, direction, relType, nodeId, relationshipRecord, relationshipGroupRecord, storeStatement.recordCursors());
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 34 with RelationshipRecord

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

the class StorageLayer method visitDenseNode.

private void visitDenseNode(StorageStatement statement, NodeItem nodeItem, DegreeVisitor visitor) {
    RelationshipGroupRecord relationshipGroupRecord = relationshipGroupStore.newRecord();
    RecordCursor<RelationshipGroupRecord> relationshipGroupCursor = statement.recordCursors().relationshipGroup();
    RelationshipRecord relationshipRecord = relationshipStore.newRecord();
    RecordCursor<RelationshipRecord> relationshipCursor = statement.recordCursors().relationship();
    long groupId = nodeItem.nextGroupId();
    while (groupId != NO_NEXT_RELATIONSHIP.longValue()) {
        relationshipGroupCursor.next(groupId, relationshipGroupRecord, FORCE);
        if (relationshipGroupRecord.inUse()) {
            int type = relationshipGroupRecord.getType();
            long firstLoop = relationshipGroupRecord.getFirstLoop();
            long firstOut = relationshipGroupRecord.getFirstOut();
            long firstIn = relationshipGroupRecord.getFirstIn();
            long loop = countByFirstPrevPointer(firstLoop, relationshipCursor, nodeItem.id(), relationshipRecord);
            long outgoing = countByFirstPrevPointer(firstOut, relationshipCursor, nodeItem.id(), relationshipRecord) + loop;
            long incoming = countByFirstPrevPointer(firstIn, relationshipCursor, nodeItem.id(), relationshipRecord) + loop;
            visitor.visitDegree(type, outgoing, incoming);
        }
        groupId = relationshipGroupRecord.getNext();
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 35 with RelationshipRecord

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

the class PhysicalLogCommandReaderV2_1 method visitRelationshipCommand.

private Command visitRelationshipCommand(ReadableChannel channel) throws IOException {
    long id = channel.getLong();
    byte flags = channel.get();
    boolean inUse = false;
    if (notFlag(notFlag(flags, Record.IN_USE.byteValue()), Record.CREATED_IN_TX) != 0) {
        throw new IOException("Illegal in use flag: " + flags);
    }
    if (bitFlag(flags, Record.IN_USE.byteValue())) {
        inUse = true;
    }
    RelationshipRecord record;
    if (inUse) {
        record = new RelationshipRecord(id, channel.getLong(), channel.getLong(), channel.getInt());
        record.setInUse(true);
        record.setFirstPrevRel(channel.getLong());
        record.setFirstNextRel(channel.getLong());
        record.setSecondPrevRel(channel.getLong());
        record.setSecondNextRel(channel.getLong());
        record.setNextProp(channel.getLong());
        byte extraByte = channel.get();
        record.setFirstInFirstChain((extraByte & 0x1) > 0);
        record.setFirstInSecondChain((extraByte & 0x2) > 0);
    } else {
        record = new RelationshipRecord(id);
        record.setInUse(false);
    }
    if (bitFlag(flags, Record.CREATED_IN_TX)) {
        record.setCreated();
    }
    return new Command.RelationshipCommand(null, record);
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) IOException(java.io.IOException)

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