Search in sources :

Example 6 with TransactionCommitProcess

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

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

the class TransactionCommittingResponseUnpackerTest method shouldUnfreezeKernelTransactionsAfterApplyIfBatchIsLarge.

/*
      * Tests that we unfreeze active transactions after commit and after apply of batch if batch length (in time)
      * is larger than safeZone time.
      */
@Test
public void shouldUnfreezeKernelTransactionsAfterApplyIfBatchIsLarge() throws Throwable {
    // GIVEN
    int maxBatchSize = 10;
    long idReuseSafeZoneTime = 100;
    Dependencies dependencies = mock(Dependencies.class);
    TransactionObligationFulfiller fulfiller = mock(TransactionObligationFulfiller.class);
    when(dependencies.obligationFulfiller()).thenReturn(fulfiller);
    when(dependencies.logService()).thenReturn(NullLogService.getInstance());
    KernelTransactions kernelTransactions = mock(KernelTransactions.class);
    when(dependencies.kernelTransactions()).thenReturn(kernelTransactions);
    TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
    when(dependencies.commitProcess()).thenReturn(commitProcess);
    TransactionCommittingResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(dependencies, maxBatchSize, idReuseSafeZoneTime));
    // WHEN
    int txCount = maxBatchSize;
    int doesNotMatter = 1;
    unpacker.unpackResponse(new DummyTransactionResponse(doesNotMatter, txCount, idReuseSafeZoneTime + 1), NO_OP_TX_HANDLER);
    // THEN
    InOrder inOrder = inOrder(commitProcess, kernelTransactions);
    inOrder.verify(commitProcess, times(1)).commit(any(), any(), any());
    inOrder.verify(kernelTransactions, times(1)).unblockNewTransactions();
}
Also used : InOrder(org.mockito.InOrder) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) Test(org.junit.Test)

Example 8 with TransactionCommitProcess

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

the class ReplicatedTransactionStateMachine method installCommitProcess.

public synchronized void installCommitProcess(TransactionCommitProcess commitProcess, long lastCommittedIndex) {
    this.lastCommittedIndex = lastCommittedIndex;
    log.info(format("Updated lastCommittedIndex to %d", lastCommittedIndex));
    this.queue = new TransactionQueue(maxBatchSize, (first, last) -> commitProcess.commit(first, CommitEvent.NULL, TransactionApplicationMode.EXTERNAL));
}
Also used : Log(org.neo4j.logging.Log) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogProvider(org.neo4j.logging.LogProvider) IOException(java.io.IOException) Result(org.neo4j.causalclustering.core.state.Result) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) String.format(java.lang.String.format) Consumer(java.util.function.Consumer) LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader(org.neo4j.causalclustering.core.state.machines.tx.LogIndexTxHeaderEncoding.encodeLogIndexAsTxHeader) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) Locks(org.neo4j.kernel.impl.locking.Locks) ReplicatedLockTokenStateMachine(org.neo4j.causalclustering.core.state.machines.locks.ReplicatedLockTokenStateMachine) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) LockSessionExpired(org.neo4j.kernel.api.exceptions.Status.Transaction.LockSessionExpired) StateMachine(org.neo4j.causalclustering.core.state.machines.StateMachine) TransactionQueue(org.neo4j.kernel.impl.api.TransactionQueue) TransactionQueue(org.neo4j.kernel.impl.api.TransactionQueue)

Example 9 with TransactionCommitProcess

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

the class HighlyAvailableCommitProcessFactoryTest method createRegularCommitProcess.

@Test
public void createRegularCommitProcess() {
    HighlyAvailableCommitProcessFactory factory = new HighlyAvailableCommitProcessFactory(new DelegateInvocationHandler<>(TransactionCommitProcess.class));
    TransactionCommitProcess commitProcess = factory.create(mock(TransactionAppender.class), mock(StorageEngine.class), Config.empty());
    assertThat(commitProcess, not(instanceOf(ReadOnlyTransactionCommitProcess.class)));
    assertThat(Proxy.getInvocationHandler(commitProcess), instanceOf(DelegateInvocationHandler.class));
}
Also used : ReadOnlyTransactionCommitProcess(org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) StorageEngine(org.neo4j.storageengine.api.StorageEngine) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) Test(org.junit.Test)

Example 10 with TransactionCommitProcess

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

the class CommitProcessStateMachineCollaborationTest method shouldFailTransactionIfLockSessionChanges.

@Test
public void shouldFailTransactionIfLockSessionChanges() throws Exception {
    // given
    int initialLockSessionId = 23;
    TransactionToApply transactionToApply = new TransactionToApply(physicalTx(initialLockSessionId));
    int finalLockSessionId = 24;
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(finalLockSessionId), 16, NullLogProvider.getInstance());
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    DirectReplicator<ReplicatedTransaction> replicator = new DirectReplicator<>(stateMachine);
    ReplicatedTransactionCommitProcess commitProcess = new ReplicatedTransactionCommitProcess(replicator);
    // when
    try {
        commitProcess.commit(transactionToApply, NULL, EXTERNAL);
        fail("Should have thrown exception.");
    } catch (TransactionFailureException e) {
    // expected
    }
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DirectReplicator(org.neo4j.causalclustering.core.replication.DirectReplicator) Test(org.junit.Test)

Aggregations

TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)16 Test (org.junit.Test)11 TransactionToApply (org.neo4j.kernel.impl.api.TransactionToApply)5 TransactionAppender (org.neo4j.kernel.impl.transaction.log.TransactionAppender)5 StorageEngine (org.neo4j.storageengine.api.StorageEngine)5 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)4 ReadOnlyTransactionCommitProcess (org.neo4j.kernel.impl.api.ReadOnlyTransactionCommitProcess)4 CommitEvent (org.neo4j.kernel.impl.transaction.tracing.CommitEvent)4 TransactionApplicationMode (org.neo4j.storageengine.api.TransactionApplicationMode)4 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)2 Config (org.neo4j.kernel.configuration.Config)2 DelegateInvocationHandler (org.neo4j.kernel.ha.DelegateInvocationHandler)2 TransactionRepresentationCommitProcess (org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess)2 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)2 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 Consumer (java.util.function.Consumer)1 InOrder (org.mockito.InOrder)1