use of org.neo4j.consistency.checking.SchemaRuleKey in project neo4j by neo4j.
the class SchemaChecker method checkSchema.
private void checkSchema(MutableIntObjectMap<MutableIntSet> mandatoryNodeProperties, MutableIntObjectMap<MutableIntSet> mandatoryRelationshipProperties, CursorContext cursorContext) {
long highId = schemaStore.getHighId();
try (RecordReader<SchemaRecord> schemaReader = new RecordReader<>(schemaStore, true, cursorContext)) {
Map<Long, SchemaRecord> indexObligations = new HashMap<>();
Map<Long, SchemaRecord> constraintObligations = new HashMap<>();
Map<SchemaRuleKey, SchemaRecord> verifiedRulesWithRecords = new HashMap<>();
// KernelVersion only controls if there will be an injected NLI on non-upgraded stores. That index is not in the store and will
// not be found when going through the file in performSchemaCheck anyway so we can use latest KernelVersion here.
// If an injected NLI exist but is not online that will not be reported, but this is an unlikely corner case that we
// ignore. The index itself will be checked as long as it is online (it is found by IndexAccessors).
SchemaStorage schemaStorage = new SchemaStorage(schemaStore, tokenHolders, () -> KernelVersion.LATEST);
// Build map of obligations and such
buildObligationsMap(highId, schemaReader, schemaStorage, indexObligations, constraintObligations, verifiedRulesWithRecords, cursorContext);
// Verify all things, now that we have the complete map of obligations back and forth
performSchemaCheck(highId, schemaReader, indexObligations, constraintObligations, schemaStorage, mandatoryNodeProperties, mandatoryRelationshipProperties, cursorContext);
}
}
use of org.neo4j.consistency.checking.SchemaRuleKey in project neo4j by neo4j.
the class SchemaChecker method buildObligationsMap.
private void buildObligationsMap(long highId, RecordReader<SchemaRecord> reader, SchemaStorage schemaStorage, Map<Long, SchemaRecord> indexObligations, Map<Long, SchemaRecord> constraintObligations, Map<SchemaRuleKey, SchemaRecord> verifiedRulesWithRecords, CursorContext cursorContext) {
for (long id = schemaStore.getNumberOfReservedLowIds(); id < highId && !context.isCancelled(); id++) {
try {
SchemaRecord record = reader.read(id);
if (!record.inUse()) {
continue;
}
SchemaRule schemaRule = schemaStorage.loadSingleSchemaRule(id, cursorContext);
SchemaRecord previousContentRecord = verifiedRulesWithRecords.put(new SchemaRuleKey(schemaRule), record.copy());
if (previousContentRecord != null) {
reporter.forSchema(record).duplicateRuleContent(previousContentRecord);
}
if (schemaRule instanceof IndexDescriptor) {
IndexDescriptor rule = (IndexDescriptor) schemaRule;
if (rule.isUnique() && rule.getOwningConstraintId().isPresent()) {
SchemaRecord previousObligation = constraintObligations.put(rule.getOwningConstraintId().getAsLong(), record.copy());
if (previousObligation != null) {
reporter.forSchema(record).duplicateObligation(previousObligation);
}
}
} else if (schemaRule instanceof ConstraintDescriptor) {
ConstraintDescriptor rule = (ConstraintDescriptor) schemaRule;
if (rule.enforcesUniqueness()) {
SchemaRecord previousObligation = indexObligations.put(rule.asIndexBackedConstraint().ownedIndexId(), record.copy());
if (previousObligation != null) {
reporter.forSchema(record).duplicateObligation(previousObligation);
}
}
}
} catch (MalformedSchemaRuleException e) {
// This is OK, we'll report it below
}
}
}
Aggregations