Search in sources :

Example 1 with RelationshipGroupStore

use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.

the class MockedNeoStores method basicMockedNeoStores.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static NeoStores basicMockedNeoStores() {
    NeoStores neoStores = mock(NeoStores.class);
    // Cursor, absolutely mocked and cannot be used at all as it is
    RecordCursor cursor = mockedRecordCursor();
    // NodeStore - DynamicLabelStore
    NodeStore nodeStore = mock(NodeStore.class);
    when(nodeStore.newRecordCursor(any())).thenReturn(cursor);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    // NodeStore - DynamicLabelStore
    DynamicArrayStore dynamicLabelStore = mock(DynamicArrayStore.class);
    when(dynamicLabelStore.newRecordCursor(any())).thenReturn(cursor);
    when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
    // RelationshipStore
    RelationshipStore relationshipStore = mock(RelationshipStore.class);
    when(relationshipStore.newRecordCursor(any())).thenReturn(cursor);
    when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
    // RelationshipGroupStore
    RelationshipGroupStore relationshipGroupStore = mock(RelationshipGroupStore.class);
    when(relationshipGroupStore.newRecordCursor(any())).thenReturn(cursor);
    when(neoStores.getRelationshipGroupStore()).thenReturn(relationshipGroupStore);
    // PropertyStore
    PropertyStore propertyStore = mock(PropertyStore.class);
    when(propertyStore.newRecordCursor(any())).thenReturn(cursor);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    // PropertyStore -- DynamicStringStore
    DynamicStringStore propertyStringStore = mock(DynamicStringStore.class);
    when(propertyStringStore.newRecordCursor(any())).thenReturn(cursor);
    when(propertyStore.getStringStore()).thenReturn(propertyStringStore);
    // PropertyStore -- DynamicArrayStore
    DynamicArrayStore propertyArrayStore = mock(DynamicArrayStore.class);
    when(propertyArrayStore.newRecordCursor(any())).thenReturn(cursor);
    when(propertyStore.getArrayStore()).thenReturn(propertyArrayStore);
    return neoStores;
}
Also used : RecordCursor(org.neo4j.kernel.impl.store.RecordCursor) NodeStore(org.neo4j.kernel.impl.store.NodeStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) DynamicArrayStore(org.neo4j.kernel.impl.store.DynamicArrayStore) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 2 with RelationshipGroupStore

use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.

the class StoreIteratorRelationshipCursorTest method newRecordCursorsWithMockedNeoStores.

private static RecordCursors newRecordCursorsWithMockedNeoStores(RelationshipStore relationshipStore) {
    NeoStores neoStores = mock(NeoStores.class);
    NodeStore nodeStore = newStoreMockWithRecordCursor(NodeStore.class);
    RelationshipGroupStore relGroupStore = newStoreMockWithRecordCursor(RelationshipGroupStore.class);
    PropertyStore propertyStore = newStoreMockWithRecordCursor(PropertyStore.class);
    DynamicStringStore dynamicStringStore = newStoreMockWithRecordCursor(DynamicStringStore.class);
    DynamicArrayStore dynamicArrayStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
    DynamicArrayStore dynamicLabelStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
    when(neoStores.getRelationshipGroupStore()).thenReturn(relGroupStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getStringStore()).thenReturn(dynamicStringStore);
    when(propertyStore.getArrayStore()).thenReturn(dynamicArrayStore);
    when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
    return new RecordCursors(neoStores);
}
Also used : NodeStore(org.neo4j.kernel.impl.store.NodeStore) DynamicStringStore(org.neo4j.kernel.impl.store.DynamicStringStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) DynamicArrayStore(org.neo4j.kernel.impl.store.DynamicArrayStore) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore)

Example 3 with RelationshipGroupStore

use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.

the class RelationshipGroupDefragmenterTest method verifyGroupsAreSequentiallyOrderedByNode.

private void verifyGroupsAreSequentiallyOrderedByNode() {
    RelationshipGroupStore store = stores.getRelationshipGroupStore();
    long firstId = store.getNumberOfReservedLowIds();
    long groupCount = store.getHighId() - firstId;
    RelationshipGroupRecord groupRecord = store.newRecord();
    PageCursor groupCursor = store.openPageCursorForReading(firstId, NULL);
    long highGroupId = store.getHighId();
    long currentNodeId = -1;
    int currentTypeId = -1;
    int newGroupCount = 0;
    int currentGroupLength = 0;
    for (long id = firstId; id < highGroupId; id++, newGroupCount++) {
        store.getRecordByCursor(id, groupRecord, CHECK, groupCursor);
        if (!groupRecord.inUse()) {
            // This will be the case if we have double record units, just assert that fact
            assertTrue(units > 1);
            assertTrue(currentGroupLength > 0);
            currentGroupLength--;
            continue;
        }
        long nodeId = groupRecord.getOwningNode();
        assertTrue(nodeId >= currentNodeId, "Expected a group for node >= " + currentNodeId + ", but was " + nodeId + " in " + groupRecord);
        if (nodeId != currentNodeId) {
            currentNodeId = nodeId;
            currentTypeId = -1;
            if (units > 1) {
                assertEquals(0, currentGroupLength);
            }
            currentGroupLength = 0;
        }
        currentGroupLength++;
        assertTrue(groupRecord.getNext() == groupRecord.getId() + 1 || groupRecord.getNext() == Record.NO_NEXT_RELATIONSHIP.intValue(), "Expected this group to have a next of current + " + units + " OR NULL, " + "but was " + groupRecord);
        assertTrue(groupRecord.getType() > currentTypeId, "Expected " + groupRecord + " to have type > " + currentTypeId);
        currentTypeId = groupRecord.getType();
    }
    assertEquals(groupCount, newGroupCount);
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) PageCursor(org.neo4j.io.pagecache.PageCursor)

