Search in sources :

Example 6 with InvalidRecordException

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);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException)

Example 7 with InvalidRecordException

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;
        }
    };
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PrefetchingIterator(org.neo4j.internal.helpers.collection.PrefetchingIterator) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.internal.schema.SchemaRule) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException) InvalidRecordException(org.neo4j.kernel.impl.store.InvalidRecordException) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)

Aggregations

InvalidRecordException (org.neo4j.kernel.impl.store.InvalidRecordException)7 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)4 ByteBuffer (java.nio.ByteBuffer)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 PrefetchingIterator (org.neo4j.internal.helpers.collection.PrefetchingIterator)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1 AbstractBaseRecord (org.neo4j.kernel.impl.store.record.AbstractBaseRecord)1 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)1 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)1 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)1 PhysicalLogVersionedStoreChannel (org.neo4j.kernel.impl.transaction.log.PhysicalLogVersionedStoreChannel)1