Search in sources :

Example 61 with PropertyRecord

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

the class PropertyDeleter method deletePropertyChain.

public void deletePropertyChain(PrimitiveRecord primitive, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords) {
    long nextProp = primitive.getNextProp();
    MutableLongSet seenPropertyIds = null;
    int count = 0;
    try {
        while (nextProp != Record.NO_NEXT_PROPERTY.longValue()) {
            RecordProxy<PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad(nextProp, primitive, cursorContext);
            PropertyRecord propRecord = propertyChange.forChangingData();
            deletePropertyRecordIncludingValueRecords(propRecord);
            if (++count >= CYCLE_DETECTION_THRESHOLD) {
                if (seenPropertyIds == null) {
                    seenPropertyIds = LongSets.mutable.empty();
                }
                if (!seenPropertyIds.add(nextProp)) {
                    throw new InconsistentDataReadException("Cycle detected in property chain for %s", primitive);
                }
            }
            nextProp = propRecord.getNextProp();
            propRecord.setChanged(primitive);
        }
    } catch (InvalidRecordException e) {
        // This property chain, or a dynamic value record chain contains a record which is not in use, so it's somewhat broken.
        // Abort reading the chain, but don't fail the deletion of this property record chain.
        logInconsistentPropertyChain(primitive, "unused record", e);
    } catch (InconsistentDataReadException e) {
        // This property chain, or a dynamic value record chain contains a cycle.
        // Abort reading the chain, but don't fail the deletion of this property record chain.
        logInconsistentPropertyChain(primitive, "cycle", e);
    }
    primitive.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord)

Example 62 with PropertyRecord

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

the class Loaders method propertyLoader.

public static RecordLoader<PropertyRecord, PrimitiveRecord> propertyLoader(final PropertyStore store, CursorContext cursorContext) {
    return new RecordLoader<>(store, cursorContext) {

        @Override
        public PropertyRecord newUnused(long key, PrimitiveRecord additionalData) {
            PropertyRecord record = new PropertyRecord(key);
            setOwner(record, additionalData);
            return andMarkAsCreated(record);
        }

        private void setOwner(PropertyRecord record, PrimitiveRecord owner) {
            if (owner != null) {
                owner.setIdTo(record);
            }
        }

        @Override
        public PropertyRecord load(long key, PrimitiveRecord additionalData, RecordLoad load, CursorContext cursorContext) {
            PropertyRecord record = super.load(key, additionalData, load, cursorContext);
            setOwner(record, additionalData);
            return record;
        }

        @Override
        public PropertyRecord copy(PropertyRecord propertyRecord) {
            return new PropertyRecord(propertyRecord);
        }
    };
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) CursorContext(org.neo4j.io.pagecache.context.CursorContext) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord)

Example 63 with PropertyRecord

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

the class LogCommandSerializationV3_0_10 method readPropertyRecord.

