Search in sources :

Example 21 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldReleaseSchemaLockWhileAwaitingIndexPopulation.

@Test
public void shouldReleaseSchemaLockWhileAwaitingIndexPopulation() throws Exception {
    // given
    StubKernel kernel = new StubKernel();
    IndexingService indexingService = mock(IndexingService.class);
    StatementOperationParts constraintCreationContext = mockedParts();
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    KernelStatement state = mockedState();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, true);
    // when
    creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), index.schema());
    // then
    verify(state.locks().pessimistic()).releaseExclusive(ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
    verify(state.locks().pessimistic()).acquireExclusive(state.lockTracer(), ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) Test(org.junit.Test)

Example 22 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeRemovingIndexRule.

@Test
void shouldAcquireSchemaWriteLockBeforeRemovingIndexRule() throws Exception {
    // given
    IndexDescriptor index = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 0)).withName("index").materialise(0);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexProxy.getDescriptor()).thenReturn(index);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(storageReader.indexExists(index)).thenReturn(true);
    // when
    operations.indexDrop(index);
    // then
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, 0);
    order.verify(txState).indexDoDrop(index);
}
Also used : IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 23 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class PlainOperationsTest method shouldAcquireSchemaNameWriteLockBeforeRemovingIndexByName.

@Test
void shouldAcquireSchemaNameWriteLockBeforeRemovingIndexByName() throws Exception {
    // given
    String indexName = "My fancy index";
    IndexDescriptor index = IndexPrototype.forSchema(SchemaDescriptor.forLabel(0, 0)).withName(indexName).materialise(0);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexProxy.getDescriptor()).thenReturn(index);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(storageReader.indexGetForName(indexName)).thenReturn(index);
    when(storageReader.indexExists(index)).thenReturn(true);
    // when
    operations.indexDrop(indexName);
    // then
    long indexNameLock = ResourceIds.schemaNameResourceId(indexName);
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.SCHEMA_NAME, indexNameLock);
    order.verify(txState).indexDoDrop(index);
}
Also used : IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 24 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy 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 25 with IndexProxy

use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnNonUniqueIndexPrototypes.

@Test
void indexedBackedConstraintCreateMustThrowOnNonUniqueIndexPrototypes() throws Exception {
    // given
    when(tokenHolders.labelTokens().getTokenById(anyInt())).thenReturn(new NamedToken("Label", 123));
    when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
    IndexPrototype prototype = IndexPrototype.forSchema(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)).containsIgnoringCase("index prototype").containsIgnoringCase("not unique");
}
Also used : 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)

Aggregations

IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)33 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 Test (org.junit.jupiter.api.Test)21 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)15 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)8 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)4 Transaction (org.neo4j.graphdb.Transaction)3 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)3 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)3 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Node (org.neo4j.graphdb.Node)2 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)2 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)2 IndexPopulationFailedKernelException (org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException)2 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 IndexProxyProvider (org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider)2