Search in sources :

Example 6 with StorageRelationshipTraversalCursor

use of org.neo4j.storageengine.api.StorageRelationshipTraversalCursor in project neo4j by neo4j.

the class DefaultRelationshipTraversalCursorTest method emptyStoreAllOfType.

@Test
void emptyStoreAllOfType() {
    // given
    StorageRelationshipTraversalCursor storeCursor = emptyStoreCursor();
    DefaultRelationshipTraversalCursor cursor = new DefaultRelationshipTraversalCursor(pool::accept, storeCursor, mock(DefaultNodeCursor.class));
    Read read = txState(rel(3, node, 50, type), rel(2, node, node, type), rel(5, 50, node, type2), rel(6, node, node, type), rel(7, 56, node, type), rel(8, node, 52, type));
    // when
    cursor.init(node, relationship, selection(type, Direction.BOTH), read);
    // then
    assertRelationships(cursor, 3, 8, 7, 2, 6);
}
Also used : StorageRelationshipTraversalCursor(org.neo4j.storageengine.api.StorageRelationshipTraversalCursor) Test(org.junit.jupiter.api.Test)

Example 7 with StorageRelationshipTraversalCursor

use of org.neo4j.storageengine.api.StorageRelationshipTraversalCursor in project neo4j by neo4j.

the class NeoStoresTest method allocateRelationshipTraversalCursor.

private StorageRelationshipTraversalCursor allocateRelationshipTraversalCursor(StorageNodeCursor node) {
    StorageRelationshipTraversalCursor relationships = storageReader.allocateRelationshipTraversalCursor(NULL);
    node.relationships(relationships, ALL_RELATIONSHIPS);
    return relationships;
}
Also used : StorageRelationshipTraversalCursor(org.neo4j.storageengine.api.StorageRelationshipTraversalCursor)

Example 8 with StorageRelationshipTraversalCursor

use of org.neo4j.storageengine.api.StorageRelationshipTraversalCursor in project neo4j by neo4j.

the class DegreesRebuildFromStore method rebuild.

@Override
public void rebuild(RelationshipGroupDegreesStore.Updater updater, CursorContext cursorContext, MemoryTracker memoryTracker) {
    // === sketch of a more performant version
    // - Read all groups and for every group make a mark in a memory-structure like so:
    // (node) -> (type,active directions,out,in,loop)
    // - Read all relationships and for every matching node go into the memory-structure
    // if it's there then look up the type
    // if it's there then see if the direction matches any active direction
    // if it does then increment the counter in the correct slot
    // - Go though the memory-structure and write to the updater
    // 
    // If not all data can fit in memory then do multiple passes (node id range)
    RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
    try (RecordStorageReader storageReader = new RecordStorageReader(neoStores);
        StorageRelationshipTraversalCursor traversalCursor = storageReader.allocateRelationshipTraversalCursor(cursorContext);
        PageCursor groupCursor = groupStore.openPageCursorForReadingWithPrefetching(0, cursorContext)) {
        RelationshipGroupRecord groupRecord = groupStore.newRecord();
        long highGroupId = groupStore.getHighId();
        for (long id = groupStore.getNumberOfReservedLowIds(); id < highGroupId; id++) {
            groupStore.getRecordByCursor(id, groupRecord, RecordLoad.LENIENT_CHECK, groupCursor);
            if (groupRecord.inUse() && (groupRecord.hasExternalDegreesOut() || groupRecord.hasExternalDegreesIn() || groupRecord.hasExternalDegreesLoop())) {
                updateDegree(groupRecord.hasExternalDegreesOut(), groupRecord.getFirstOut(), groupRecord, OUTGOING, traversalCursor, updater);
                updateDegree(groupRecord.hasExternalDegreesIn(), groupRecord.getFirstIn(), groupRecord, INCOMING, traversalCursor, updater);
                updateDegree(groupRecord.hasExternalDegreesLoop(), groupRecord.getFirstLoop(), groupRecord, LOOP, traversalCursor, updater);
            }
        }
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RecordStorageReader(org.neo4j.internal.recordstorage.RecordStorageReader) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) StorageRelationshipTraversalCursor(org.neo4j.storageengine.api.StorageRelationshipTraversalCursor) PageCursor(org.neo4j.io.pagecache.PageCursor)

Aggregations

StorageRelationshipTraversalCursor (org.neo4j.storageengine.api.StorageRelationshipTraversalCursor)8 Test (org.junit.jupiter.api.Test)6 RecordStorageReader (org.neo4j.internal.recordstorage.RecordStorageReader)1 PageCursor (org.neo4j.io.pagecache.PageCursor)1 RelationshipGroupStore (org.neo4j.kernel.impl.store.RelationshipGroupStore)1 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)1