Search in sources :

Example 1 with ConstraintIndexCreator

use of org.neo4j.kernel.impl.api.state.ConstraintIndexCreator in project neo4j by neo4j.

the class NeoStoreDataSource method buildKernel.

private NeoStoreKernelModule buildKernel(TransactionAppender appender, IndexingService indexingService, StoreReadLayer storeLayer, UpdateableSchemaState updateableSchemaState, LabelScanStore labelScanStore, StorageEngine storageEngine, IndexConfigStore indexConfigStore, TransactionIdStore transactionIdStore, AvailabilityGuard availabilityGuard, Clock clock, PropertyAccessor propertyAccessor) throws KernelException, IOException {
    TransactionCommitProcess transactionCommitProcess = commitProcessFactory.create(appender, storageEngine, config);
    /*
         * This is used by legacy indexes and constraint indexes whenever a transaction is to be spawned
         * from within an existing transaction. It smells, and we should look over alternatives when time permits.
         */
    Supplier<KernelAPI> kernelProvider = () -> kernelModule.kernelAPI();
    boolean releaseSchemaLockWhenBuildingConstratinIndexes = config.get(GraphDatabaseSettings.release_schema_lock_while_building_constraint);
    ConstraintIndexCreator constraintIndexCreator = new ConstraintIndexCreator(kernelProvider, indexingService, propertyAccessor, releaseSchemaLockWhenBuildingConstratinIndexes);
    LegacyIndexStore legacyIndexStore = new LegacyIndexStore(config, indexConfigStore, kernelProvider, legacyIndexProviderLookup);
    StatementOperationContainer statementOperationContainer = dependencies.satisfyDependency(buildStatementOperations(storeLayer, autoIndexing, constraintIndexCreator, updateableSchemaState, guard, legacyIndexStore));
    TransactionHooks hooks = new TransactionHooks();
    KernelTransactions kernelTransactions = life.add(new KernelTransactions(statementLocksFactory, constraintIndexCreator, statementOperationContainer, schemaWriteGuard, transactionHeaderInformationFactory, transactionCommitProcess, indexConfigStore, legacyIndexProviderLookup, hooks, transactionMonitor, availabilityGuard, tracers, storageEngine, procedures, transactionIdStore, clock, accessCapability));
    final Kernel kernel = new Kernel(kernelTransactions, hooks, databaseHealth, transactionMonitor, procedures, config);
    kernel.registerTransactionHook(transactionEventHandlers);
    final NeoStoreFileListing fileListing = new NeoStoreFileListing(storeDir, labelScanStore, indexingService, legacyIndexProviderLookup, storageEngine);
    return new NeoStoreKernelModule(transactionCommitProcess, kernel, kernelTransactions, fileListing);
}
Also used : NeoStoreFileListing(org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) LegacyIndexStore(org.neo4j.kernel.impl.index.LegacyIndexStore) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionHooks(org.neo4j.kernel.impl.api.TransactionHooks) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) KernelAPI(org.neo4j.kernel.api.KernelAPI) Kernel(org.neo4j.kernel.impl.api.Kernel)

Example 2 with ConstraintIndexCreator

use of org.neo4j.kernel.impl.api.state.ConstraintIndexCreator in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.

@Test
public void shouldCreateIndexInAnotherTransaction() throws Exception {
    // given
    StatementOperationParts constraintCreationContext = mockedParts();
    StatementOperationParts indexCreationContext = mockedParts();
    KernelStatement state = mockedState();
    IndexingService indexingService = mock(IndexingService.class);
    StubKernel kernel = new StubKernel();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    long indexId = creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
    // then
    assertEquals(2468L, indexId);
    assertEquals(1, kernel.statements.size());
    verify(kernel.statements.get(0).txState()).indexRuleDoAdd(eq(index));
    verifyNoMoreInteractions(indexCreationContext.schemaWriteOperations());
    verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
    verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
    verify(indexProxy).awaitStoreScanCompleted();
}
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 3 with ConstraintIndexCreator

use of org.neo4j.kernel.impl.api.state.ConstraintIndexCreator in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.

@Test
public void shouldDropIndexIfPopulationFails() throws Exception {
    // given
    StatementOperationParts constraintCreationContext = mockedParts();
    KernelStatement state = mockedState();
    IndexingService indexingService = mock(IndexingService.class);
    StubKernel kernel = new StubKernel();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
    IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, "a");
    doThrow(new IndexPopulationFailedKernelException(SchemaBoundary.map(descriptor), "some index", cause)).when(indexProxy).awaitStoreScanCompleted();
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    try {
        creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
        fail("expected exception");
    }// then
     catch (UniquePropertyValueValidationException e) {
        assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) ASSERT label[123].property[456] IS UNIQUE.", e.getMessage());
    }
    assertEquals(2, kernel.statements.size());
    TransactionState tx1 = kernel.statements.get(0).txState();
    NewIndexDescriptor newIndex = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
    verify(tx1).indexRuleDoAdd(newIndex);
    verifyNoMoreInteractions(tx1);
    verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
    verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
    TransactionState tx2 = kernel.statements.get(1).txState();
    verify(tx2).indexDoDrop(newIndex);
    verifyNoMoreInteractions(tx2);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Test(org.junit.Test)

Example 4 with ConstraintIndexCreator

use of org.neo4j.kernel.impl.api.state.ConstraintIndexCreator in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldDropIndexInAnotherTransaction.

@Test
public void shouldDropIndexInAnotherTransaction() throws Exception {
    // given
    StubKernel kernel = new StubKernel();
    IndexingService indexingService = mock(IndexingService.class);
    NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    creator.dropUniquenessConstraintIndex(index);
    // then
    assertEquals(1, kernel.statements.size());
    verify(kernel.statements.get(0).txState()).indexDoDrop(index);
    verifyZeroInteractions(indexingService);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Test(org.junit.Test)

Example 5 with ConstraintIndexCreator

use of org.neo4j.kernel.impl.api.state.ConstraintIndexCreator in project neo4j by neo4j.

the class IndexIT method shouldRemoveAConstraintIndexWithoutOwnerInRecovery.

@Test
public void shouldRemoveAConstraintIndexWithoutOwnerInRecovery() throws Exception {
    // given
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    creator.createConstraintIndex(SchemaBoundary.map(descriptor));
    // when
    restartDb();
    // then
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(readOperations.indexesGetForLabel(labelId)));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)6 Test (org.junit.Test)5 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)5 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StatementOperationParts (org.neo4j.kernel.impl.api.StatementOperationParts)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 KernelAPI (org.neo4j.kernel.api.KernelAPI)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)1 IndexPopulationFailedKernelException (org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException)1 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)1 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)1 Kernel (org.neo4j.kernel.impl.api.Kernel)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 StatementOperationContainer (org.neo4j.kernel.impl.api.StatementOperationContainer)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 TransactionHooks (org.neo4j.kernel.impl.api.TransactionHooks)1 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)1