Search in sources :

Example 6 with RelationshipGroupRecord

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

the class StorageLayerRelTypesAndDegreeTest method markRelGroupNotInUse.

private void markRelGroupNotInUse(long nodeId, TestRelType... types) {
    NodeRecord node = getNodeRecord(nodeId);
    assertTrue(node.isDense());
    Set<TestRelType> typesToRemove = asSet(types);
    long relGroupId = node.getNextRel();
    while (relGroupId != NO_NEXT_RELATIONSHIP.intValue()) {
        RelationshipGroupRecord relGroup = getRelGroupRecord(relGroupId);
        TestRelType type = relTypeForId(relGroup.getType());
        if (typesToRemove.contains(type)) {
            relGroup.setInUse(false);
            update(relGroup);
        }
        relGroupId = relGroup.getNext();
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

Example 7 with RelationshipGroupRecord

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

the class TransactionRecordStateTest method assertDenseRelationshipCounts.

public static void assertDenseRelationshipCounts(RecordChangeSet recordChangeSet, long nodeId, int type, int outCount, int inCount) {
    RelationshipGroupRecord group = getRelationshipGroup(recordChangeSet, recordChangeSet.getNodeRecords().getOrLoad(nodeId, null).forReadingData(), type).forReadingData();
    assertNotNull(group);
    RelationshipRecord rel;
    long relId = group.getFirstOut();
    if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        rel = recordChangeSet.getRelRecords().getOrLoad(relId, null).forReadingData();
        // count is stored in the back pointer of the first relationship in the chain
        assertEquals("Stored relationship count for OUTGOING differs", outCount, rel.getFirstPrevRel());
        assertEquals("Manually counted relationships for OUTGOING differs", outCount, manuallyCountRelationships(recordChangeSet, nodeId, relId));
    }
    relId = group.getFirstIn();
    if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        rel = recordChangeSet.getRelRecords().getOrLoad(relId, null).forReadingData();
        assertEquals("Stored relationship count for INCOMING differs", inCount, rel.getSecondPrevRel());
        assertEquals("Manually counted relationships for INCOMING differs", inCount, manuallyCountRelationships(recordChangeSet, nodeId, relId));
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 8 with RelationshipGroupRecord

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

the class WriteTransactionCommandOrderingTest method injectAllPossibleCommands.

private TransactionRecordState injectAllPossibleCommands() {
    RecordChangeSet recordChangeSet = mock(RecordChangeSet.class);
    RecordChanges<Integer, LabelTokenRecord, Void> labelTokenChanges = mock(RecordChanges.class);
    RecordChanges<Integer, RelationshipTypeTokenRecord, Void> relationshipTypeTokenChanges = mock(RecordChanges.class);
    RecordChanges<Integer, PropertyKeyTokenRecord, Void> propertyKeyTokenChanges = mock(RecordChanges.class);
    RecordChanges<Long, NodeRecord, Void> nodeRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, RelationshipRecord, Void> relationshipRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, PropertyRecord, PrimitiveRecord> propertyRecordChanges = mock(RecordChanges.class);
    RecordChanges<Long, RelationshipGroupRecord, Integer> relationshipGroupChanges = mock(RecordChanges.class);
    RecordChanges<Long, SchemaRecord, SchemaRule> schemaRuleChanges = mock(RecordChanges.class);
    when(recordChangeSet.getLabelTokenChanges()).thenReturn(labelTokenChanges);
    when(recordChangeSet.getRelationshipTypeTokenChanges()).thenReturn(relationshipTypeTokenChanges);
    when(recordChangeSet.getPropertyKeyTokenChanges()).thenReturn(propertyKeyTokenChanges);
    when(recordChangeSet.getNodeRecords()).thenReturn(nodeRecordChanges);
    when(recordChangeSet.getRelRecords()).thenReturn(relationshipRecordChanges);
    when(recordChangeSet.getPropertyRecords()).thenReturn(propertyRecordChanges);
    when(recordChangeSet.getRelGroupRecords()).thenReturn(relationshipGroupChanges);
    when(recordChangeSet.getSchemaRuleChanges()).thenReturn(schemaRuleChanges);
    List<RecordProxy<Long, NodeRecord, Void>> nodeChanges = new LinkedList<>();
    RecordChange<Long, NodeRecord, Void> deletedNode = mock(RecordChange.class);
    when(deletedNode.getBefore()).thenReturn(inUseNode());
    when(deletedNode.forReadingLinkage()).thenReturn(missingNode());
    nodeChanges.add(deletedNode);
    RecordChange<Long, NodeRecord, Void> createdNode = mock(RecordChange.class);
    when(createdNode.getBefore()).thenReturn(missingNode());
    when(createdNode.forReadingLinkage()).thenReturn(createdNode());
    nodeChanges.add(createdNode);
    RecordChange<Long, NodeRecord, Void> updatedNode = mock(RecordChange.class);
    when(updatedNode.getBefore()).thenReturn(inUseNode());
    when(updatedNode.forReadingLinkage()).thenReturn(inUseNode());
    nodeChanges.add(updatedNode);
    when(nodeRecordChanges.changes()).thenReturn(nodeChanges);
    when(nodeRecordChanges.changeSize()).thenReturn(3);
    when(recordChangeSet.changeSize()).thenReturn(3);
    when(labelTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, LabelTokenRecord, Void>>emptyList());
    when(relationshipTypeTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, RelationshipTypeTokenRecord, Void>>emptyList());
    when(propertyKeyTokenChanges.changes()).thenReturn(Collections.<RecordProxy<Integer, PropertyKeyTokenRecord, Void>>emptyList());
    when(relationshipRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipRecord, Void>>emptyList());
    when(propertyRecordChanges.changes()).thenReturn(Collections.<RecordProxy<Long, PropertyRecord, PrimitiveRecord>>emptyList());
    when(relationshipGroupChanges.changes()).thenReturn(Collections.<RecordProxy<Long, RelationshipGroupRecord, Integer>>emptyList());
    when(schemaRuleChanges.changes()).thenReturn(Collections.<RecordProxy<Long, SchemaRecord, SchemaRule>>emptyList());
    NeoStores neoStores = mock(NeoStores.class);
    when(neoStores.getNodeStore()).thenReturn(mock(NodeStore.class));
    when(neoStores.getRelationshipGroupStore()).thenReturn(mock(RelationshipGroupStore.class));
    when(neoStores.getRelationshipStore()).thenReturn(mock(RelationshipStore.class));
    return new TransactionRecordState(neoStores, mock(IntegrityValidator.class), recordChangeSet, 0, null, null, null, null, null);
}
Also used : RelationshipTypeTokenRecord(org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeStore(org.neo4j.kernel.impl.store.NodeStore) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) RecordProxy(org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) RelationshipGroupStore(org.neo4j.kernel.impl.store.RelationshipGroupStore) LinkedList(java.util.LinkedList) NeoStores(org.neo4j.kernel.impl.store.NeoStores) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore)

Example 9 with RelationshipGroupRecord

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

the class RelationshipGroupGetterTest method shouldAbortLoadingGroupChainIfComeTooFar.

@Test
public void shouldAbortLoadingGroupChainIfComeTooFar() throws Exception {
    // GIVEN a node with relationship group chain 2-->4-->10-->23
    File dir = new File("dir");
    fs.get().mkdirs(dir);
    LogProvider logProvider = NullLogProvider.getInstance();
    StoreFactory storeFactory = new StoreFactory(dir, pageCache.getPageCache(fs.get()), fs.get(), logProvider);
    try (NeoStores stores = storeFactory.openNeoStores(true, StoreType.RELATIONSHIP_GROUP)) {
        RecordStore<RelationshipGroupRecord> store = spy(stores.getRelationshipGroupStore());
        RelationshipGroupRecord group_2 = group(0, 2);
        RelationshipGroupRecord group_4 = group(1, 4);
        RelationshipGroupRecord group_10 = group(2, 10);
        RelationshipGroupRecord group_23 = group(3, 23);
        link(group_2, group_4, group_10, group_23);
        store.updateRecord(group_2);
        store.updateRecord(group_4);
        store.updateRecord(group_10);
        store.updateRecord(group_23);
        RelationshipGroupGetter groupGetter = new RelationshipGroupGetter(store);
        NodeRecord node = new NodeRecord(0, true, group_2.getId(), -1);
        // WHEN trying to find relationship group 7
        RecordAccess<Long, RelationshipGroupRecord, Integer> access = new DirectRecordAccess<>(store, Loaders.relationshipGroupLoader(store));
        RelationshipGroupPosition result = groupGetter.getRelationshipGroup(node, 7, access);
        // THEN only groups 2, 4 and 10 should have been loaded
        InOrder verification = inOrder(store);
        verification.verify(store).getRecord(eq(group_2.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_4.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store).getRecord(eq(group_10.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        verification.verify(store, times(0)).getRecord(eq(group_23.getId()), any(RelationshipGroupRecord.class), any(RecordLoad.class));
        // it should also be reported as not found
        assertNull(result.group());
        // with group 4 as closes previous one
        assertEquals(group_4, result.closestPrevious().forReadingData());
    }
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) InOrder(org.mockito.InOrder) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) DirectRecordAccess(org.neo4j.unsafe.batchinsert.DirectRecordAccess) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File) RelationshipGroupPosition(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter.RelationshipGroupPosition) Test(org.junit.Test)

Example 10 with RelationshipGroupRecord

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

the class RelationshipGroupGetterTest method group.

private RelationshipGroupRecord group(long id, int type) {
    RelationshipGroupRecord group = new RelationshipGroupRecord(id, type);
    group.setInUse(true);
    return group;
}
Also used : RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)

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