Search in sources :

Example 11 with InvalidRecordException

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

the class WriteTransaction method connect.

private void connect(NodeRecord node, RelationshipRecord rel) {
    if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
        Relationship lockableRel = new LockableRelationship(node.getNextRel());
        getWriteLock(lockableRel);
        RelationshipRecord nextRel = getRelationshipRecord(node.getNextRel());
        if (nextRel == null) {
            nextRel = getRelationshipStore().getRecord(node.getNextRel());
            addRelationshipRecord(nextRel);
        }
        boolean changed = false;
        if (nextRel.getFirstNode() == node.getId()) {
            nextRel.setFirstPrevRel(rel.getId());
            changed = true;
        }
        if (nextRel.getSecondNode() == node.getId()) {
            nextRel.setSecondPrevRel(rel.getId());
            changed = true;
        }
        if (!changed) {
            throw new InvalidRecordException(node + " dont match " + nextRel);
        }
    }
}
Also used : Relationship(org.neo4j.graphdb.Relationship) RelationshipRecord(org.neo4j.kernel.impl.nioneo.store.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 12 with InvalidRecordException

use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException 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)

Example 13 with InvalidRecordException

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

the class LegacyDynamicRecordFetcher method getArrayFor.

public Object getArrayFor(LegacyPropertyRecord propertyRecord) {
    long recordToFind = propertyRecord.getPropBlock();
    Map<Long, LegacyDynamicRecord> recordsMap = new HashMap<Long, LegacyDynamicRecord>();
    for (LegacyDynamicRecord record : readDynamicRecords(propertyRecord)) {
        recordsMap.put(record.getId(), record);
    }
    List<byte[]> byteList = new LinkedList<byte[]>();
    int totalSize = 0;
    while (recordToFind != Record.NO_NEXT_BLOCK.intValue()) {
        LegacyDynamicRecord record = recordsMap.get(recordToFind);
        if (!record.isCharData()) {
            ByteBuffer buf = ByteBuffer.wrap(record.getData());
            byte[] bytes = new byte[record.getData().length];
            totalSize += bytes.length;
            buf.get(bytes);
            byteList.add(bytes);
        } else {
            throw new InvalidRecordException("Expected byte data on record " + record);
        }
        recordToFind = record.getNextBlock();
    }
    byte[] bArray = new byte[totalSize];
    int offset = 0;
    for (byte[] currentArray : byteList) {
        System.arraycopy(currentArray, 0, bArray, offset, currentArray.length);
        offset += currentArray.length;
    }
    return arrayPropertyStore.getRightArray(bArray);
}
Also used : HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException) LinkedList(java.util.LinkedList)

Example 14 with InvalidRecordException

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

the class LegacyDynamicStoreReader method getRecord.

private LegacyDynamicRecord getRecord(long blockId, PersistenceWindow window) {
    LegacyDynamicRecord record = new LegacyDynamicRecord(blockId);
    Buffer buffer = window.getOffsettedBuffer(blockId);
    // [    ,   x] in use
    // [xxxx,    ] high bits for prev block
    long inUseByte = buffer.get();
    boolean inUse = (inUseByte & 0x1) == Record.IN_USE.intValue();
    if (!inUse) {
        throw new InvalidRecordException("Not in use, blockId[" + blockId + "]");
    }
    long prevBlock = buffer.getUnsignedInt();
    long prevModifier = (inUseByte & 0xF0L) << 28;
    int dataSize = blockSize - BLOCK_HEADER_SIZE;
    // [    ,    ][xxxx,xxxx][xxxx,xxxx][xxxx,xxxx] number of bytes
    // [    ,xxxx][    ,    ][    ,    ][    ,    ] higher bits for next block
    long nrOfBytesInt = buffer.getInt();
    int nrOfBytes = (int) (nrOfBytesInt & 0xFFFFFF);
    long nextBlock = buffer.getUnsignedInt();
    long nextModifier = (nrOfBytesInt & 0xF000000L) << 8;
    long longNextBlock = LegacyStore.longFromIntAndMod(nextBlock, nextModifier);
    if (longNextBlock != Record.NO_NEXT_BLOCK.intValue() && nrOfBytes < dataSize || nrOfBytes > dataSize) {
        throw new InvalidRecordException("Next block set[" + nextBlock + "] current block illegal size[" + nrOfBytes + "/" + dataSize + "]");
    }
    record.setInUse(true);
    record.setLength(nrOfBytes);
    record.setPrevBlock(LegacyStore.longFromIntAndMod(prevBlock, prevModifier));
    record.setNextBlock(longNextBlock);
    byte[] byteArrayElement = new byte[nrOfBytes];
    buffer.get(byteArrayElement);
    record.setData(byteArrayElement);
    return record;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.neo4j.kernel.impl.nioneo.store.Buffer) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Example 15 with InvalidRecordException

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

the class BatchGraphDatabaseImpl method getNodeById.

public Node getNodeById(long id) {
    NodeBatchImpl node = nodes.get(id);
    if (node == null) {
        try {
            node = new NodeBatchImpl(id, this, batchInserter.getNodeProperties(id));
            nodes.put(id, node);
        } catch (InvalidRecordException e) {
            throw new NotFoundException(e);
        }
    }
    return node;
}
Also used : NotFoundException(org.neo4j.graphdb.NotFoundException) InvalidRecordException(org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)

Aggregations

InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)29 RelationshipRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipRecord)20 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)10 ArrayList (java.util.ArrayList)7 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)7 XAException (javax.transaction.xa.XAException)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 Relationship (org.neo4j.graphdb.Relationship)4 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)4 RelationshipTypeRecord (org.neo4j.kernel.impl.nioneo.store.RelationshipTypeRecord)4 ByteBuffer (java.nio.ByteBuffer)3 PropertyData (org.neo4j.kernel.impl.nioneo.store.PropertyData)3 ArrayMap (org.neo4j.kernel.impl.util.ArrayMap)3 RelationshipType (org.neo4j.graphdb.RelationshipType)2 DynamicRecord (org.neo4j.kernel.impl.nioneo.store.DynamicRecord)2 RelationshipData (org.neo4j.kernel.impl.nioneo.store.RelationshipData)2 PropertyCommand (org.neo4j.kernel.impl.nioneo.xa.Command.PropertyCommand)2 XaCommand (org.neo4j.kernel.impl.transaction.xaframework.XaCommand)2 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1