use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization method serialize.
/**
* Serialize the provided IndexRule onto the target buffer
* @param indexRule the IndexRule to serialize
* @throws IllegalStateException if the IndexRule is of type unique, but the owning constrain has not been set
*/
public static byte[] serialize(IndexRule indexRule) {
ByteBuffer target = ByteBuffer.allocate(lengthOf(indexRule));
target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID);
target.put(INDEX_RULE);
SchemaIndexProvider.Descriptor providerDescriptor = indexRule.getProviderDescriptor();
UTF8.putEncodedStringInto(providerDescriptor.getKey(), target);
UTF8.putEncodedStringInto(providerDescriptor.getVersion(), target);
NewIndexDescriptor indexDescriptor = indexRule.getIndexDescriptor();
switch(indexDescriptor.type()) {
case GENERAL:
target.put(GENERAL_INDEX);
break;
case UNIQUE:
target.put(UNIQUE_INDEX);
// The owning constraint can be null. See IndexRule.getOwningConstraint()
Long owningConstraint = indexRule.getOwningConstraint();
target.putLong(owningConstraint == null ? NO_OWNING_CONSTRAINT_YET : owningConstraint);
break;
default:
throw new UnsupportedOperationException(format("Got unknown index descriptor type '%s'.", indexDescriptor.type()));
}
indexDescriptor.schema().processWith(new SchemaDescriptorSerializer(target));
UTF8.putEncodedStringInto(indexRule.getName(), target);
return target.array();
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization method lengthOf.
/**
* Compute the byte size needed to serialize the provided IndexRule using serialize.
* @param indexRule the IndexRule
* @return the byte size of indexRule
*/
public static int lengthOf(IndexRule indexRule) {
// legacy label or relType id
int length = 4;
// schema rule type
length += 1;
SchemaIndexProvider.Descriptor providerDescriptor = indexRule.getProviderDescriptor();
length += UTF8.computeRequiredByteBufferSize(providerDescriptor.getKey());
length += UTF8.computeRequiredByteBufferSize(providerDescriptor.getVersion());
// index type
length += 1;
NewIndexDescriptor indexDescriptor = indexRule.getIndexDescriptor();
if (indexDescriptor.type() == NewIndexDescriptor.Type.UNIQUE) {
// owning constraint id
length += 8;
}
length += indexDescriptor.schema().computeWith(schemaSizeComputer);
length += UTF8.computeRequiredByteBufferSize(indexRule.getName());
return length;
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class SchemaRuleSerialization method readIndexRule.
// PRIVATE
// READ INDEX
private static IndexRule readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
SchemaIndexProvider.Descriptor indexProvider = readIndexProviderDescriptor(source);
LabelSchemaDescriptor schema;
byte indexRuleType = source.get();
String name;
switch(indexRuleType) {
case GENERAL_INDEX:
schema = readLabelSchema(source);
name = readRuleName(id, IndexRule.class, source);
return IndexRule.indexRule(id, NewIndexDescriptorFactory.forSchema(schema), indexProvider, name);
case UNIQUE_INDEX:
long owningConstraint = source.getLong();
schema = readLabelSchema(source);
NewIndexDescriptor descriptor = NewIndexDescriptorFactory.uniqueForSchema(schema);
name = readRuleName(id, IndexRule.class, source);
return IndexRule.constraintIndexRule(id, descriptor, indexProvider, owningConstraint == NO_OWNING_CONSTRAINT_YET ? null : owningConstraint, name);
default:
throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor 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.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class GraphDbStructureGuide method showUniqueIndices.
private void showUniqueIndices(DbStructureVisitor visitor, ReadOperations read, TokenNameLookup nameLookup) throws IndexNotFoundKernelException {
for (NewIndexDescriptor descriptor : loop(read.uniqueIndexesGetAll())) {
String userDescription = descriptor.schema().userDescription(nameLookup);
double uniqueValuesPercentage = read.indexUniqueValuesSelectivity(descriptor);
long size = read.indexSize(descriptor);
visitor.visitUniqueIndex(descriptor, userDescription, uniqueValuesPercentage, size);
}
}
Aggregations