Search in sources :

Example 16 with RelationshipGroupRecord

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

the class StorageLayer method relationshipTypes.

@Override
public PrimitiveIntSet relationshipTypes(StorageStatement statement, NodeItem node) {
    PrimitiveIntSet set = intSet();
    if (node.isDense()) {
        RelationshipGroupRecord groupRecord = relationshipGroupStore.newRecord();
        RecordCursor<RelationshipGroupRecord> cursor = statement.recordCursors().relationshipGroup();
        for (long id = node.nextGroupId(); id != NO_NEXT_RELATIONSHIP.intValue(); id = groupRecord.getNext()) {
            if (cursor.next(id, groupRecord, FORCE)) {
                set.add(groupRecord.getType());
            }
        }
    } else {
        nodeGetRelationships(statement, node, Direction.BOTH).forAll(relationship -> set.add(relationship.type()));
    }
    return set;
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet)

Example 17 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord 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 18 with RelationshipGroupRecord

use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord 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 19 with RelationshipGroupRecord

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

the class EncodeGroupsStepTest method shouldEncodeGroupChains.

@SuppressWarnings("unchecked")
@Test
public void shouldEncodeGroupChains() throws Throwable {
    // GIVEN
    StageControl control = mock(StageControl.class);
    final AtomicLong nextId = new AtomicLong();
    RecordStore<RelationshipGroupRecord> store = mock(RecordStore.class);
    when(store.nextId()).thenAnswer(invocation -> nextId.incrementAndGet());
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, RelationshipGroupRecord.class).setFirstOut(1);
        return null;
    }).when(store).prepareForCommit(any(RelationshipGroupRecord.class));
    Configuration config = Configuration.withBatchSize(DEFAULT, 10);
    EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store);
    // WHEN
    encoder.start(Step.ORDER_SEND_DOWNSTREAM);
    Catcher catcher = new Catcher();
    encoder.process(batch(new Group(1, 3), new Group(2, 3), new Group(3, 4)), catcher);
    encoder.process(batch(new Group(4, 2), new Group(5, 10)), catcher);
    encoder.process(batch(new Group(6, 35)), catcher);
    encoder.process(batch(new Group(7, 2)), catcher);
    encoder.endOfUpstream();
    while (!encoder.isCompleted()) {
        Thread.sleep(10);
    }
    encoder.close();
    // THEN
    assertEquals(4, catcher.batches.size());
    long lastOwningNodeLastBatch = -1;
    for (RelationshipGroupRecord[] batch : catcher.batches) {
        assertBatch(batch, lastOwningNodeLastBatch);
        lastOwningNodeLastBatch = batch[batch.length - 1].getOwningNode();
    }
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.ReadGroupsFromCacheStepTest.Group) AtomicLong(java.util.concurrent.atomic.AtomicLong) StageControl(org.neo4j.unsafe.impl.batchimport.staging.StageControl) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Example 20 with RelationshipGroupRecord

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

the class RelationshipGroupRecordFormatTest method useFixedReferenceFormatWhenRecordCanFitInRecordSizeRecord.

@Test
public void useFixedReferenceFormatWhenRecordCanFitInRecordSizeRecord() throws IOException {
    RelationshipGroupRecord source = new RelationshipGroupRecord(1);
    RelationshipGroupRecord target = new RelationshipGroupRecord(1);
    source.initialize(true, randomType(), randomFixedReference(), randomFixedReference(), randomFixedReference(), randomFixedReference(), randomFixedReference());
    writeReadRecord(source, target, RelationshipGroupRecordFormat.FIXED_FORMAT_RECORD_SIZE);
    assertTrue("Record should use fixed reference if can fit in format record.", target.isUseFixedReferences());
    verifySame(source, target);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Aggregations

RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)83 Test (org.junit.Test)42 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)24 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)11 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)11 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)11 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)10 Command (org.neo4j.kernel.impl.transaction.command.Command)5 IOException (java.io.IOException)4 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)4 File (java.io.File)3 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 Transaction (org.neo4j.graphdb.Transaction)3 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)3 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)3 RelationshipGroupCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipGroupCommand)3