private PropertyRecord readPropertyRecord(long id, ReadableChannel channel) throws IOException {
    // in_use(byte)+type(int)+key_indexId(int)+prop_blockId(long)+
    // prev_prop_id(long)+next_prop_id(long)
    PropertyRecord record = new PropertyRecord(id);
    // 1
    byte flags = channel.get();
    boolean inUse = bitFlag(flags, Record.IN_USE.byteValue());
    boolean nodeProperty = !bitFlag(flags, Record.REL_PROPERTY.byteValue());
    boolean requireSecondaryUnit = bitFlag(flags, Record.REQUIRE_SECONDARY_UNIT);
    boolean hasSecondaryUnit = bitFlag(flags, Record.HAS_SECONDARY_UNIT);
    boolean usesFixedReferenceFormat = bitFlag(flags, Record.USES_FIXED_REFERENCE_FORMAT);
    record.setRequiresSecondaryUnit(requireSecondaryUnit);
    record.setUseFixedReferences(usesFixedReferenceFormat);
    // 8
    long nextProp = channel.getLong();
    // 8
    long prevProp = channel.getLong();
    record.setNextProp(nextProp);
    record.setPrevProp(prevProp);
    // 8
    long primitiveId = channel.getLong();
    if (primitiveId != -1 && nodeProperty) {
        record.setNodeId(primitiveId);
    } else if (primitiveId != -1) {
        record.setRelId(primitiveId);
    }
    if (hasSecondaryUnit) {
        record.setSecondaryUnitIdOnLoad(channel.getLong());
    }
    int nrPropBlocks = channel.get();
    assert nrPropBlocks >= 0;
    if (nrPropBlocks > 0) {
        record.setInUse(true);
    }
    while (nrPropBlocks-- > 0) {
        PropertyBlock block = readPropertyBlock(channel);
        if (block == null) {
            return null;
        }
        record.addPropertyBlock(block);
    }
    int deletedRecords = readDynamicRecords(channel, record, PROPERTY_DELETED_DYNAMIC_RECORD_ADDER);
    if (deletedRecords == -1) {
        return null;
    }
    assert deletedRecords >= 0;
    while (deletedRecords-- > 0) {
        DynamicRecord read = readDynamicRecord(channel);
        if (read == null) {
            return null;
        }
        record.addDeletedRecord(read);
    }
    if ((inUse && !record.inUse()) || (!inUse && record.inUse())) {
        throw new IllegalStateException("Weird, inUse was read in as " + inUse + " but the record is " + record);
    }
    return record;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 64 with PropertyRecord

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

the class LockVerificationMonitor method verifyPropertySufficientlyLocked.

private void verifyPropertySufficientlyLocked(PropertyRecord before) {
    assertRecordsEquals(before, id -> {
        // This loads without inferred data, so just move it over so we can do equality check
        PropertyRecord stored = loader.loadProperty(id);
        stored.setEntity(before);
        return stored;
    });
    if (before.isNodeSet()) {
        if (!txState.nodeIsAddedInThisTx(before.getNodeId())) {
            assertLocked(before.getNodeId(), NODE, before);
        }
    } else if (before.isRelSet()) {
        if (!txState.relationshipIsAddedInThisTx(before.getRelId())) {
            assertLocked(before.getRelId(), RELATIONSHIP, before);
        }
    } else if (before.isSchemaSet()) {
        assertSchemaLocked(locks, loader.loadSchema(before.getSchemaRuleId()), before);
    }
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord)

Example 65 with PropertyRecord

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

the class PropertyTraverser method findPropertyRecordContaining.

/**
 * Traverses a property record chain and finds the record containing the property with key {@code propertyKey}.
 * If none is found and {@code strict} is {@code true} then {@link IllegalStateException} is thrown,
 * otherwise id value of {@link Record#NO_NEXT_PROPERTY} is returned.
 *
 * @param primitive {@link PrimitiveRecord} which is the owner of the chain.
 * @param propertyKey property key token id to look for.
 * @param propertyRecords access to records.
 * @param strict dictates behavior on property key not found. If {@code true} then {@link IllegalStateException}
 * is thrown, otherwise value of {@link Record#NO_NEXT_PROPERTY} is returned.
 * @return property record id containing property with the given {@code propertyKey}, otherwise if
 * {@code strict} is false value of {@link Record#NO_NEXT_PROPERTY}.
 */
public long findPropertyRecordContaining(PrimitiveRecord primitive, int propertyKey, RecordAccess<PropertyRecord, PrimitiveRecord> propertyRecords, boolean strict) {
    long propertyRecordId = primitive.getNextProp();
    while (!Record.NO_NEXT_PROPERTY.is(propertyRecordId)) {
        PropertyRecord propertyRecord = propertyRecords.getOrLoad(propertyRecordId, primitive, cursorContext).forReadingLinkage();
        if (propertyRecord.getPropertyBlock(propertyKey) != null) {
            return propertyRecordId;
        }
        propertyRecordId = propertyRecord.getNextProp();
    }
    if (strict) {
        throw new IllegalStateException("No property record in property chain for " + primitive + " contained property with key " + propertyKey);
    }
    return Record.NO_NEXT_PROPERTY.intValue();
}
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