Search in sources :

Example 16 with PropertyBlock

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

the class NeoStoresTest method deleteRel1.

private void deleteRel1(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws Exception {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("-string1", data.value());
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(-1, data.value());
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            transaction.relationshipDoRemoveProperty(rel, prop3);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
    propertyLoader.relLoadProperties(rel, propertyCounter);
    assertEquals(3, propertyCounter.count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
    relDelete(rel);
    assertHasRelationships(firstNode);
    assertHasRelationships(secondNode);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 17 with PropertyBlock

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

the class NeoStoresTest method deleteRel2.

private void deleteRel2(long rel, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long firstNode, long secondNode, int relType) throws Exception {
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.relLoadProperties(rel, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = pStore.getRecord(id, pStore.newRecord(), NORMAL);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("-string2", data.value());
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(-2, data.value());
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(true, data.value());
            transaction.relationshipDoRemoveProperty(rel, prop3);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    CountingPropertyReceiver propertyCounter = new CountingPropertyReceiver();
    propertyLoader.relLoadProperties(rel, propertyCounter);
    assertEquals(3, propertyCounter.count);
    assertRelationshipData(rel, firstNode, secondNode, relType);
    relDelete(rel);
    assertHasRelationships(firstNode);
    assertHasRelationships(secondNode);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Pair(org.neo4j.helpers.collection.Pair)

Example 18 with PropertyBlock

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

the class NeoStoresTest method validateNodeRel2.

private void validateNodeRel2(final long node, DefinedProperty prop1, DefinedProperty prop2, DefinedProperty prop3, long rel1, long rel2, final int relType1, final int relType2) throws IOException, RuntimeException {
    assertTrue(nodeExists(node));
    ArrayMap<Integer, Pair<DefinedProperty, Long>> props = new ArrayMap<>();
    propertyLoader.nodeLoadProperties(node, newPropertyReceiver(props));
    int count = 0;
    for (int keyId : props.keySet()) {
        long id = props.get(keyId).other();
        PropertyRecord record = getRecord(pStore, id);
        PropertyBlock block = record.getPropertyBlock(props.get(keyId).first().propertyKeyId());
        DefinedProperty data = block.newPropertyData(pStore);
        if (data.propertyKeyId() == prop1.propertyKeyId()) {
            assertEquals("prop1", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals("string2", data.value());
            nodeAddProperty(node, prop1.propertyKeyId(), "-string2");
        } else if (data.propertyKeyId() == prop2.propertyKeyId()) {
            assertEquals("prop2", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(2, data.value());
            nodeAddProperty(node, prop2.propertyKeyId(), -2);
        } else if (data.propertyKeyId() == prop3.propertyKeyId()) {
            assertEquals("prop3", MyPropertyKeyToken.getIndexFor(keyId).name());
            assertEquals(false, data.value());
            nodeAddProperty(node, prop3.propertyKeyId(), true);
        } else {
            throw new IOException();
        }
        count++;
    }
    assertEquals(3, count);
    count = 0;
    try (KernelStatement statement = (KernelStatement) tx.acquireStatement();
        Cursor<NodeItem> nodeCursor = statement.getStoreStatement().acquireSingleNodeCursor(node)) {
        nodeCursor.next();
        NodeItem nodeItem = nodeCursor.get();
        try (Cursor<RelationshipItem> relationships = statement.getStoreStatement().acquireNodeRelationshipCursor(nodeItem.isDense(), nodeItem.id(), nodeItem.nextRelationshipId(), BOTH, ALWAYS_TRUE_INT)) {
            while (relationships.next()) {
                long rel = relationships.get().id();
                if (rel == rel1) {
                    assertEquals(node, relationships.get().endNode());
                    assertEquals(relType1, relationships.get().type());
                } else if (rel == rel2) {
                    assertEquals(node, relationships.get().startNode());
                    assertEquals(relType2, relationships.get().type());
                } else {
                    throw new IOException();
                }
                count++;
            }
        }
    }
    assertEquals(2, count);
}
Also used : DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem) Pair(org.neo4j.helpers.collection.Pair)

Example 19 with PropertyBlock

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

the class OwnerCheck method decoratePropertyChecker.

@Override
public RecordCheck<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> decoratePropertyChecker(final RecordCheck<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> checker) {
    if (owners == null && dynamics == null) {
        return checker;
    }
    return new RecordCheck<PropertyRecord, ConsistencyReport.PropertyConsistencyReport>() {

        @Override
        public void check(PropertyRecord record, CheckerEngine<PropertyRecord, ConsistencyReport.PropertyConsistencyReport> engine, RecordAccess records) {
            if (record.inUse()) {
                if (owners != null && Record.NO_PREVIOUS_PROPERTY.is(record.getPrevProp())) {
                    // this record is first in a chain
                    PropertyOwner.UnknownOwner owner = new PropertyOwner.UnknownOwner();
                    engine.comparativeCheck(owner, ORPHAN_CHECKER);
                    if (null == owners.putIfAbsent(record.getId(), owner)) {
                        owner.markInCustody();
                    }
                }
                if (dynamics != null) {
                    for (PropertyBlock block : record) {
                        RecordType type = recordType(block.forceGetType());
                        if (type != null) {
                            ConcurrentMap<Long, DynamicOwner> dynamicOwners = dynamics.get(type);
                            if (dynamicOwners != null) {
                                long id = block.getSingleValueLong();
                                DynamicOwner.Property owner = new DynamicOwner.Property(type, record);
                                DynamicOwner prev = dynamicOwners.put(id, owner);
                                if (prev != null) {
                                    engine.comparativeCheck(prev.record(records), owner);
                                }
                            }
                        }
                    }
                }
            }
            checker.check(record, engine, records);
        }
    };
}
Also used : RecordAccess(org.neo4j.consistency.store.RecordAccess) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) RelationshipGroupConsistencyReport(org.neo4j.consistency.report.ConsistencyReport.RelationshipGroupConsistencyReport) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) RecordType(org.neo4j.consistency.RecordType) OwningRecordCheck(org.neo4j.consistency.checking.OwningRecordCheck) RecordCheck(org.neo4j.consistency.checking.RecordCheck) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) CheckerEngine(org.neo4j.consistency.checking.CheckerEngine)

Example 20 with PropertyBlock

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

the class PropertyAndNodeIndexedCheck method checkIndexToLabels.

private void checkIndexToLabels(NodeRecord record, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, RecordAccess records, Collection<PropertyRecord> propertyRecs) {
    Set<Long> labels = NodeLabelReader.getListOfLabels(record, records, engine);
    List<PropertyBlock> properties = null;
    for (IndexRule indexRule : indexes.rules()) {
        long labelId = indexRule.schema().getLabelId();
        if (!labels.contains(labelId)) {
            continue;
        }
        if (properties == null) {
            properties = propertyReader.propertyBlocks(propertyRecs);
        }
        // assuming 1 property always
        int propertyId = indexRule.schema().getPropertyId();
        PropertyBlock property = propertyWithKey(properties, propertyId);
        if (property == null) {
            continue;
        }
        try (IndexReader reader = indexes.accessorFor(indexRule).newReader()) {
            Object propertyValue = propertyReader.propertyValue(property).value();
            long nodeId = record.getId();
            if (indexRule.canSupportUniqueConstraint()) {
                verifyNodeCorrectlyIndexedUniquely(nodeId, property.getKeyIndexId(), propertyValue, engine, indexRule, reader);
            } else {
                verifyNodeCorrectlyIndexed(nodeId, propertyValue, engine, indexRule, reader);
            }
        }
    }
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Aggregations

PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)139 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)86 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)25 Test (org.junit.jupiter.api.Test)16 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)14 Value (org.neo4j.values.storable.Value)13 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)10 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)8 Pair (org.neo4j.helpers.collection.Pair)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)8 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)8 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)7 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)7 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)7 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)7