Search in sources :

Example 11 with IndexProxy

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

the class PlainOperationsTest method indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas.

@Test
void indexedBackedConstraintCreateMustThrowOnAnyTokenSchemas() throws Exception {
    // given
    SchemaDescriptor schema = SchemaDescriptor.forAnyEntityTokens(NODE);
    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("any token 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) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with IndexProxy

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

the class LookupAccessorsFromRunningDb method apply.

@Override
public IndexAccessor apply(IndexDescriptor indexDescriptor) {
    try {
        IndexProxy proxy = indexingService.getIndexProxy(indexDescriptor);
        while (proxy instanceof AbstractDelegatingIndexProxy) {
            proxy = ((AbstractDelegatingIndexProxy) proxy).getDelegate();
        }
        assertEquals(InternalIndexState.ONLINE, proxy.getState());
        return ((OnlineIndexProxy) proxy).accessor();
    } catch (IndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : OnlineIndexProxy(org.neo4j.kernel.impl.api.index.OnlineIndexProxy) AbstractDelegatingIndexProxy(org.neo4j.kernel.impl.api.index.AbstractDelegatingIndexProxy) AbstractDelegatingIndexProxy(org.neo4j.kernel.impl.api.index.AbstractDelegatingIndexProxy) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) OnlineIndexProxy(org.neo4j.kernel.impl.api.index.OnlineIndexProxy) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)

Example 13 with IndexProxy

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

the class DynamicIndexStoreViewTest method shouldVisitNodesUsingTokenIndex.

@Test
void shouldVisitNodesUsingTokenIndex() throws Exception {
    long[] nodeIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int[] indexedLabels = { 2, 6 };
    StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    StubTokenIndexReader tokenReader = new StubTokenIndexReader();
    IndexDescriptor descriptor = forSchema(forAnyEntityTokens(NODE), DESCRIPTOR).withName("index").materialise(0);
    when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
    when(indexProxy.newTokenReader()).thenReturn(tokenReader);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
    // Nodes indexed by label
    for (long nodeId : nodeIds) {
        cursors.withNode(nodeId).propertyId(1).relationship(1).labels(2, 6);
        tokenReader.index(indexedLabels, nodeId);
    }
    // Nodes not indexed
    cursors.withNode(9).labels(5);
    cursors.withNode(10).labels(6);
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer consumer = new TestTokenScanConsumer();
    StoreScan storeScan = storeView.visitNodes(indexedLabels, Predicates.ALWAYS_TRUE_INT, new TestPropertyScanConsumer(), consumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(consumer.batches.size()).isEqualTo(1);
    assertThat(consumer.batches.get(0).size()).isEqualTo(nodeIds.length);
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 14 with IndexProxy

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

the class CheckerTestBase method labelIndexWriter.

IndexUpdater labelIndexWriter() {
    IndexingService indexingService = db.getDependencyResolver().resolveDependency(IndexingService.class);
    final IndexDescriptor[] indexDescriptors = schemaStorage.indexGetForSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE), CursorContext.NULL);
    // The Node Label Index should exist and be unique.
    assertThat(indexDescriptors.length).isEqualTo(1);
    IndexDescriptor nli = indexDescriptors[0];
    IndexProxy indexProxy;
    try {
        indexProxy = indexingService.getIndexProxy(nli);
    } catch (IndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
    return indexProxy.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 15 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.

@Test
void shouldCreateIndexInAnotherTransaction() throws Exception {
    // given
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexingService indexingService = mock(IndexingService.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(indexProxy.getDescriptor()).thenReturn(index);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    // when
    IndexDescriptor constraintIndex = creator.createUniquenessConstraintIndex(createTransaction(), constraint, prototype);
    // then
    assertEquals(INDEX_ID, constraintIndex.getId());
    verify(schemaRead).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
    verify(indexProxy).awaitStoreScanCompleted(anyLong(), any());
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) 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