Search in sources :

Example 26 with IndexProxy

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

the class PlainOperationsTest method shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint.

@Test
void shouldAcquireSchemaWriteLockBeforeCreatingUniquenessConstraint() throws Exception {
    // given
    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.schema())).thenReturn(Collections.emptyIterator());
    when(storageReader.indexGetForSchema(schema.schema())).thenReturn(Collections.emptyIterator());
    // when
    operations.uniquePropertyConstraintCreate(prototype);
    // then
    order.verify(locks).acquireExclusive(LockTracer.NONE, ResourceTypes.LABEL, schema.getLabelId());
    order.verify(txState).constraintDoAdd(ConstraintDescriptorFactory.uniqueForSchema(schema), constraintIndex);
}
Also used : 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 27 with IndexProxy

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

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

the class LabelScanNodeViewTracingIT method tracePageCacheAccess.

@Test
void tracePageCacheAccess() throws Exception {
    int nodeCount = 1000;
    var label = Label.label("marker");
    try (var tx = database.beginTx()) {
        for (int i = 0; i < nodeCount; i++) {
            var node = tx.createNode(label);
            node.setProperty("a", randomAscii(10));
        }
        tx.commit();
    }
    var labelId = getLabelId(label);
    var cacheTracer = new DefaultPageCacheTracer();
    IndexProxy indexProxy = indexingService.getIndexProxy(findTokenIndex());
    var scan = new LabelIndexedNodeStoreScan(Config.defaults(), storageEngine.newReader(), lockService, indexProxy.newTokenReader(), new TestTokenScanConsumer(), null, new int[] { labelId }, any -> false, false, jobScheduler, cacheTracer, INSTANCE);
    scan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(cacheTracer.pins()).isEqualTo(3);
    assertThat(cacheTracer.unpins()).isEqualTo(3);
    assertThat(cacheTracer.hits()).isEqualTo(3);
}
Also used : IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) Test(org.junit.jupiter.api.Test)

Example 29 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName.

@Test
void shouldIgnoreExistingOrphanedConstraintIndexWithDifferentName() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    long orphanedConstraintIndexId = 111;
    String orphanedName = "blabla";
    IndexDescriptor orphanedIndex = IndexPrototype.uniqueForSchema(schema).withName(orphanedName).materialise(orphanedConstraintIndexId);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(orphanedIndex)).thenReturn(indexProxy);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(schemaRead.index(schema)).thenReturn(Iterators.iterator(orphanedIndex));
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    when(schemaRead.indexGetForName(orphanedName)).thenReturn(orphanedIndex);
    when(schemaRead.indexGetOwningUniquenessConstraintId(orphanedIndex)).thenReturn(// which means it has no owner
    null);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    // then
    assertEquals(1, kernel.transactions.size());
    verify(schemaRead).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 30 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.

@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
    IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
    IndexDescriptor index = prototype.materialise(this.index.getId());
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    // then
    assertEquals(1, kernel.transactions.size());
    KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
    verify(transactionInstance).indexUniqueCreate(prototype);
    verify(schemaRead).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) 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)

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