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);
}
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations