Search in sources :

Example 36 with PropertyRecord

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

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

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

the class PropertyAndNode2LabelIndexProcessor method process.

@Override
public void process(NodeRecord nodeRecord) {
    reporter.forNode(nodeRecord, nodeIndexCheck);
    CacheAccess.Client client = cacheAccess.client();
    try (MandatoryProperties.Check<NodeRecord, ConsistencyReport.NodeConsistencyReport> mandatoryCheck = mandatoryProperties.apply(nodeRecord)) {
        Iterable<PropertyRecord> properties = client.getPropertiesFromCache();
        // go by unnoticed.
        if (properties != null) {
            for (PropertyRecord property : properties) {
                reporter.forProperty(property, propertyCheck);
                mandatoryCheck.receive(ChainCheck.keys(property));
            }
        }
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) CacheAccess(org.neo4j.consistency.checking.cache.CacheAccess) NodeConsistencyReport(org.neo4j.consistency.report.ConsistencyReport.NodeConsistencyReport)

Example 39 with PropertyRecord

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

the class PropertyReader method getPropertyRecordChain.

public Collection<PropertyRecord> getPropertyRecordChain(long firstId) {
    long nextProp = firstId;
    List<PropertyRecord> toReturn = new LinkedList<>();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propertyStore.getRecord(nextProp, propertyStore.newRecord(), FORCE);
        toReturn.add(propRecord);
        nextProp = propRecord.getNextProp();
    }
    return toReturn;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) LinkedList(java.util.LinkedList)

Example 40 with PropertyRecord

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

the class StorePropertyCursor method next.

@Override
public boolean next() {
    // Are there more properties to return for this current record we're at?
    if (payload.next()) {
        return true;
    }
    // No, OK continue down the chain and hunt for more...
    while (true) {
        if (recordCursor.next()) {
            // All good, we can get values off of this record
            PropertyRecord propertyRecord = recordCursor.get();
            payload.init(propertyRecord.getBlocks(), propertyRecord.getNumberOfBlocks());
            if (payload.next()) {
                return true;
            }
        } else if (Record.NO_NEXT_PROPERTY.is(recordCursor.get().getNextProp())) {
            // No more records in this chain, i.e. no more properties.
            return false;
        }
    // Sort of alright, this record isn't in use, but could just be due to concurrent delete.
    // Continue to next record in the chain and try there.
    }
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord)

Aggregations

PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)230 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)86 Test (org.junit.Test)75 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)37 Test (org.junit.jupiter.api.Test)36 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)35 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)28 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)19 ArrayList (java.util.ArrayList)17 Value (org.neo4j.values.storable.Value)17 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)14 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)14 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)9 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 NodeStore (org.neo4j.kernel.impl.store.NodeStore)8