Search in sources :

Example 71 with ConstraintDescriptor

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

the class AllStoreHolder method constraintGetForName.

ConstraintDescriptor constraintGetForName(StorageSchemaReader reader, String name) {
    ktx.assertOpen();
    ConstraintDescriptor constraint = reader.constraintGetForName(name);
    if (ktx.hasTxStateWithChanges()) {
        Predicate<ConstraintDescriptor> namePredicate = constraintDescriptor -> constraintDescriptor.getName().equals(name);
        Iterator<ConstraintDescriptor> constraints = ktx.txState().constraintsChanges().filterAdded(namePredicate).apply(Iterators.iterator(constraint));
        constraint = singleOrNull(constraints);
    }
    return lockConstraint(constraint);
}
Also used : ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) CursorContext(org.neo4j.io.pagecache.context.CursorContext) EMPTY(org.neo4j.storageengine.api.txstate.TxStateVisitor.EMPTY) ResourceTypes(org.neo4j.lock.ResourceTypes) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Value(org.neo4j.values.storable.Value) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Statement(org.neo4j.kernel.api.Statement) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenReadSession(org.neo4j.internal.kernel.api.TokenReadSession) IndexStatisticsStore(org.neo4j.kernel.impl.api.index.stats.IndexStatisticsStore) AdminAccessMode(org.neo4j.internal.kernel.api.security.AdminAccessMode) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) SecurityContext(org.neo4j.internal.kernel.api.security.SecurityContext) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) Dependencies(org.neo4j.collection.Dependencies) Predicate(java.util.function.Predicate) Set(java.util.Set) String.format(java.lang.String.format) UserFunctionHandle(org.neo4j.internal.kernel.api.procs.UserFunctionHandle) Objects(java.util.Objects) AccessMode(org.neo4j.internal.kernel.api.security.AccessMode) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) Stream(java.util.stream.Stream) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) EntityType(org.neo4j.common.EntityType) RelationshipScanCursor(org.neo4j.internal.kernel.api.RelationshipScanCursor) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) AnyValue(org.neo4j.values.AnyValue) RawIterator(org.neo4j.collection.RawIterator) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) RestrictedAccessMode(org.neo4j.kernel.impl.api.security.RestrictedAccessMode) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) TokenRead(org.neo4j.internal.kernel.api.TokenRead) Function(java.util.function.Function) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) Iterators.singleOrNull(org.neo4j.internal.helpers.collection.Iterators.singleOrNull) DefaultValueMapper(org.neo4j.kernel.impl.util.DefaultValueMapper) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) IndexReaderCache(org.neo4j.kernel.impl.api.IndexReaderCache) UserAggregator(org.neo4j.internal.kernel.api.procs.UserAggregator) StorageReader(org.neo4j.storageengine.api.StorageReader) MemoryTracker(org.neo4j.memory.MemoryTracker) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexSample(org.neo4j.kernel.api.index.IndexSample) Iterator(java.util.Iterator) Iterators(org.neo4j.internal.helpers.collection.Iterators) DiffSets(org.neo4j.storageengine.api.txstate.DiffSets) OverriddenAccessMode(org.neo4j.kernel.impl.api.security.OverriddenAccessMode) BasicContext.buildContext(org.neo4j.kernel.api.procedure.BasicContext.buildContext) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) Context(org.neo4j.kernel.api.procedure.Context) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor) ProcedureHandle(org.neo4j.internal.kernel.api.procs.ProcedureHandle) TokenIndexReader(org.neo4j.kernel.api.index.TokenIndexReader) StorageSchemaReader(org.neo4j.storageengine.api.StorageSchemaReader) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) SchemaState(org.neo4j.internal.schema.SchemaState) Collections(java.util.Collections) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor)

Example 72 with ConstraintDescriptor

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

the class PlainOperationsTest method shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot.

