Search in sources :

Example 36 with SchemaDescriptor

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

the class SchemaImpl method descriptorToDefinition.

private IndexDefinition descriptorToDefinition(final TokenRead tokenRead, IndexDescriptor index) {
    try {
        SchemaDescriptor schema = index.schema();
        int[] entityTokenIds = schema.getEntityTokenIds();
        boolean constraintIndex = index.isUnique();
        String[] propertyNames = PropertyNameUtils.getPropertyKeysOrThrow(tokenRead, index.schema().getPropertyIds());
        switch(schema.entityType()) {
            case NODE:
                Label[] labels = new Label[entityTokenIds.length];
                for (int i = 0; i < labels.length; i++) {
                    labels[i] = label(tokenRead.nodeLabelName(entityTokenIds[i]));
                }
                return new IndexDefinitionImpl(actions, index, labels, propertyNames, constraintIndex);
            case RELATIONSHIP:
                RelationshipType[] relTypes = new RelationshipType[entityTokenIds.length];
                for (int i = 0; i < relTypes.length; i++) {
                    relTypes[i] = withName(tokenRead.relationshipTypeName(entityTokenIds[i]));
                }
                return new IndexDefinitionImpl(actions, index, relTypes, propertyNames, constraintIndex);
            default:
                throw new IllegalArgumentException("Cannot create IndexDefinition for " + schema.entityType() + " entity-typed schema.");
        }
    } catch (KernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) RelationshipType(org.neo4j.graphdb.RelationshipType) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 37 with SchemaDescriptor

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

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnFulltextSchemas.

@Test
void indexedBackedConstraintCreateMustThrowOnFulltextSchemas() throws Exception {
    // given
    when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
    when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
    SchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, this.schema.getEntityTokenIds(), this.schema.getPropertyIds());
    IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR);
    IndexDescriptor constraintIndex = prototype.materialise(42);
    when(constraintIndexCreator.createUniquenessConstraintIndex(any(), any(), eq(prototype))).thenReturn(constraintIndex);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexProxy.getDescriptor()).thenReturn(constraintIndex);
    when(indexingService.getIndexProxy(constraintIndex)).thenReturn(indexProxy);
    when(storageReader.constraintsGetForSchema(schema)).thenReturn(Collections.emptyIterator());
    when(storageReader.indexGetForSchema(schema)).thenReturn(Collections.emptyIterator());
    // when
    var e = assertThrows(KernelException.class, () -> operations.uniquePropertyConstraintCreate(prototype));
    assertThat(e.getUserMessage(tokenHolders)).contains("full-text schema");
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) NamedToken(org.neo4j.token.api.NamedToken) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 38 with SchemaDescriptor

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

the class IndexTxStateUpdaterTestBase method setUp.

void setUp(List<IndexDescriptor> indexes) throws IndexNotFoundKernelException {
    txState = mock(TransactionState.class);
    when(txState.memoryTracker()).thenReturn(EmptyMemoryTracker.INSTANCE);
    StorageReader storageReader = mock(StorageReader.class);
    when(storageReader.valueIndexesGetRelated(any(), anyInt(), any())).thenAnswer(invocationOnMock -> {
        long[] tokens = invocationOnMock.getArgument(0);
        int propertyKeyId = invocationOnMock.getArgument(1);
        Set<IndexDescriptor> descriptors = new HashSet<>();
        for (IndexDescriptor index : indexes) {
            SchemaDescriptor schema = index.schema();
            if (schema.isAffected(tokens) && contains(schema.getPropertyIds(), propertyKeyId)) {
                if (schema.propertySchemaType() == PropertySchemaType.COMPLETE_ALL_TOKENS) {
                    descriptors.add(index);
                }
            }
        }
        return descriptors;
    });
    when(storageReader.valueIndexesGetRelated(any(), any(int[].class), any())).thenAnswer(invocationOnMock -> {
        long[] tokens = invocationOnMock.getArgument(0);
        int[] propertyKeyIds = invocationOnMock.getArgument(1);
        Set<IndexDescriptor> descriptors = new HashSet<>();
        for (IndexDescriptor index : indexes) {
            if (index.schema().isAffected(tokens)) {
                boolean containsAll = true;
                for (int propertyId : index.schema().getPropertyIds()) {
                    containsAll &= contains(propertyKeyIds, propertyId);
                }
                if (containsAll) {
                    descriptors.add(index);
                }
            }
        }
        return descriptors;
    });
    Read readOps = mock(Read.class);
    when(readOps.txState()).thenReturn(txState);
    IndexingService indexingService = mock(IndexingService.class);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(any(IndexDescriptor.class))).thenReturn(indexProxy);
    indexTxUpdater = new IndexTxStateUpdater(storageReader, readOps, indexingService);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) HashSet(java.util.HashSet)

Example 39 with SchemaDescriptor

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

the class LockVerificationMonitor method assertSchemaLocked.

static void assertSchemaLocked(ResourceLocker locks, SchemaRule schemaRule, AbstractBaseRecord record) {
    if (schemaRule instanceof IndexDescriptor && ((IndexDescriptor) schemaRule).isUnique()) {
        // Current lock abstraction does not let us check if anyone (parent) has those locks so there is nothing we can check here unfortunately
        return;
    }
    Objects.requireNonNull(schemaRule);
    assertLocked(locks, schemaNameResourceId(schemaRule.getName()), SCHEMA_NAME, EXCLUSIVE, record);
    SchemaDescriptor schema = schemaRule.schema();
    for (long key : schema.lockingKeys()) {
        assertLocked(locks, key, schema.keyType(), EXCLUSIVE, record);
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 40 with SchemaDescriptor

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

the class MultipleIndexPopulator method newPopulatingUpdater.

@VisibleForTesting
MultipleIndexUpdater newPopulatingUpdater(NodePropertyAccessor accessor, CursorContext cursorContext) {
    Map<SchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
    forEachPopulation(population -> {
        IndexUpdater updater = population.populator.newPopulatingUpdater(accessor, cursorContext);
        updaters.put(population.schema(), Pair.of(population, updater));
    }, cursorContext);
    return new MultipleIndexUpdater(this, updaters, logProvider, cursorContext);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) HashMap(java.util.HashMap) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) VisibleForTesting(org.neo4j.util.VisibleForTesting)

Aggregations

SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)58 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 Test (org.junit.jupiter.api.Test)18 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)18 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)18 Value (org.neo4j.values.storable.Value)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 ArrayList (java.util.ArrayList)6 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 KernelException (org.neo4j.exceptions.KernelException)4 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)4