Search in sources :

Example 1 with IndexProviderDescriptor

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

the class LuceneFulltextIndexTest method completeConfigurationMustNotOverwriteExistingConfiguration.

@Test
void completeConfigurationMustNotOverwriteExistingConfiguration() {
    IndexConfig indexConfig = IndexConfig.with("A", Values.stringValue("B"));
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { 1 }, new int[] { 1 });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").materialise(1)).withIndexConfig(indexConfig);
    assertEquals(Values.stringValue("B"), descriptor.getIndexConfig().get("A"));
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) 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 2 with IndexProviderDescriptor

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

the class LuceneFulltextIndexTest method completeConfigurationMustInjectMissingConfigurations.

@Test
void completeConfigurationMustInjectMissingConfigurations() throws Exception {
    int label;
    int propertyKey;
    try (Transaction tx = db.beginTx()) {
        createNodeIndexableByPropertyValue(tx, LABEL, "bla");
        tx.commit();
    }
    try (KernelTransactionImplementation tx = getKernelTransaction()) {
        label = tx.tokenRead().nodeLabel(LABEL.name());
        propertyKey = tx.tokenRead().propertyKey(PROP);
        tx.success();
    }
    IndexConfig indexConfig = IndexConfig.with(EVENTUALLY_CONSISTENT, Values.booleanValue(true));
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { label }, new int[] { propertyKey });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").withIndexConfig(indexConfig).materialise(1));
    assertThat((Value) descriptor.getIndexConfig().get(ANALYZER)).isEqualTo(Values.stringValue("standard-no-stop-words"));
    assertThat((Value) descriptor.getIndexConfig().get(EVENTUALLY_CONSISTENT)).isEqualTo(Values.booleanValue(true));
    assertThat(asList(descriptor.getCapability().behaviours())).containsExactlyInAnyOrder(IndexBehaviour.EVENTUALLY_CONSISTENT, IndexBehaviour.SKIP_AND_LIMIT);
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Value(org.neo4j.values.storable.Value) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexProviderDescriptor

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

the class Operations method ensureIndexPrototypeHasIndexProvider.

private IndexPrototype ensureIndexPrototypeHasIndexProvider(IndexPrototype prototype) {
    if (prototype.getIndexProvider() == IndexProviderDescriptor.UNDECIDED) {
        IndexProviderDescriptor provider;
        if (prototype.getIndexType() == IndexType.FULLTEXT) {
            provider = indexProviders.getFulltextProvider();
        } else if (prototype.getIndexType() == IndexType.LOOKUP) {
            provider = indexProviders.getTokenIndexProvider();
        } else {
            provider = indexProviders.getDefaultProvider();
        }
        prototype = prototype.withIndexProvider(provider);
    }
    return prototype;
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor)

Example 4 with IndexProviderDescriptor

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

the class GenericBlockBasedIndexPopulatorTest method setup.

@BeforeEach
void setup() {
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("test", "v1");
    IndexDirectoryStructure directoryStructure = directoriesByProvider(directory.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 = new IndexPopulator.PopulationWorkScheduler() {

        @Override
        public <T> JobHandle<T> schedule(IndexPopulator.JobDescriptionSupplier descriptionSupplier, Callable<T> job) {
            return jobScheduler.schedule(Group.INDEX_POPULATION_WORK, new JobMonitoringParams(null, null, null), job);
        }
    };
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) JobHandle(org.neo4j.scheduler.JobHandle) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with IndexProviderDescriptor

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

the class IndexingService method init.

/**
 * Called while the database starts up, before recovery.
 */
@Override
public void init() throws IOException {
    validateDefaultProviderExisting();
    try (var cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer(INIT_TAG))) {
        indexMapRef.modify(indexMap -> {
            Map<InternalIndexState, List<IndexLogRecord>> indexStates = new EnumMap<>(InternalIndexState.class);
            for (IndexDescriptor descriptor : indexDescriptors) {
                // No index (except NLI) is allowed to have the name generated for NLI.
                if (descriptor.getName().equals(IndexDescriptor.NLI_GENERATED_NAME) && !(descriptor.schema().isAnyTokenSchemaDescriptor() && descriptor.schema().entityType() == NODE)) {
                    throw new IllegalStateException("Index '" + descriptor.userDescription(tokenNameLookup) + "' is using a reserved name: '" + IndexDescriptor.NLI_GENERATED_NAME + "'. This index must be removed on an earlier version " + "to be able to use binaries for version 4.3 or newer.");
                }
                IndexProxy indexProxy;
                IndexProviderDescriptor providerDescriptor = descriptor.getIndexProvider();
                IndexProvider provider = providerMap.lookup(providerDescriptor);
                InternalIndexState initialState = provider.getInitialState(descriptor, cursorContext);
                indexStates.computeIfAbsent(initialState, internalIndexState -> new ArrayList<>()).add(new IndexLogRecord(descriptor));
                internalLog.debug(indexStateInfo("init", initialState, descriptor));
                switch(initialState) {
                    case ONLINE:
                        monitor.initialState(databaseName, descriptor, ONLINE);
                        indexProxy = indexProxyCreator.createOnlineIndexProxy(descriptor);
                        break;
                    case POPULATING:
                        // The database was shut down during population, or a crash has occurred, or some other sad thing.
                        monitor.initialState(databaseName, descriptor, POPULATING);
                        indexProxy = indexProxyCreator.createRecoveringIndexProxy(descriptor);
                        break;
                    case FAILED:
                        monitor.initialState(databaseName, descriptor, FAILED);
                        IndexPopulationFailure failure = failure(provider.getPopulationFailure(descriptor, cursorContext));
                        indexProxy = indexProxyCreator.createFailedIndexProxy(descriptor, failure);
                        break;
                    default:
                        throw new IllegalArgumentException("" + initialState);
                }
                indexMap.putIndexProxy(indexProxy);
            }
            logIndexStateSummary("init", indexStates);
            return indexMap;
        });
    }
    indexStatisticsStore.init();
}
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) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) 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)

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