Search in sources :

Example 1 with SchemaProcessor

use of org.neo4j.internal.schema.SchemaProcessor in project neo4j by neo4j.

the class SchemaProcessorTest method shouldHandleCorrectDescriptorVersions.

@Test
void shouldHandleCorrectDescriptorVersions() {
    List<String> callHistory = new ArrayList<>();
    SchemaProcessor processor = new SchemaProcessor() {

        @Override
        public void processSpecific(LabelSchemaDescriptor schema) {
            callHistory.add("LabelSchemaDescriptor");
        }

        @Override
        public void processSpecific(RelationTypeSchemaDescriptor schema) {
            callHistory.add("RelationTypeSchemaDescriptor");
        }

        @Override
        public void processSpecific(SchemaDescriptor schemaDescriptor) {
            callHistory.add("SchemaDescriptor");
        }
    };
    disguisedLabel().processWith(processor);
    disguisedLabel().processWith(processor);
    disguisedRelType().processWith(processor);
    disguisedLabel().processWith(processor);
    disguisedRelType().processWith(processor);
    disguisedRelType().processWith(processor);
    assertThat(callHistory).containsExactly("LabelSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "LabelSchemaDescriptor", "RelationTypeSchemaDescriptor", "RelationTypeSchemaDescriptor");
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ArrayList(java.util.ArrayList) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaProcessor(org.neo4j.internal.schema.SchemaProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with SchemaProcessor

use of org.neo4j.internal.schema.SchemaProcessor in project neo4j by neo4j.

the class SchemaChecker method performSchemaCheck.

private void performSchemaCheck(long highId, RecordReader<SchemaRecord> reader, Map<Long, SchemaRecord> indexObligations, Map<Long, SchemaRecord> constraintObligations, SchemaStorage schemaStorage, MutableIntObjectMap<MutableIntSet> mandatoryNodeProperties, MutableIntObjectMap<MutableIntSet> mandatoryRelationshipProperties, CursorContext cursorContext) {
    SchemaRecord record = reader.record();
    SchemaProcessor basicSchemaCheck = new BasicSchemaCheck(record, cursorContext);
    SchemaProcessor mandatoryPropertiesBuilder = new MandatoryPropertiesBuilder(mandatoryNodeProperties, mandatoryRelationshipProperties);
    for (long id = schemaStore.getNumberOfReservedLowIds(); id < highId && !context.isCancelled(); id++) {
        try {
            reader.read(id);
            if (record.inUse()) {
                SchemaRule schemaRule = schemaStorage.loadSingleSchemaRule(id, cursorContext);
                schemaRule.schema().processWith(basicSchemaCheck);
                if (schemaRule instanceof IndexDescriptor) {
                    IndexDescriptor rule = (IndexDescriptor) schemaRule;
                    if (rule.isUnique()) {
                        SchemaRecord obligation = indexObligations.get(rule.getId());
                        if (// no pointer to here
                        obligation == null) {
                            if (// we only expect a pointer if we have an owner
                            rule.getOwningConstraintId().isPresent()) {
                                reporter.forSchema(record).missingObligation(SchemaRuleKind.UNIQUENESS_CONSTRAINT.name());
                            }
                        } else {
                            // if someone points to here, it must be our owner
                            OptionalLong owningConstraintId = rule.getOwningConstraintId();
                            if (owningConstraintId.isEmpty() || obligation.getId() != owningConstraintId.getAsLong()) {
                                reporter.forSchema(record).constraintIndexRuleNotReferencingBack(obligation);
                            }
                        }
                    }
                    if (indexAccessors.notOnlineRules().contains(rule)) {
                        reporter.forSchema(record).schemaRuleNotOnline(rule);
                    }
                    if (indexAccessors.inconsistentRules().contains(rule)) {
                        reporter.forSchema(record).malformedSchemaRule();
                    }
                } else if (schemaRule instanceof ConstraintDescriptor) {
                    ConstraintDescriptor rule = (ConstraintDescriptor) schemaRule;
                    if (rule.enforcesUniqueness()) {
                        SchemaRecord obligation = constraintObligations.get(rule.getId());
                        if (obligation == null) {
                            reporter.forSchema(record).missingObligation(SchemaRuleKind.CONSTRAINT_INDEX_RULE.name());
                        } else {
                            if (obligation.getId() != rule.asIndexBackedConstraint().ownedIndexId()) {
                                reporter.forSchema(record).uniquenessConstraintNotReferencingBack(obligation);
                            }
                        }
                    }
                    if (rule.enforcesPropertyExistence()) {
                        rule.schema().processWith(mandatoryPropertiesBuilder);
                    }
                } else {
                    reporter.forSchema(record).unsupportedSchemaRuleType(null);
                }
            }
        } catch (MalformedSchemaRuleException e) {
            reporter.forSchema(record).malformedSchemaRule();
        }
    }
}
Also used : MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaRule(org.neo4j.internal.schema.SchemaRule) OptionalLong(java.util.OptionalLong) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) SchemaProcessor(org.neo4j.internal.schema.SchemaProcessor)

Aggregations

SchemaProcessor (org.neo4j.internal.schema.SchemaProcessor)2 ArrayList (java.util.ArrayList)1 OptionalLong (java.util.OptionalLong)1 Test (org.junit.jupiter.api.Test)1 MalformedSchemaRuleException (org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException)1 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)1 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)1 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)1 SchemaRule (org.neo4j.internal.schema.SchemaRule)1 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)1