@Test
void shouldNotAcquireSchemaReadLockLazilyBeforeGettingAllConstraintsFromSnapshot() {
    // given
    int labelId = 1;
    int relTypeId = 2;
    UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
    RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
    when(storageReaderSnapshot.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
    // when
    Iterator<ConstraintDescriptor> result = allStoreHolder.snapshot().constraintsGetAll();
    // then
    assertThat(Iterators.count(result)).isEqualTo(2L);
    assertThat(asList(result)).isEmpty();
    verify(storageReaderSnapshot).constraintsGetAll();
    verifyNoMoreInteractions(locks);
}
Also used : RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 73 with ConstraintDescriptor

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

the class PlainOperationsTest method shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints.

@Test
void shouldAcquireSchemaReadLockLazilyBeforeGettingAllConstraints() {
    // given
    int labelId = 1;
    int relTypeId = 2;
    UniquenessConstraintDescriptor uniquenessConstraint = uniqueForLabel(labelId, 2, 3, 3);
    RelExistenceConstraintDescriptor existenceConstraint = existsForRelType(relTypeId, 3, 4, 5);
    when(storageReader.constraintsGetAll()).thenReturn(Iterators.iterator(uniquenessConstraint, existenceConstraint));
    when(storageReader.constraintExists(uniquenessConstraint)).thenReturn(true);
    when(storageReader.constraintExists(existenceConstraint)).thenReturn(true);
    // when
    Iterator<ConstraintDescriptor> result = allStoreHolder.constraintsGetAll();
    // then
    assertThat(Iterators.count(result)).isEqualTo(2L);
    assertThat(asList(result)).isEmpty();
    order.verify(storageReader).constraintsGetAll();
    order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.LABEL, labelId);
    order.verify(locks, atLeastOnce()).acquireShared(LockTracer.NONE, ResourceTypes.RELATIONSHIP_TYPE, relTypeId);
}
Also used : RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.RelExistenceConstraintDescriptor) NodeKeyConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.internal.schema.constraints.NodeExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexBackedConstraintDescriptor(org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 74 with ConstraintDescriptor

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

the class KernelSchemaStateFlushingTest method createConstraint.

private ConstraintDescriptor createConstraint() throws KernelException {
    try (KernelTransaction transaction = beginTransaction()) {
        ConstraintDescriptor descriptor = transaction.schemaWrite().uniquePropertyConstraintCreate(IndexPrototype.uniqueForSchema(SchemaDescriptor.forLabel(labelId, propId)));
        transaction.commit();
        return descriptor;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor)

Example 75 with ConstraintDescriptor

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

the class RecordStorageReaderSchemaTest method shouldListAllConstraintsAtTimeOfSnapshot.

@Test
void shouldListAllConstraintsAtTimeOfSnapshot() throws Exception {
    // Given
    createUniquenessConstraint(label1, propertyKey);
    // When
    StorageSchemaReader snapshot = storageReader.schemaSnapshot();
    createUniquenessConstraint(label2, propertyKey);
    Set<ConstraintDescriptor> constraints = asSet(snapshot.constraintsGetAll());
    // Then
    Set<ConstraintDescriptor> expectedConstraints = asSet(uniqueConstraintDescriptor(label1, propertyKey));
    assertEquals(expectedConstraints, constraints);
}
Also used : StorageSchemaReader(org.neo4j.storageengine.api.StorageSchemaReader) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)107 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)34 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)32 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)21 NodeKeyConstraintDescriptor (org.neo4j.internal.schema.constraints.NodeKeyConstraintDescriptor)20 IndexBackedConstraintDescriptor (org.neo4j.internal.schema.constraints.IndexBackedConstraintDescriptor)19 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)16 TokenRead (org.neo4j.internal.kernel.api.TokenRead)9 ArrayList (java.util.ArrayList)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)6 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)6 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)5 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)5 SchemaRule (org.neo4j.internal.schema.SchemaRule)5 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)5 OptionalLong (java.util.OptionalLong)4