Search in sources :

Example 16 with IndexProxy

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

the class ConstraintIndexCreatorTest method logMessagesAboutConstraintCreation.

@Test
void logMessagesAboutConstraintCreation() throws SchemaKernelException, UniquePropertyValueValidationException, TransactionFailureException, IndexNotFoundKernelException {
    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);
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    String constraintString = constraint.userDescription(tokenRead);
    assertThat(logProvider).containsMessages(format("Starting constraint creation: %s.", constraintString), format("Constraint %s populated, starting verification.", constraintString), format("Constraint %s verified.", constraintString));
}
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) Test(org.junit.jupiter.api.Test)

Example 17 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldReleaseLabelLockWhileAwaitingIndexPopulation.

@Test
void shouldReleaseLabelLockWhileAwaitingIndexPopulation() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(schemaRead.index(schema)).thenReturn(Iterators.emptyResourceIterator());
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    // then
    verify(transaction.lockClient()).releaseExclusive(ResourceTypes.LABEL, schema.getLabelId());
    verify(transaction.lockClient()).acquireExclusive(transaction.lockTracer(), ResourceTypes.LABEL, schema.getLabelId());
}
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) Test(org.junit.jupiter.api.Test)

Example 18 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.

@Test
void shouldDropIndexIfPopulationFails() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    when(indexProxy.getDescriptor()).thenReturn(index);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX, index);
    IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));
    doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
    when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(// first claim it doesn't exist, because it doesn't... so
    Iterators.emptyResourceIterator()).thenReturn(// then after it failed claim it does exist
    Iterators.iterator(index));
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    UniquePropertyValueValidationException exception = assertThrows(UniquePropertyValueValidationException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
    assertEquals("Existing data does not satisfy Constraint( name='constraint', type='UNIQUENESS', schema=(:Label {prop}) ): " + "Both node 2 and node 1 share the property value ( String(\"a\") )", exception.getMessage());
    assertEquals(2, kernel.transactions.size());
    KernelTransactionImplementation tx1 = kernel.transactions.get(0);
    verify(tx1).indexUniqueCreate(prototype);
    verify(schemaRead, times(2)).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
    KernelTransactionImplementation kti2 = kernel.transactions.get(1);
    verify(kti2).addIndexDoDropToTxState(index);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Test(org.junit.jupiter.api.Test)

Example 19 with IndexProxy

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

the class ConstraintIndexCreatorTest method shouldThrowOnExistingOrphanedConstraintIndexWithSameName.

@Test
void shouldThrowOnExistingOrphanedConstraintIndexWithSameName() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    long orphanedConstraintIndexId = 111;
    String orphanedName = "constraint";
    IndexDescriptor orphanedIndex = IndexPrototype.uniqueForSchema(schema).withName(orphanedName).materialise(orphanedConstraintIndexId);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(orphanedIndex)).thenReturn(indexProxy);
    when(schemaRead.index(schema)).thenReturn(Iterators.iterator(orphanedIndex));
    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();
    assertThrows(AlreadyConstrainedException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
    // then
    assertEquals(0, kernel.transactions.size(), "There should have been no need to acquire a statement to create the constraint index");
    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 20 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 {
    IndexProxy indexProxy = indexService.getIndexProxy(SchemaDescriptorFactory.forLabel(labelId, propertyId));
    indexProxy.awaitStoreScanCompleted();
    indexProxy.activate();
}
Also used : IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy)

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