Search in sources :

Example 36 with IndexProviderDescriptor

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

the class LuceneFulltextIndexTest method mustNotOverwriteExistingCapabilities.

@Test
void mustNotOverwriteExistingCapabilities() {
    IndexCapability capability = new IndexCapability() {

        @Override
        public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
            return IndexOrderCapability.NONE;
        }

        @Override
        public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
            return IndexValueCapability.NO;
        }
    };
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { 1 }, new int[] { 1 });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor index = IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").materialise(1).withIndexCapability(capability);
    IndexDescriptor completed = indexProvider.completeConfiguration(index);
    assertSame(capability, completed.getCapability());
}
Also used : ValueCategory(org.neo4j.values.storable.ValueCategory) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 37 with IndexProviderDescriptor

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

the class BlockBasedIndexPopulatorTest method setup.

@BeforeEach
void setup() {
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("test", "v1");
    IndexDirectoryStructure directoryStructure = directoriesByProvider(testDir.homePath()).forProvider(providerDescriptor);
    indexFiles = new IndexFiles.Directory(fs, directoryStructure, INDEX_DESCRIPTOR.getId());
    databaseIndexContext = DatabaseIndexContext.builder(pageCache, fs, DEFAULT_DATABASE_NAME).build();
    jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
    populationWorkScheduler = wrapScheduler(jobScheduler);
}
Also used : IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with IndexProviderDescriptor

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

the class BuiltInProcedures method createIndex.

