Search in sources :

Example 6 with PropertyBlock

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

the class PhysicalLogCommandReaderV3_0_2 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);
    record.setRequiresSecondaryUnit(requireSecondaryUnit);
    // 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.setSecondaryUnitId(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 7 with PropertyBlock

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

the class PropertyCreator method createPropertyChain.

public long createPropertyChain(PrimitiveRecord owner, Iterator<PropertyBlock> properties, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
    if (properties == null || !properties.hasNext()) {
        return Record.NO_NEXT_PROPERTY.intValue();
    }
    PropertyRecord currentRecord = propertyRecords.create(propertyRecordIdGenerator.nextId(), owner).forChangingData();
    currentRecord.setInUse(true);
    currentRecord.setCreated();
    PropertyRecord firstRecord = currentRecord;
    while (properties.hasNext()) {
        PropertyBlock block = properties.next();
        if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
            // Here it means the current block is done for
            PropertyRecord prevRecord = currentRecord;
            // Create new record
            long propertyId = propertyRecordIdGenerator.nextId();
            currentRecord = propertyRecords.create(propertyId, owner).forChangingData();
            currentRecord.setInUse(true);
            currentRecord.setCreated();
            // Set up links
            prevRecord.setNextProp(propertyId);
            currentRecord.setPrevProp(prevRecord.getId());
        // Now current is ready to start picking up blocks
        }
        currentRecord.addPropertyBlock(block);
    }
    return firstRecord.getId();
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

Example 8 with PropertyBlock

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

the class PropertyDeleter method removeProperty.

public <P extends PrimitiveRecord> void removeProperty(RecordProxy<Long, P, Void> primitiveProxy, int propertyKey, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
    PrimitiveRecord primitive = primitiveProxy.forReadingData();
    // propertyData.getId();
    long propertyId = traverser.findPropertyRecordContaining(primitive, propertyKey, propertyRecords, true);
    RecordProxy<Long, PropertyRecord, PrimitiveRecord> recordChange = propertyRecords.getOrLoad(propertyId, primitive);
    PropertyRecord propRecord = recordChange.forChangingData();
    if (!propRecord.inUse()) {
        throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
    }
    PropertyBlock block = propRecord.removePropertyBlock(propertyKey);
    if (block == null) {
        throw new IllegalStateException("Property with index[" + propertyKey + "] is not present in property[" + propertyId + "]");
    }
    for (DynamicRecord valueRecord : block.getValueRecords()) {
        assert valueRecord.inUse();
        valueRecord.setInUse(false, block.getType().intValue());
        propRecord.addDeletedRecord(valueRecord);
    }
    if (propRecord.size() > 0) {
        /*
             * There are remaining blocks in the record. We do not unlink yet.
             */
        propRecord.setChanged(primitive);
        assert traverser.assertPropertyChain(primitive, propertyRecords);
    } else {
        unlinkPropertyRecord(propRecord, propertyRecords, primitiveProxy);
    }
}
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) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord)

Example 9 with PropertyBlock

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

the class PropertyDeleter method deletePropertyChain.

public void deletePropertyChain(PrimitiveRecord primitive, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords) {
    long nextProp = primitive.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        RecordProxy<Long, PropertyRecord, PrimitiveRecord> propertyChange = propertyRecords.getOrLoad(nextProp, primitive);
        // TODO forChanging/forReading piggy-backing
        PropertyRecord propRecord = propertyChange.forChangingData();
        for (PropertyBlock block : propRecord) {
            for (DynamicRecord valueRecord : block.getValueRecords()) {
                assert valueRecord.inUse();
                valueRecord.setInUse(false);
                propRecord.addDeletedRecord(valueRecord);
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        propRecord.setChanged(primitive);
        // We do not remove them individually, but all together here
        propRecord.clearPropertyBlocks();
    }
    primitive.setNextProp(Record.NO_NEXT_PROPERTY.intValue());
}
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) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord)

Example 10 with PropertyBlock

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

the class PropertyTraverser method getPropertyChain.

public void getPropertyChain(long nextProp, RecordAccess<Long, PropertyRecord, PrimitiveRecord> propertyRecords, Listener<PropertyBlock> collector) {
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = propertyRecords.getOrLoad(nextProp, null).forReadingData();
        for (PropertyBlock propBlock : propRecord) {
            collector.receive(propBlock);
        }
        nextProp = propRecord.getNextProp();
    }
}
Also used : PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock)

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