Search in sources :

Example 6 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project graphdb by neo4j-attic.

the class WriteTransaction method relDelete.

ArrayMap<Integer, PropertyData> relDelete(long id) {
    RelationshipRecord record = getRelationshipRecord(id);
    if (record == null) {
        record = getRelationshipStore().getRecord(id);
        addRelationshipRecord(record);
    }
    if (!record.inUse()) {
        throw new IllegalStateException("Unable to delete relationship[" + id + "] since it is already deleted.");
    }
    ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
    long nextProp = record.getNextProp();
    while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord propRecord = getPropertyRecord(nextProp);
        if (propRecord == null) {
            propRecord = getPropertyStore().getRecord(nextProp);
            addPropertyRecord(propRecord);
        }
        if (propRecord.isLight()) {
            getPropertyStore().makeHeavy(propRecord);
        }
        if (!propRecord.isCreated()) {
            if (!propRecord.isChanged()) {
                propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
            } else {
                // we have to re-read committed value since property has 
                // changed and old value is erased in memory
                PropertyRecord diskValue = getPropertyStore().getRecord(propRecord.getId());
                getPropertyStore().makeHeavy(diskValue);
                propertyMap.put(diskValue.getKeyIndexId(), new PropertyData(diskValue.getId(), propertyGetValueOrNull(diskValue)));
            }
        }
        nextProp = propRecord.getNextProp();
        propRecord.setInUse(false);
        // TODO: update count on property index record
        for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
            valueRecord.setInUse(false);
        }
    }
    disconnectRelationship(record);
    updateNodes(record);
    record.setInUse(false);
    return propertyMap;
}
Also used : DynamicRecord(org.neo4j.kernel.impl.nioneo.store.DynamicRecord) PropertyData(org.neo4j.kernel.impl.nioneo.store.PropertyData) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) ArrayMap(org.neo4j.kernel.impl.util.ArrayMap)

Example 7 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method addPropertyBlockToPrimitive.

private PropertyRecord addPropertyBlockToPrimitive(PropertyBlock block, PrimitiveRecord primitive, boolean isNode) {
    assert assertPropertyChain(primitive);
    int newBlockSizeInBytes = block.getSize();
    /*
         * Here we could either iterate over the whole chain or just go for the first record
         * which is the most likely to be the less full one. Currently we opt for the second
         * to perform better.
         */
    PropertyRecord host = null;
    long firstProp = primitive.getNextProp();
    if (firstProp != Record.NO_NEXT_PROPERTY.intValue()) {
        // We do not store in map - might not have enough space
        PropertyRecord propRecord = getPropertyRecord(firstProp, false, false);
        assert propRecord.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue() : propRecord + " for " + primitive;
        assert propRecord.inUse() : propRecord;
        int propSize = propRecord.size();
        assert propSize > 0 : propRecord;
        if (propSize + newBlockSizeInBytes <= PropertyType.getPayloadSize()) {
            host = propRecord;
            host.addPropertyBlock(block);
            host.setChanged();
        }
    }
    if (host == null) {
        // First record in chain didn't fit, make new one
        host = new PropertyRecord(getPropertyStore().nextId());
        host.setCreated();
        if (primitive.getNextProp() != Record.NO_NEXT_PROPERTY.intValue()) {
            PropertyRecord prevProp = getPropertyRecord(primitive.getNextProp(), true, true);
            if (isNode) {
                addNodeRecord((NodeRecord) primitive);
            } else {
                addRelationshipRecord((RelationshipRecord) primitive);
            }
            assert prevProp.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue();
            prevProp.setPrevProp(host.getId());
            host.setNextProp(prevProp.getId());
            prevProp.setChanged();
        }
        primitive.setNextProp(host.getId());
        host.addPropertyBlock(block);
        host.setInUse(true);
    }
    // Ok, here host does for the job. Use it
    if (isNode) {
        host.setNodeId(primitive.getId());
    } else {
        host.setRelId(primitive.getId());
    }
    addPropertyRecord(host);
    assert assertPropertyChain(primitive);
    return host;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord)

