Search in sources :

Example 1 with StatementOperationParts

use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.

the class NeoStoreDataSource method buildStatementOperations.

private StatementOperationContainer buildStatementOperations(StoreReadLayer storeReadLayer, AutoIndexing autoIndexing, ConstraintIndexCreator constraintIndexCreator, UpdateableSchemaState updateableSchemaState, Guard guard, LegacyIndexStore legacyIndexStore) {
    // The passed in StoreReadLayer is the bottom most layer: Read-access to committed data.
    // To it we add:
    // + Transaction state handling
    StateHandlingStatementOperations stateHandlingContext = new StateHandlingStatementOperations(storeReadLayer, autoIndexing, constraintIndexCreator, legacyIndexStore);
    QueryRegistrationOperations queryRegistrationOperations = new StackingQueryRegistrationOperations(clock);
    StatementOperationParts parts = new StatementOperationParts(stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, stateHandlingContext, new SchemaStateConcern(updateableSchemaState), null, stateHandlingContext, stateHandlingContext, stateHandlingContext, queryRegistrationOperations);
    // + Constraints
    ConstraintEnforcingEntityOperations constraintEnforcingEntityOperations = new ConstraintEnforcingEntityOperations(constraintSemantics, parts.entityWriteOperations(), parts.entityReadOperations(), parts.schemaWriteOperations(), parts.schemaReadOperations());
    // + Data integrity
    DataIntegrityValidatingStatementOperations dataIntegrityContext = new DataIntegrityValidatingStatementOperations(parts.keyWriteOperations(), parts.schemaReadOperations(), constraintEnforcingEntityOperations);
    parts = parts.override(null, dataIntegrityContext, constraintEnforcingEntityOperations, constraintEnforcingEntityOperations, null, dataIntegrityContext, null, null, null, null, null, null);
    // + Locking
    LockingStatementOperations lockingContext = new LockingStatementOperations(parts.entityReadOperations(), parts.entityWriteOperations(), parts.schemaReadOperations(), parts.schemaWriteOperations(), parts.schemaStateOperations());
    parts = parts.override(null, null, null, lockingContext, lockingContext, lockingContext, lockingContext, lockingContext, null, null, null, null);
    // + Guard
    GuardingStatementOperations guardingOperations = new GuardingStatementOperations(parts.entityWriteOperations(), parts.entityReadOperations(), guard);
    StatementOperationParts guardedParts = parts.override(null, null, guardingOperations, guardingOperations, null, null, null, null, null, null, null, null);
    return new StatementOperationContainer(guardedParts, parts);
}
Also used : StackingQueryRegistrationOperations(org.neo4j.kernel.impl.api.StackingQueryRegistrationOperations) QueryRegistrationOperations(org.neo4j.kernel.impl.api.operations.QueryRegistrationOperations) SchemaStateConcern(org.neo4j.kernel.impl.api.SchemaStateConcern) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) LockingStatementOperations(org.neo4j.kernel.impl.api.LockingStatementOperations) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) ConstraintEnforcingEntityOperations(org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations) StackingQueryRegistrationOperations(org.neo4j.kernel.impl.api.StackingQueryRegistrationOperations) GuardingStatementOperations(org.neo4j.kernel.impl.api.GuardingStatementOperations) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) DataIntegrityValidatingStatementOperations(org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations)

Example 2 with StatementOperationParts

use of org.neo4j.kernel.impl.api.StatementOperationParts 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 StatementOperationParts

use of org.neo4j.kernel.impl.api.StatementOperationParts 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 StatementOperationParts

use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldReleaseSchemaLockWhileAwaitingIndexPopulation.

@Test
public void shouldReleaseSchemaLockWhileAwaitingIndexPopulation() throws Exception {
    // given
    StubKernel kernel = new StubKernel();
    IndexingService indexingService = mock(IndexingService.class);
    StatementOperationParts constraintCreationContext = mockedParts();
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    KernelStatement state = mockedState();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, true);
    // when
    creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), index.schema());
    // then
    verify(state.locks().pessimistic()).releaseExclusive(ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
    verify(state.locks().pessimistic()).acquireExclusive(state.lockTracer(), ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
}
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 5 with StatementOperationParts

use of org.neo4j.kernel.impl.api.StatementOperationParts in project neo4j by neo4j.

the class GuardIT method notIncludeGuardingOperationLayerOnNonGuardingParts.

@Test
public void notIncludeGuardingOperationLayerOnNonGuardingParts() throws Exception {
    GraphDatabaseAPI database = startDataBase();
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    StatementOperationContainer operationParts = dependencyResolver.resolveDependency(StatementOperationContainer.class);
    StatementOperationParts guardedParts = operationParts.nonGuarderParts();
    assertThat(guardedParts.entityReadOperations(), not(instanceOf(GuardingStatementOperations.class)));
    assertThat(guardedParts.entityWriteOperations(), not(instanceOf(GuardingStatementOperations.class)));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Aggregations

StatementOperationParts (org.neo4j.kernel.impl.api.StatementOperationParts)6 Test (org.junit.Test)5 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StatementOperationContainer (org.neo4j.kernel.impl.api.StatementOperationContainer)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)2 GuardingStatementOperations (org.neo4j.kernel.impl.api.GuardingStatementOperations)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 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 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)1 ConstraintEnforcingEntityOperations (org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations)1 DataIntegrityValidatingStatementOperations (org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations)1 LockingStatementOperations (org.neo4j.kernel.impl.api.LockingStatementOperations)1 SchemaStateConcern (org.neo4j.kernel.impl.api.SchemaStateConcern)1