@Deprecated(since = "4.2.0", forRemoval = true)
@Description("Create a named schema index with specified index provider and configuration (optional). " + "Yield: name, labels, properties, providerName, status")
@Procedure(name = "db.createIndex", mode = SCHEMA, deprecatedBy = "CREATE INDEX command")
public Stream<SchemaIndexInfo> createIndex(@Name("indexName") String indexName, @Name("labels") List<String> labels, @Name("properties") List<String> properties, @Name("providerName") String providerName, @Name(value = "config", defaultValue = "{}") Map<String, Object> config) throws ProcedureException {
    IndexProcedures indexProcedures = indexProcedures();
    final IndexProviderDescriptor indexProviderDescriptor = getIndexProviderDescriptor(providerName);
    return indexProcedures.createIndex(indexName, labels, properties, indexProviderDescriptor, config);
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 39 with IndexProviderDescriptor

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

the class IndexingService method start.

// Recovery semantics: This is to be called after init, and after the database has run recovery.
@Override
public void start() throws Exception {
    state = State.STARTING;
    // Recovery will not do refresh (update read views) while applying recovered transactions and instead
    // do it at one point after recovery... i.e. here
    indexMapRef.indexMapSnapshot().forEachIndexProxy(indexProxyOperation("refresh", IndexProxy::refresh));
    final MutableLongObjectMap<IndexDescriptor> rebuildingDescriptors = new LongObjectHashMap<>();
    indexMapRef.modify(indexMap -> {
        Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
        Map<IndexProviderDescriptor, List<IndexLogRecord>> indexProviders = new HashMap<>();
        // Find all indexes that are not already online, do not require rebuilding, and create them
        indexMap.forEachIndexProxy((indexId, proxy) -> {
            InternalIndexState state = proxy.getState();
            IndexDescriptor descriptor = proxy.getDescriptor();
            IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
            IndexLogRecord indexLogRecord = new IndexLogRecord(descriptor);
            indexStates.computeIfAbsent(state, internalIndexState -> new ArrayList<>()).add(indexLogRecord);
            indexProviders.computeIfAbsent(providerDescriptor, indexProviderDescriptor -> new ArrayList<>()).add(indexLogRecord);
            internalLog.debug(indexStateInfo("start", state, descriptor));
            switch(state) {
                case ONLINE:
                case FAILED:
                    proxy.start();
                    break;
                case POPULATING:
                    // Remember for rebuilding right below in this method
                    rebuildingDescriptors.put(indexId, descriptor);
                    break;
                default:
                    throw new IllegalStateException("Unknown state: " + state);
            }
        });
        logIndexStateSummary("start", indexStates);
        logIndexProviderSummary(indexProviders);
        dontRebuildIndexesInReadOnlyMode(rebuildingDescriptors);
        // Drop placeholder proxies for indexes that need to be rebuilt
        dropRecoveringIndexes(indexMap, rebuildingDescriptors.keySet());
        // Rebuild indexes by recreating and repopulating them
        populateIndexesOfAllTypes(rebuildingDescriptors, indexMap);
        return indexMap;
    });
    indexStatisticsStore.start();
    samplingController.recoverIndexSamples();
    samplingController.start();
    // So at this point we've started population of indexes that needs to be rebuilt in the background.
    // Indexes backing uniqueness constraints are normally built within the transaction creating the constraint
    // and so we shouldn't leave such indexes in a populating state after recovery.
    // This is why we now go and wait for those indexes to be fully populated.
    rebuildingDescriptors.forEachKeyValue((indexId, index) -> {
        if (!index.isUnique()) {
            // It's not a uniqueness constraint, so don't wait for it to be rebuilt
            return;
        }
        IndexProxy proxy;
        try {
            proxy = getIndexProxy(index);
        } catch (IndexNotFoundKernelException e) {
            throw new IllegalStateException("What? This index was seen during recovery just now, why isn't it available now?", e);
        }
        if (proxy.getDescriptor().getOwningConstraintId().isEmpty()) {
            // so there's no gain in waiting for this index.
            return;
        }
        monitor.awaitingPopulationOfRecoveredIndex(index);
        awaitOnlineAfterRecovery(proxy);
    });
    state = State.RUNNING;
}
Also used : LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) Arrays(java.util.Arrays) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Log(org.neo4j.logging.Log) CursorContext(org.neo4j.io.pagecache.context.CursorContext) TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LongObjectProcedure(org.eclipse.collections.api.block.procedure.primitive.LongObjectProcedure) UnaryOperator(java.util.function.UnaryOperator) Config(org.neo4j.configuration.Config) Value(org.neo4j.values.storable.Value) Preconditions(org.neo4j.util.Preconditions) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) Map(java.util.Map) LongIterable(org.eclipse.collections.api.LongIterable) PageCacheTracer(org.neo4j.io.pagecache.tracing.PageCacheTracer) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Path(java.nio.file.Path) EnumMap(java.util.EnumMap) SYSTEM(org.neo4j.common.Subject.SYSTEM) Collection(java.util.Collection) Set(java.util.Set) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) EntityType(org.neo4j.common.EntityType) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) FAILED(org.neo4j.internal.kernel.api.InternalIndexState.FAILED) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) DatabaseReadOnlyChecker(org.neo4j.configuration.helpers.DatabaseReadOnlyChecker) NODE(org.neo4j.common.EntityType.NODE) Iterators.asResourceIterator(org.neo4j.internal.helpers.collection.Iterators.asResourceIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexSamplingController(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingController) LogProvider(org.neo4j.logging.LogProvider) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) Iterators.iterator(org.neo4j.internal.helpers.collection.Iterators.iterator) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) ArrayList(java.util.ArrayList) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) ThrowingConsumer(org.neo4j.function.ThrowingConsumer) POPULATING(org.neo4j.internal.kernel.api.InternalIndexState.POPULATING) IndexPopulationFailure.failure(org.neo4j.kernel.impl.api.index.IndexPopulationFailure.failure) ONLINE(org.neo4j.internal.kernel.api.InternalIndexState.ONLINE) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) MemoryTracker(org.neo4j.memory.MemoryTracker) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Subject(org.neo4j.common.Subject) Iterators(org.neo4j.internal.helpers.collection.Iterators) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) IOException(java.io.IOException) IndexActivationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TimeUnit(java.util.concurrent.TimeUnit) KernelException(org.neo4j.exceptions.KernelException) StringJoiner(java.util.StringJoiner) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) SchemaState(org.neo4j.internal.schema.SchemaState) LongSet(org.eclipse.collections.api.set.primitive.LongSet) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) HashMap(java.util.HashMap) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) ArrayList(java.util.ArrayList) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) List(java.util.List) ArrayList(java.util.ArrayList) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) EnumMap(java.util.EnumMap)

Example 40 with IndexProviderDescriptor

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

the class IndexWriterStep method createIndex.

private IndexDescriptor createIndex(EntityType entityType, IndexConfig config, SchemaRuleAccess schemaRule, SchemaStore schemaStore, MemoryTracker memoryTracker, CursorContext cursorContext) {
    try {
        IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("token-lookup", "1.0");
        IndexPrototype prototype = forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(providerDescriptor);
        String name = defaultIfEmpty(config.indexName(entityType), generateName(prototype, new String[] {}, new String[] {}));
        IndexDescriptor descriptor = prototype.withName(name).materialise(schemaStore.nextId(cursorContext));
        schemaRule.writeSchemaRule(descriptor, cursorContext, memoryTracker);
        return descriptor;
    } catch (KernelException e) {
        throw new RuntimeException("Error preparing indexes", e);
    }
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)41 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)18 Test (org.junit.jupiter.api.Test)16 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)11 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)10 ArrayList (java.util.ArrayList)5 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)5 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)4 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)4 Path (java.nio.file.Path)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 String.format (java.lang.String.format)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2