Example 8 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method assertPropertyChain.

private boolean assertPropertyChain(PrimitiveRecord primitive) {
    List<PropertyRecord> toCheck = new LinkedList<PropertyRecord>();
    long nextIdToFetch = primitive.getNextProp();
    while (nextIdToFetch != Record.NO_NEXT_PROPERTY.intValue()) {
        PropertyRecord toAdd = getPropertyRecord(nextIdToFetch, true, false);
        toCheck.add(toAdd);
        assert toAdd.inUse() : primitive + "->" + Arrays.toString(toCheck.toArray());
        nextIdToFetch = toAdd.getNextProp();
    }
    if (toCheck.isEmpty()) {
        assert primitive.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive;
        return true;
    }
    PropertyRecord first = toCheck.get(0);
    PropertyRecord last = toCheck.get(toCheck.size() - 1);
    assert first.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
    assert last.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
    PropertyRecord current, previous = first;
    for (int i = 1; i < toCheck.size(); i++) {
        current = toCheck.get(i);
        assert current.getPrevProp() == previous.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
        assert previous.getNextProp() == current.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
        previous = current;
    }
    return true;
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) LinkedList(java.util.LinkedList)

Example 9 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method loadPropertyValue.

@Override
public Object loadPropertyValue(PropertyData propertyData) {
    PropertyRecord propertyRecord = propertyRecords.get(propertyData.getId());
    if (propertyRecord == null) {
        propertyRecord = getPropertyStore().getRecord(propertyData.getId());
    }
    PropertyBlock block = propertyRecord.getPropertyBlock(propertyData.getIndex());
    if (block == null) {
        throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyData.getId() + "]");
    }
    if (block.isLight()) {
        getPropertyStore().makeHeavy(block);
    }
    return block.getType().getValue(block, getPropertyStore());
}
Also used : PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.nioneo.store.PropertyBlock)

Example 10 with PropertyRecord

use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.

the class WriteTransaction method doPrepare.

@Override
protected void doPrepare() throws XAException {
    if (committed) {
        throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
    }
    if (prepared) {
        throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
    }
    // generate records then write to logical log via addCommand method
    prepared = true;
    for (RelationshipTypeRecord record : relTypeRecords.values()) {
        Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
        relTypeCommands.add(command);
        addCommand(command);
    }
    for (NodeRecord record : nodeRecords.values()) {
        if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
            throw new InvalidRecordException("Node record " + record + " still has relationships");
        }
        Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
        nodeCommands.add(command);
        if (!record.inUse()) {
            removeNodeFromCache(record.getId());
        }
        addCommand(command);
    }
    for (RelationshipRecord record : relRecords.values()) {
        Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
        relCommands.add(command);
        if (!record.inUse()) {
            removeRelationshipFromCache(record.getId());
        }
        addCommand(command);
    }
    for (PropertyIndexRecord record : propIndexRecords.values()) {
        Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
        propIndexCommands.add(command);
        addCommand(command);
    }
    for (PropertyRecord record : propertyRecords.values()) {
        Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
        propCommands.add(command);
        addCommand(command);
    }
}
Also used : XAException(javax.transaction.xa.XAException) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) PropertyIndexRecord(org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord) RelationshipTypeRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) NodeRecord(org.neo4j.kernel.impl.nioneo.store.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.nioneo.store.PropertyRecord) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) XaCommand(org.neo4j.kernel.impl.transaction.xaframework.XaCommand) PropertyCommand(org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)36 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)15 PropertyBlock (org.neo4j.kernel.impl.nioneo.store.PropertyBlock)13 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)12 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)12 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)8 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)7 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)7 PropertyStore (org.neo4j.kernel.impl.nioneo.store.PropertyStore)6 XAException (javax.transaction.xa.XAException)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ArrayList (java.util.ArrayList)3 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 PropertyStore.encodeString (org.neo4j.kernel.impl.nioneo.store.PropertyStore.encodeString)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 PropertyType (org.neo4j.kernel.impl.nioneo.store.PropertyType)1