Search in sources :

Example 6 with IndexProxy

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

the class MultiIndexPopulationConcurrentUpdatesIT method checkIndexIsOnline.

private void checkIndexIsOnline(int labelId) throws IndexNotFoundKernelException {
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyId);
    IndexDescriptor index = single(schemaCache.indexesForSchema(schema));
    IndexProxy indexProxy = indexService.getIndexProxy(index);
    assertSame(InternalIndexState.ONLINE, indexProxy.getState());
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 7 with IndexProxy

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

the class MultiIndexPopulationConcurrentUpdatesIT method waitIndexOnline.

private void waitIndexOnline(IndexingService indexService, int propertyId, int labelId) throws IndexNotFoundKernelException, IndexPopulationFailedKernelException, InterruptedException, IndexActivationFailedKernelException {
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, propertyId);
    IndexDescriptor index = single(schemaCache.indexesForSchema(schema));
    IndexProxy indexProxy = indexService.getIndexProxy(index);
    indexProxy.awaitStoreScanCompleted(0, TimeUnit.MILLISECONDS);
    while (indexProxy.getState() != InternalIndexState.ONLINE) {
        Thread.sleep(10);
    }
    indexProxy.activate();
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 8 with IndexProxy

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

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnIndexTypeFullText.

@Test
void indexedBackedConstraintCreateMustThrowOnIndexTypeFullText() throws Exception {
    // given
    IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema).withName("constraint name").withIndexProvider(GenericNativeIndexProvider.DESCRIPTOR).withIndexType(IndexType.FULLTEXT);
    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(new InMemoryTokens())).contains("FULLTEXT");
}
Also used : InMemoryTokens(org.neo4j.test.InMemoryTokens) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 9 with IndexProxy

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

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnRelationshipSchemas.

@Test
void indexedBackedConstraintCreateMustThrowOnRelationshipSchemas() throws Exception {
    // given
    when(tokenHolders.relationshipTypeTokens().getTokenById(anyInt())).thenReturn(new NamedToken("RelType", 123));
    when(tokenHolders.propertyKeyTokens().getTokenById(anyInt())).thenReturn(new NamedToken("prop", 456));
    SchemaDescriptor schema = SchemaDescriptor.forRelType(this.schema.getEntityTokenIds()[0], 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("relationship type 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 10 with IndexProxy

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

the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeRemovingIndexRuleBySchema.

@Test
void shouldAcquireSchemaWriteLockBeforeRemovingIndexRuleBySchema() 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.indexGetForSchema(index.schema())).thenReturn(Iterators.iterator(index));
    when(storageReader.indexExists(index)).thenReturn(true);
    // when
    operations.indexDrop(index.schema());
    // 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)

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