Search in sources :

Example 41 with NodeStore

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

the class TransactionRecordStateTest method assertRelationshipGroupsInOrder.

private static void assertRelationshipGroupsInOrder(NeoStores neoStores, long nodeId, int... types) {
    NodeStore nodeStore = neoStores.getNodeStore();
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), NORMAL, NULL);
    assertTrue(node.isDense(), "Node should be dense, is " + node);
    long groupId = node.getNextRel();
    int cursor = 0;
    List<RelationshipGroupRecord> seen = new ArrayList<>();
    while (groupId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        RecordStore<RelationshipGroupRecord> relationshipGroupStore = neoStores.getRelationshipGroupStore();
        RelationshipGroupRecord group = relationshipGroupStore.getRecord(groupId, relationshipGroupStore.newRecord(), NORMAL, NULL);
        seen.add(group);
        assertEquals(types[cursor++], group.getType(), "Invalid type, seen groups so far " + seen);
        groupId = group.getNext();
    }
    assertEquals(types.length, cursor, "Not enough relationship group records found in chain for " + node);
}
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) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)

Example 42 with NodeStore

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

the class TransactionRecordStateTest method shouldDeleteEmptyGroupsWhenDeletingNodeAndLastRelationship.

@Test
void shouldDeleteEmptyGroupsWhenDeletingNodeAndLastRelationship() throws Exception {
    // given
    // node --> group A (empty) --> group B (not empty) --> group C (empty)
    // |
    // v
    // relationship
    neoStores = createStores();
    NodeStore nodeStore = neoStores.getNodeStore();
    RelationshipGroupStore groupStore = neoStores.getRelationshipGroupStore();
    RelationshipStore relationshipStore = neoStores.getRelationshipStore();
    long nodeId = nodeStore.nextId(NULL);
    long relationshipId = relationshipStore.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(), relationshipId, 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);
    relationshipStore.updateRecord(new RelationshipRecord(relationshipId).initialize(true, NO_NEXT_PROPERTY.longValue(), nodeId, nodeId, 1, 1, NULL_REFERENCE.longValue(), 1, NULL_REFERENCE.longValue(), true, true), 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.relModify(singleDelete(relationship(relationshipId, 1, nodeId, nodeId)));
    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();
    assertThat(relationshipStore.isInUse(relationshipId, 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) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) Test(org.junit.jupiter.api.Test)

Aggregations

NodeStore (org.neo4j.kernel.impl.store.NodeStore)42 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)28 NeoStores (org.neo4j.kernel.impl.store.NeoStores)12 Test (org.junit.jupiter.api.Test)10 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)10 Test (org.junit.Test)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 ArrayList (java.util.ArrayList)7 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)6 RelationshipGroupStore (org.neo4j.kernel.impl.store.RelationshipGroupStore)6 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)6 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 CountsComputer (org.neo4j.kernel.impl.store.CountsComputer)4 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)4 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)4 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)4 Value (org.neo4j.values.storable.Value)4 BatchingNeoStores (org.neo4j.internal.batchimport.store.BatchingNeoStores)3