use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class SchemaCache method removeSchemaRule.
public void removeSchemaRule(long id) {
if (constraintRuleById.containsKey(id)) {
ConstraintRule rule = constraintRuleById.remove(id);
constraints.remove(constraintSemantics.readConstraint(rule));
} else if (indexRuleById.containsKey(id)) {
IndexRule rule = indexRuleById.remove(id);
indexDescriptors.remove(rule.schema());
}
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class IndexLookup method buildIndexRuleIndex.
private PrimitiveIntObjectMap<List<IndexRule>> buildIndexRuleIndex(SchemaStore schemaStore) {
final PrimitiveIntObjectMap<List<IndexRule>> indexRuleIndex = Primitive.intObjectMap();
for (SchemaRule schemaRule : schemaStore) {
if (schemaRule instanceof IndexRule) {
IndexRule rule = (IndexRule) schemaRule;
// assuming 1 property always
int propertyId = rule.schema().getPropertyId();
List<IndexRule> ruleList = indexRuleIndex.get(propertyId);
if (ruleList == null) {
ruleList = new LinkedList<>();
indexRuleIndex.put(propertyId, ruleList);
}
ruleList.add(rule);
}
}
return indexRuleIndex;
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class SchemaStorage method indexGetForSchema.
/**
* Find the IndexRule that matches the given NewIndexDescriptor.
*
* @return the matching IndexRule, or null if no matching IndexRule was found
* @throws IllegalStateException if more than one matching rule.
* @param descriptor the target NewIndexDescriptor
*/
public IndexRule indexGetForSchema(final NewIndexDescriptor descriptor) {
Iterator<IndexRule> rules = loadAllSchemaRules(descriptor::isSame, IndexRule.class, false);
IndexRule foundRule = null;
while (rules.hasNext()) {
IndexRule candidate = rules.next();
if (foundRule != null) {
throw new IllegalStateException(String.format("Found more than one matching index rule, %s and %s", foundRule, candidate));
}
foundRule = candidate;
}
return foundRule;
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class BatchInserterImpl method repopulateAllIndexes.
private void repopulateAllIndexes() throws IOException, IndexEntryConflictException {
if (!labelsTouched) {
return;
}
final IndexRule[] rules = getIndexesNeedingPopulation();
final IndexPopulator[] populators = new IndexPopulator[rules.length];
// the store is uncontended at this point, so creating a local LockService is safe.
final NewIndexDescriptor[] descriptors = new NewIndexDescriptor[rules.length];
for (int i = 0; i < rules.length; i++) {
IndexRule rule = rules[i];
descriptors[i] = rule.getIndexDescriptor();
populators[i] = schemaIndexProviders.apply(rule.getProviderDescriptor()).getPopulator(rule.getId(), descriptors[i], new IndexSamplingConfig(config));
populators[i].create();
}
Visitor<NodeUpdates, IOException> propertyUpdateVisitor = updates -> {
for (int i = 0; i < descriptors.length; i++) {
Optional<IndexEntryUpdate> update = updates.forIndex(descriptors[i].schema());
if (update.isPresent()) {
try {
populators[i].add(Collections.singletonList(update.get()));
} catch (IndexEntryConflictException conflict) {
throw conflict.notAllowed(descriptors[i]);
}
}
}
return true;
};
List<NewIndexDescriptor> descriptorList = Arrays.asList(descriptors);
int[] labelIds = descriptorList.stream().mapToInt(index -> index.schema().getLabelId()).toArray();
int[] propertyKeyIds = descriptorList.stream().flatMapToInt(d -> Arrays.stream(d.schema().getPropertyIds())).toArray();
InitialNodeLabelCreationVisitor labelUpdateVisitor = new InitialNodeLabelCreationVisitor();
StoreScan<IOException> storeScan = indexStoreView.visitNodes(labelIds, (propertyKeyId) -> PrimitiveIntCollections.contains(propertyKeyIds, propertyKeyId), propertyUpdateVisitor, labelUpdateVisitor, true);
storeScan.run();
for (IndexPopulator populator : populators) {
populator.verifyDeferredConstraints(indexStoreView);
populator.close(true);
}
labelUpdateVisitor.close();
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class SchemaRecordCheckTest method shouldReportInvalidPropertyReferenceFromIndexRule.
@Test
public void shouldReportInvalidPropertyReferenceFromIndexRule() throws Exception {
// given
int schemaRuleId = 0;
DynamicRecord record = inUse(dynamicRecord(schemaRuleId));
SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor("in-memory", "1.0");
IndexRule rule = indexRule(schemaRuleId, labelId, propertyKeyId, providerDescriptor);
when(checker().ruleAccess.loadSingleSchemaRule(schemaRuleId)).thenReturn(rule);
add(inUse(new LabelTokenRecord(labelId)));
PropertyKeyTokenRecord propertyKeyToken = add(notInUse(new PropertyKeyTokenRecord(propertyKeyId)));
// when
ConsistencyReport.SchemaConsistencyReport report = check(record);
// then
verify(report).propertyKeyNotInUse(propertyKeyToken);
}
Aggregations