Search in sources :

Example 51 with IndexDescriptor

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

the class RecordStorageReaderSchemaTest method shouldListAllIndexes.

@Test
void shouldListAllIndexes() throws Exception {
    // Given
    IndexDescriptor firstExpectedIndex = createIndex(label1, propertyKey);
    IndexDescriptor secondExpectedIndex = createIndex(label2, propertyKey);
    // When
    Set<IndexDescriptor> indexes = asSet(storageReader.indexesGetAll());
    // Then
    Set<IndexDescriptor> expectedIndexes = asSet(firstExpectedIndex, secondExpectedIndex);
    assertEquals(expectedIndexes, indexes);
}
Also used : IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 52 with IndexDescriptor

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

the class RecordStorageReaderTestBase method createUniqueIndex.

private IndexDescriptor createUniqueIndex(Label label, String propertyKey) throws Exception {
    TxState txState = new TxState();
    int labelId = getOrCreateLabelId(label);
    int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
    long id = commitContext.reserveSchema();
    IndexDescriptor index = IndexPrototype.uniqueForSchema(forLabel(labelId, propertyKeyId)).withName("constraint_" + id).materialise(id);
    txState.indexDoAdd(index);
    apply(txState);
    return index;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 53 with IndexDescriptor

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

the class RecordStorageReaderTestBase method createIndex.

protected IndexDescriptor createIndex(Label label, String propertyKey) throws Exception {
    TxState txState = new TxState();
    int labelId = getOrCreateLabelId(label);
    int propertyKeyId = getOrCreatePropertyKeyId(propertyKey);
    long id = commitContext.reserveSchema();
    IndexPrototype prototype = IndexPrototype.forSchema(forLabel(labelId, propertyKeyId)).withName("index_" + id);
    IndexDescriptor index = prototype.materialise(id);
    txState.indexDoAdd(index);
    apply(txState);
    return index;
}
Also used : TxState(org.neo4j.kernel.impl.api.state.TxState) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 54 with IndexDescriptor

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

the class IndexingService method filterOutAndHandleInjectedTokenIndex.

/**
 * Once upon a time there was something called label scan store.
 * In essence, it was a btree used for indexing nodes, but it was not managed like other indexes.
 * Most importantly, it did not have a record in the schema store.
 * In 4.3, the label scan store was turned into a proper index referred to as node label index
 * and got a corresponding record in a schema store.
 * However, during a rolling upgrade until the cluster is fully upgraded to a version >= 4.3,
 * a former label scan store behaves like a node label index, but does not have a record in schema store.
 * We call such node label index as "injected".
 * During an upgrade, a record in a schema store is created for the injected node label index.
 * The purpose of this code is to catch the event when a new index descriptor for the injected node label index
 * is submitted, filter it from the list of to-be-created indexes and swap the old descriptor on
 * the injected node label index with the newly submitted descriptor.
 * In other words, adding identity to an injected index is the only and very special case when
 * {@link #createIndexes} is called with a descriptor for an already existing index
 * and such operation needs to cause the index being linked to the new descriptor instead of
 * a new index being created and because we effectively "remove" the old injected index and replace
 * with the new we also need to clear the schema state.
 * Of course it would be much simpler to close the injected index and create a new one with the new identity.
 * The reason why the elaborate migration was introduced is not to interrupt any ongoing operations
 * against the index by keeping the file/accessor of the injected label index open.
 */
private IndexDescriptor[] filterOutAndHandleInjectedTokenIndex(IndexDescriptor[] rules) {
    IndexProxy nli = indexMapRef.indexMapSnapshot().getIndexProxy(IndexDescriptor.INJECTED_NLI_ID);
    if (nli == null) {
        return rules;
    }
    List<IndexDescriptor> filteredRules = new ArrayList<>();
    for (IndexDescriptor rule : rules) {
        if (rule.schema().isAnyTokenSchemaDescriptor() && rule.schema().entityType() == NODE) {
            nli.changeIdentity(rule);
            indexMapRef.modify(indexMap -> {
                indexMap.putIndexProxy(nli);
                indexMap.removeIndexProxy(IndexDescriptor.INJECTED_NLI_ID);
                return indexMap;
            });
            schemaState.clear();
        } else {
            filteredRules.add(rule);
        }
    }
    return filteredRules.toArray(IndexDescriptor[]::new);
}
Also used : ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 55 with IndexDescriptor

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

the class IndexingService method populateIndexesOfAllTypes.

private void populateIndexesOfAllTypes(MutableLongObjectMap<IndexDescriptor> rebuildingDescriptors, IndexMap indexMap) {
    Map<EntityType, MutableLongObjectMap<IndexDescriptor>> rebuildingDescriptorsByType = new EnumMap<>(EntityType.class);
    for (IndexDescriptor descriptor : rebuildingDescriptors) {
        rebuildingDescriptorsByType.computeIfAbsent(descriptor.schema().entityType(), type -> new LongObjectHashMap<>()).put(descriptor.getId(), descriptor);
    }
    for (Map.Entry<EntityType, MutableLongObjectMap<IndexDescriptor>> descriptorToPopulate : rebuildingDescriptorsByType.entrySet()) {
        IndexPopulationJob populationJob = newIndexPopulationJob(descriptorToPopulate.getKey(), false, SYSTEM);
        populate(descriptorToPopulate.getValue(), indexMap, populationJob);
    }
}
Also used : EntityType(org.neo4j.common.EntityType) 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) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) MutableLongObjectMap(org.eclipse.collections.api.map.primitive.MutableLongObjectMap) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)

Aggregations

IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)404 Test (org.junit.jupiter.api.Test)231 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)81 Value (org.neo4j.values.storable.Value)43 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)33 ArrayList (java.util.ArrayList)31 Transaction (org.neo4j.graphdb.Transaction)31 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)31 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)30 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)30 TokenRead (org.neo4j.internal.kernel.api.TokenRead)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)26 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)25 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)23 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)23 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)22 KernelException (org.neo4j.exceptions.KernelException)20