use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project graphdb by neo4j-attic.
the class WriteTransaction method disconnectRelationship.
private void disconnectRelationship(RelationshipRecord rel) {
// update first node prev
if (rel.getFirstPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getFirstPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getFirstPrevRel());
addRelationshipRecord(prevRel);
}
if (prevRel.getFirstNode() == rel.getFirstNode()) {
prevRel.setFirstNextRel(rel.getFirstNextRel());
} else if (prevRel.getSecondNode() == rel.getFirstNode()) {
prevRel.setSecondNextRel(rel.getFirstNextRel());
} else {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update first node next
if (rel.getFirstNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getFirstNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getFirstNextRel());
addRelationshipRecord(nextRel);
}
if (nextRel.getFirstNode() == rel.getFirstNode()) {
nextRel.setFirstPrevRel(rel.getFirstPrevRel());
} else if (nextRel.getSecondNode() == rel.getFirstNode()) {
nextRel.setSecondPrevRel(rel.getFirstPrevRel());
} else {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
// update second node prev
if (rel.getSecondPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getSecondPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getSecondPrevRel());
addRelationshipRecord(prevRel);
}
if (prevRel.getFirstNode() == rel.getSecondNode()) {
prevRel.setFirstNextRel(rel.getSecondNextRel());
} else if (prevRel.getSecondNode() == rel.getSecondNode()) {
prevRel.setSecondNextRel(rel.getSecondNextRel());
} else {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update second node next
if (rel.getSecondNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getSecondNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getSecondNextRel());
addRelationshipRecord(nextRel);
}
if (nextRel.getFirstNode() == rel.getSecondNode()) {
nextRel.setFirstPrevRel(rel.getSecondPrevRel());
} else if (nextRel.getSecondNode() == rel.getSecondNode()) {
nextRel.setSecondPrevRel(rel.getSecondPrevRel());
} else {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project graphdb by neo4j-attic.
the class WriteTransaction method connectRelationship.
private void connectRelationship(NodeRecord firstNode, NodeRecord secondNode, RelationshipRecord rel) {
assert firstNode.getNextRel() != rel.getId();
assert secondNode.getNextRel() != rel.getId();
rel.setFirstNextRel(firstNode.getNextRel());
rel.setSecondNextRel(secondNode.getNextRel());
if (firstNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(firstNode.getNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(firstNode.getNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(firstNode.getNextRel());
addRelationshipRecord(nextRel);
}
if (nextRel.getFirstNode() == firstNode.getId()) {
nextRel.setFirstPrevRel(rel.getId());
} else if (nextRel.getSecondNode() == firstNode.getId()) {
nextRel.setSecondPrevRel(rel.getId());
} else {
throw new InvalidRecordException(firstNode + " dont match " + nextRel);
}
}
if (secondNode.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(secondNode.getNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(secondNode.getNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(secondNode.getNextRel());
addRelationshipRecord(nextRel);
}
if (nextRel.getFirstNode() == secondNode.getId()) {
nextRel.setFirstPrevRel(rel.getId());
} else if (nextRel.getSecondNode() == secondNode.getId()) {
nextRel.setSecondPrevRel(rel.getId());
} else {
throw new InvalidRecordException(secondNode + " dont match " + nextRel);
}
}
firstNode.setNextRel(rel.getId());
secondNode.setNextRel(rel.getId());
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project graphdb by neo4j-attic.
the class WriteTransaction method nodeGetProperties.
ArrayMap<Integer, PropertyData> nodeGetProperties(long nodeId, boolean light) {
ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
NodeRecord nodeRecord = getNodeRecord(nodeId);
if (nodeRecord != null && nodeRecord.isCreated()) {
return propertyMap;
}
if (nodeRecord != null) {
if (!nodeRecord.inUse() && !light) {
throw new IllegalStateException("Node[" + nodeId + "] has been deleted in this tx");
}
}
nodeRecord = getNodeStore().getRecord(nodeId);
if (!nodeRecord.inUse()) {
throw new InvalidRecordException("Node[" + nodeId + "] not in use");
}
long nextProp = nodeRecord.getNextProp();
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = getPropertyStore().getLightRecord(nextProp);
propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
nextProp = propRecord.getNextProp();
}
return propertyMap;
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class ReadTransaction method getMoreRelationships.
static Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, Long> getMoreRelationships(long nodeId, long position, int grabSize, RelationshipStore relStore) {
// initialCapacity=grabSize saves the lists the trouble of resizing
List<RelationshipRecord> out = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> in = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> loop = null;
Map<DirectionWrapper, Iterable<RelationshipRecord>> result = new EnumMap<DirectionWrapper, Iterable<RelationshipRecord>>(DirectionWrapper.class);
result.put(DirectionWrapper.OUTGOING, out);
result.put(DirectionWrapper.INCOMING, in);
for (int i = 0; i < grabSize && position != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = relStore.getChainRecord(position);
if (relRecord == null) {
// return what we got so far
return Pair.of(result, position);
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (relRecord.inUse()) {
if (firstNode == secondNode) {
if (loop == null) {
// This is done lazily because loops are probably quite
// rarely encountered
loop = new ArrayList<RelationshipRecord>();
result.put(DirectionWrapper.BOTH, loop);
}
loop.add(relRecord);
} else if (firstNode == nodeId) {
out.add(relRecord);
} else if (secondNode == nodeId) {
in.add(relRecord);
}
} else {
i--;
}
if (firstNode == nodeId) {
position = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
position = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
return Pair.of(result, position);
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relLoadProperties.
@Override
public ArrayMap<Integer, PropertyData> relLoadProperties(long relId, boolean light) {
RelationshipRecord relRecord = getRelationshipRecord(relId);
if (relRecord != null && relRecord.isCreated()) {
return null;
}
if (relRecord != null) {
if (!relRecord.inUse() && !light) {
throw new IllegalStateException("Relationship[" + relId + "] has been deleted in this tx");
}
}
relRecord = getRelationshipStore().getRecord(relId);
if (!relRecord.inUse()) {
throw new InvalidRecordException("Relationship[" + relId + "] not in use");
}
return ReadTransaction.loadProperties(getPropertyStore(), relRecord.getNextProp());
}
Aggregations