Search in sources :

Example 56 with NewIndexDescriptor

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();
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) ByteBuffer(java.nio.ByteBuffer)

Example 57 with NewIndexDescriptor

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;
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 58 with NewIndexDescriptor

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));
    }
}
Also used : SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 59 with NewIndexDescriptor

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();
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) Arrays(java.util.Arrays) SimpleKernelContext(org.neo4j.kernel.impl.spi.SimpleKernelContext) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) BatchRelationship(org.neo4j.unsafe.batchinsert.BatchRelationship) Iterators(org.neo4j.helpers.collection.Iterators) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) RelationshipGroupGetter(org.neo4j.kernel.impl.transaction.state.RelationshipGroupGetter) PrimitiveIntCollections(org.neo4j.collection.primitive.PrimitiveIntCollections) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) NodeLabelsField.parseLabelsField(org.neo4j.kernel.impl.store.NodeLabelsField.parseLabelsField) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) CountsComputer(org.neo4j.kernel.impl.store.CountsComputer) PropertyStore.encodeString(org.neo4j.kernel.impl.store.PropertyStore.encodeString) Map(java.util.Map) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) NodeMultiPropertyDescriptor(org.neo4j.kernel.api.schema.NodeMultiPropertyDescriptor) DefaultSchemaIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultSchemaIndexProviderMap) KernelExtensions(org.neo4j.kernel.extension.KernelExtensions) IndexDefinitionImpl(org.neo4j.kernel.impl.coreapi.schema.IndexDefinitionImpl) NullLog(org.neo4j.logging.NullLog) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) HighestSelectionStrategy(org.neo4j.kernel.extension.dependency.HighestSelectionStrategy) LabelTokenRecord(org.neo4j.kernel.impl.store.record.LabelTokenRecord) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) RecordCursors(org.neo4j.kernel.impl.store.RecordCursors) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Locks(org.neo4j.kernel.impl.locking.Locks) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) KernelExtensionFactory(org.neo4j.kernel.extension.KernelExtensionFactory) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) RelationshipType(org.neo4j.graphdb.RelationshipType) NodeStore(org.neo4j.kernel.impl.store.NodeStore) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory) IndexCreatorImpl(org.neo4j.kernel.impl.coreapi.schema.IndexCreatorImpl) RelationshipTypeToken(org.neo4j.kernel.impl.core.RelationshipTypeToken) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) PageCacheLifecycle(org.neo4j.kernel.impl.pagecache.PageCacheLifecycle) IteratorWrapper(org.neo4j.helpers.collection.IteratorWrapper) ArrayList(java.util.ArrayList) InternalSchemaActions(org.neo4j.kernel.impl.coreapi.schema.InternalSchemaActions) RelationshipStore(org.neo4j.kernel.impl.store.RelationshipStore) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) DirectRecordAccessSet(org.neo4j.unsafe.batchinsert.DirectRecordAccessSet) SchemaCache(org.neo4j.kernel.impl.api.store.SchemaCache) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) DatabaseInfo(org.neo4j.kernel.impl.factory.DatabaseInfo) UnsatisfiedDependencyStrategies(org.neo4j.kernel.extension.UnsatisfiedDependencyStrategies) Listener(org.neo4j.kernel.impl.util.Listener) PrimitiveLongCollections.map(org.neo4j.collection.primitive.PrimitiveLongCollections.map) BaseNodeConstraintCreator(org.neo4j.kernel.impl.coreapi.schema.BaseNodeConstraintCreator) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) IOException(java.io.IOException) Label.label(org.neo4j.graphdb.Label.label) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) IoPrimitiveUtils.safeCastLongToInt(org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt) File(java.io.File) Iterables(org.neo4j.helpers.collection.Iterables) ConstraintDescriptorFactory(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptorFactory) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) SchemaIndexProviderMap(org.neo4j.kernel.impl.api.index.SchemaIndexProviderMap) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) AlreadyConstrainedException(org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) PropertyDeleter(org.neo4j.kernel.impl.transaction.state.PropertyDeleter) Log(org.neo4j.logging.Log) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Dependencies(org.neo4j.kernel.impl.util.Dependencies) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) RelationshipTypeTokenStore(org.neo4j.kernel.impl.store.RelationshipTypeTokenStore) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Record(org.neo4j.kernel.impl.store.record.Record) PageCache(org.neo4j.io.pagecache.PageCache) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) PropertyCreator(org.neo4j.kernel.impl.transaction.state.PropertyCreator) Collection(java.util.Collection) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) KernelException(org.neo4j.kernel.api.exceptions.KernelException) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) RecordStore(org.neo4j.kernel.impl.store.RecordStore) List(java.util.List) NamedLabelScanStoreSelectionStrategy(org.neo4j.kernel.extension.dependency.NamedLabelScanStoreSelectionStrategy) StoreLocker(org.neo4j.kernel.internal.StoreLocker) Entry(java.util.Map.Entry) Optional(java.util.Optional) EmbeddedGraphDatabase(org.neo4j.kernel.internal.EmbeddedGraphDatabase) Label(org.neo4j.graphdb.Label) SchemaDescriptorFactory(org.neo4j.kernel.api.schema_new.SchemaDescriptorFactory) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) Token(org.neo4j.storageengine.api.Token) NotFoundException(org.neo4j.graphdb.NotFoundException) ConfiguringPageCacheFactory(org.neo4j.kernel.impl.pagecache.ConfiguringPageCacheFactory) UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NodeLabels(org.neo4j.kernel.impl.store.NodeLabels) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) NeoStores(org.neo4j.kernel.impl.store.NeoStores) StoreLogService(org.neo4j.kernel.impl.logging.StoreLogService) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) RelationshipTypeTokenRecord(org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord) PrintStream(java.io.PrintStream) Config(org.neo4j.kernel.configuration.Config) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordProxy(org.neo4j.kernel.impl.transaction.state.RecordAccess.RecordProxy) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) LockService(org.neo4j.kernel.impl.locking.LockService) RelationshipCreator(org.neo4j.kernel.impl.transaction.state.RelationshipCreator) Iterator(java.util.Iterator) LongFunction(java.util.function.LongFunction) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) RecordAccess(org.neo4j.kernel.impl.transaction.state.RecordAccess) PropertyKeyTokenRecord(org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord) IdValidator(org.neo4j.kernel.impl.store.id.validation.IdValidator) PropertyTraverser(org.neo4j.kernel.impl.transaction.state.PropertyTraverser) PrimitiveRecord(org.neo4j.kernel.impl.store.record.PrimitiveRecord) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) Visitor(org.neo4j.helpers.collection.Visitor) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Optional(java.util.Optional) IOException(java.io.IOException) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Example 60 with NewIndexDescriptor

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);
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4