use of org.neo4j.kernel.impl.store.InvalidRecordException in project neo4j by neo4j.
the class RelationshipCreator method connectSparse.
private void connectSparse(long nodeId, long firstRelId, RelationshipRecord createdRelationship, RecordAccess<RelationshipRecord, Void> relRecords) {
long newCount = 1;
if (!isNull(firstRelId)) {
RelationshipRecord firstRel = relRecords.getOrLoad(firstRelId, null, cursorContext).forChangingLinkage();
boolean changed = false;
if (firstRel.getFirstNode() == nodeId) {
newCount = firstRel.getFirstPrevRel() + 1;
firstRel.setFirstPrevRel(createdRelationship.getId());
firstRel.setFirstInFirstChain(false);
changed = true;
}
if (firstRel.getSecondNode() == nodeId) {
newCount = firstRel.getSecondPrevRel() + 1;
firstRel.setSecondPrevRel(createdRelationship.getId());
firstRel.setFirstInSecondChain(false);
changed = true;
}
if (!changed) {
throw new InvalidRecordException(nodeId + " doesn't match " + firstRel);
}
}
// Set the relationship count
if (createdRelationship.getFirstNode() == nodeId) {
createdRelationship.setFirstPrevRel(newCount);
createdRelationship.setFirstInFirstChain(true);
}
if (createdRelationship.getSecondNode() == nodeId) {
createdRelationship.setSecondPrevRel(newCount);
createdRelationship.setFirstInSecondChain(true);
}
}
use of org.neo4j.kernel.impl.store.InvalidRecordException in project neo4j by neo4j.
the class SchemaStorage35 method loadAllSchemaRules.
/**
* Scans the schema store and loads all {@link SchemaRule rules} in it. This method is written with the assumption
* that there's no id reuse on schema records.
*
* @param returnType type of {@link SchemaRule} to load.
* @return {@link Iterator} of the loaded schema rules, lazily loaded when advancing the iterator.
*/
private <ReturnType extends SchemaRule> Iterator<ReturnType> loadAllSchemaRules(final Class<ReturnType> returnType, CursorContext cursorContext, ThrowingConsumer<Exception, RuntimeException> malformedExceptionHandler) {
return new PrefetchingIterator<>() {
private final long highestId = schemaStore.getHighestPossibleIdInUse(cursorContext);
private long currentId = 1;
/*record 0 contains the block size*/
private final byte[] scratchData = newRecordBuffer();
private final DynamicRecord record = schemaStore.newRecord();
@Override
protected ReturnType fetchNextOrNull() {
while (currentId <= highestId) {
try {
long id = currentId++;
schemaStore.getRecord(id, record, RecordLoad.LENIENT_CHECK, cursorContext);
if (!record.inUse()) {
continue;
}
schemaStore.getRecord(id, record, RecordLoad.NORMAL, cursorContext);
if (record.isStartRecord()) {
// that we're reading and that rule may have spanned multiple dynamic records.
try {
Collection<DynamicRecord> records;
try {
records = schemaStore.getRecords(id, RecordLoad.NORMAL, false, cursorContext);
} catch (InvalidRecordException e) {
// This may have been due to a concurrent drop of this rule.
continue;
}
SchemaRule schemaRule = SchemaStore35.readSchemaRule(id, records, scratchData);
if (returnType.isInstance(schemaRule)) {
return returnType.cast(schemaRule);
}
} catch (MalformedSchemaRuleException e) {
throw new RuntimeException(e);
}
}
} catch (Exception e) {
malformedExceptionHandler.accept(e);
}
}
return null;
}
};
}
Aggregations