Example 4 with RelationshipGroupStore

use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.

the class TransactionRecordStateTest method shouldDeleteEmptyGroupsWhenDeletingNode.

@Test
void shouldDeleteEmptyGroupsWhenDeletingNode() throws Exception {
    // given
    // node --> group A (empty) --> group B (empty) --> group C (empty)
    neoStores = createStores();
    NodeStore nodeStore = neoStores.getNodeStore();
    RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
    long nodeId = nodeStore.nextId(NULL);
    long groupA = groupStore.nextId(NULL);
    long groupB = groupStore.nextId(NULL);
    long groupC = groupStore.nextId(NULL);
    groupStore.updateRecord(new RelationshipGroupRecord(groupA).initialize(true, 0, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, groupB), NULL);
    groupStore.updateRecord(new RelationshipGroupRecord(groupB).initialize(true, 1, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, groupC), NULL);
    groupStore.updateRecord(new RelationshipGroupRecord(groupC).initialize(true, 2, NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), NULL_REFERENCE.longValue(), nodeId, NULL_REFERENCE.longValue()), NULL);
    nodeStore.updateRecord(new NodeRecord(nodeId).initialize(true, NO_NEXT_PROPERTY.longValue(), true, groupA, Record.NO_LABELS_FIELD.longValue()), NULL);
    // when
    TransactionRecordState state = newTransactionRecordState();
    state.nodeDelete(nodeId);
    apply(state);
    // then
    assertThat(nodeStore.isInUse(nodeId, NULL)).isFalse();
    assertThat(groupStore.isInUse(groupA, NULL)).isFalse();
    assertThat(groupStore.isInUse(groupB, NULL)).isFalse();
    assertThat(groupStore.isInUse(groupC, NULL)).isFalse();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) Test(org.junit.jupiter.api.Test)

Example 5 with RelationshipGroupStore

use of org.neo4j.kernel.impl.store.RelationshipGroupStore in project neo4j by neo4j.

the class RecordRelationshipTraversalCursorTest method createRelationshipStructure.

protected long createRelationshipStructure(boolean dense, RelationshipSpec... relationshipSpecs) {
    RelationshipStore relationshipStore = neoStores.getRelationshipStore();
    if (!dense) {
        // a single chain
        for (int i = 0; i < relationshipSpecs.length; i++) {
            long nextRelationshipId = i == relationshipSpecs.length - 1 ? NULL : i + 1;
            relationshipStore.updateRecord(createRelationship(i, nextRelationshipId, relationshipSpecs[i]), CursorContext.NULL);
        }
        return 0;
    } else {
        // split chains on type/direction
        Arrays.sort(relationshipSpecs);
        RelationshipGroupStore relationshipGroupStore = neoStores.getRelationshipGroupStore();
        int currentType = -1;
        long[] currentGroup = null;
        long nextGroupId = relationshipGroupStore.getNumberOfReservedLowIds();
        for (int i = 0; i < relationshipSpecs.length; i++) {
            RelationshipSpec spec = relationshipSpecs[i];
            if (spec.type != currentType || currentGroup == null) {
                if (currentGroup != null) {
                    relationshipGroupStore.updateRecord(createRelationshipGroup(nextGroupId++, currentType, currentGroup, nextGroupId), CursorContext.NULL);
                }
                currentType = spec.type;
                currentGroup = new long[] { NULL, NULL, NULL };
            }
            int relationshipOrdinal = relationshipSpecs[i].direction.ordinal();
            long relationshipId = i;
            long nextRelationshipId = i < relationshipSpecs.length - 1 && relationshipSpecs[i + 1].equals(spec) ? i + 1 : NULL;
            relationshipStore.updateRecord(createRelationship(relationshipId, nextRelationshipId, relationshipSpecs[i]), CursorContext.NULL);
            if (currentGroup[relationshipOrdinal] == NULL) {
                currentGroup[relationshipOrdinal] = relationshipId;
            }
        }
        relationshipGroupStore.updateRecord(createRelationshipGroup(nextGroupId, currentType, currentGroup, NULL), CursorContext.NULL);
        return relationshipsReferenceWithDenseMarker(relationshipGroupStore.getNumberOfReservedLowIds(), true);
    }
}
Also used : RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore)

Aggregations

RelationshipGroupStore (org.neo4j.kernel.impl.store.RelationshipGroupStore)11 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)7 NodeStore (org.neo4j.kernel.impl.store.NodeStore)6 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)5 Test (org.junit.jupiter.api.Test)4 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)3 PageCursor (org.neo4j.io.pagecache.PageCursor)2 DynamicArrayStore (org.neo4j.kernel.impl.store.DynamicArrayStore)2 DynamicStringStore (org.neo4j.kernel.impl.store.DynamicStringStore)2 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)2 LinkedList (java.util.LinkedList)1 MutableLongLongMap (org.eclipse.collections.api.map.primitive.MutableLongLongMap)1 CacheAccess (org.neo4j.consistency.checking.cache.CacheAccess)1 RelationshipGroupDegreesStore (org.neo4j.internal.counts.RelationshipGroupDegreesStore)1 ProgressListener (org.neo4j.internal.helpers.progress.ProgressListener)1 RecordProxy (org.neo4j.internal.recordstorage.RecordAccess.RecordProxy)1 RecordStorageEngine (org.neo4j.internal.recordstorage.RecordStorageEngine)1 RecordStorageReader (org.neo4j.internal.recordstorage.RecordStorageReader)1