Search in sources :

Example 51 with RelationshipRecord

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

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

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

the class RelationshipGroupStoreTest method assertRelationshipChain.

private static void assertRelationshipChain(RelationshipStore relationshipStore, Node node, long firstId, long... chainedIds) {
    long nodeId = node.getId();
    RelationshipRecord record = relationshipStore.getRecord(firstId, relationshipStore.newRecord(), NORMAL, CursorContext.NULL);
    Set<Long> readChain = new HashSet<>();
    readChain.add(firstId);
    while (true) {
        long nextId = record.getFirstNode() == nodeId ? record.getFirstNextRel() : record.getSecondNextRel();
        if (nextId == -1) {
            break;
        }
        readChain.add(nextId);
        relationshipStore.getRecord(nextId, record, NORMAL, CursorContext.NULL);
    }
    Set<Long> expectedChain = new HashSet<>(Collections.singletonList(firstId));
    for (long id : chainedIds) {
        expectedChain.add(id);
    }
    assertEquals(expectedChain, readChain);
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) HashSet(java.util.HashSet)

Example 54 with RelationshipRecord

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

the class PropertyDeleter method logInconsistentPropertyChain.

private void logInconsistentPropertyChain(PrimitiveRecord primitive, String causeMessage, Throwable cause) {
    if (!config.get(GraphDatabaseInternalSettings.log_inconsistent_data_deletion)) {
        return;
    }
    StringBuilder message = new StringBuilder(format("Deleted inconsistent property chain with %s for %s", causeMessage, primitive));
    try (RecordPropertyCursor propertyCursor = new RecordPropertyCursor(neoStores.getPropertyStore(), cursorContext, memoryTracker)) {
        if (primitive instanceof NodeRecord) {
            NodeRecord node = (NodeRecord) primitive;
            message.append(" with labels: ");
            long[] labelIds = NodeLabelsField.parseLabelsField(node).get(neoStores.getNodeStore(), cursorContext);
            message.append(LongStream.of(labelIds).mapToObj(labelId -> tokenNameLookup.labelGetName(toIntExact(labelId))).collect(Collectors.toList()));
            propertyCursor.initNodeProperties(node.getNextProp(), node.getId());
        } else if (primitive instanceof RelationshipRecord) {
            RelationshipRecord relationship = (RelationshipRecord) primitive;
            message.append(format(" with relationship type: %s", tokenNameLookup.relationshipTypeGetName(relationship.getType())));
            propertyCursor.initRelationshipProperties(relationship.getNextProp(), relationship.getId());
        }
        // Use the cursor to read property values, because it's more flexible in reading data
        MutableIntSet seenKeyIds = IntSets.mutable.empty();
        while (propertyCursor.next()) {
            int keyId = propertyCursor.propertyKey();
            if (!seenKeyIds.add(keyId)) {
                continue;
            }
            String key = tokenNameLookup.propertyKeyGetName(keyId);
            Value value;
            try {
                value = propertyCursor.propertyValue();
            } catch (Exception e) {
                value = null;
            }
            String valueToString = value != null ? value.toString() : "<value could not be read>";
            message.append(format("%n  %s = %s", key, valueToString));
        }
    } catch (InconsistentDataReadException e) {
    // Expected to occur on chain cycles, that's what we're here for
    }
    logProvider.getLog(InconsistentDataDeletion.class).error(message.toString(), cause);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) Value(org.neo4j.values.storable.Value) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 55 with RelationshipRecord

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

the class LogCommandSerializationV4_0 method readRelationshipRecord.

private static RelationshipRecord readRelationshipRecord(long id, ReadableChannel channel) throws IOException {
    byte flags = channel.get();
    boolean inUse = bitFlag(flags, Record.IN_USE.byteValue());
    boolean requiresSecondaryUnit = bitFlag(flags, Record.REQUIRE_SECONDARY_UNIT);
    boolean hasSecondaryUnit = bitFlag(flags, Record.HAS_SECONDARY_UNIT);
    boolean usesFixedReferenceFormat = bitFlag(flags, Record.USES_FIXED_REFERENCE_FORMAT);
    RelationshipRecord record;
    if (inUse) {
        record = new RelationshipRecord(id);
        record.setLinks(channel.getLong(), channel.getLong(), channel.getInt());
        record.setInUse(true);
        record.setRequiresSecondaryUnit(requiresSecondaryUnit);
        record.setFirstPrevRel(channel.getLong());
        record.setFirstNextRel(channel.getLong());
        record.setSecondPrevRel(channel.getLong());
        record.setSecondNextRel(channel.getLong());
        record.setNextProp(channel.getLong());
        byte extraByte = channel.get();
        record.setFirstInFirstChain((extraByte & 0x1) > 0);
        record.setFirstInSecondChain((extraByte & 0x2) > 0);
        if (hasSecondaryUnit) {
            record.setSecondaryUnitIdOnLoad(channel.getLong());
        }
        record.setUseFixedReferences(usesFixedReferenceFormat);
    } else {
        record = new RelationshipRecord(id);
        record.setLinks(-1, -1, channel.getInt());
        record.setInUse(false);
    }
    if (bitFlag(flags, Record.CREATED_IN_TX)) {
        record.setCreated();
    }
    return record;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Aggregations

RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)207 Test (org.junit.Test)73 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)69 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)43 Test (org.junit.jupiter.api.Test)34 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)30 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)19 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)14 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)12 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)12 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)12 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)11 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)9 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6