Search in sources :

Example 1 with KernelTransactions

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

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

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

the class TransactionCommittingResponseUnpackerTest method shouldCommitTransactionsInBatches.

@Test
public void shouldCommitTransactionsInBatches() throws Exception {
    // GIVEN
    Dependencies dependencies = mock(Dependencies.class);
    TransactionCountingTransactionCommitProcess commitProcess = new TransactionCountingTransactionCommitProcess();
    when(dependencies.commitProcess()).thenReturn(commitProcess);
    when(dependencies.logService()).thenReturn(NullLogService.getInstance());
    KernelTransactions kernelTransactions = mock(KernelTransactions.class);
    when(dependencies.kernelTransactions()).thenReturn(kernelTransactions);
    TransactionCommittingResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(dependencies, 5, 0));
    // WHEN
    unpacker.unpackResponse(new DummyTransactionResponse(BASE_TX_ID + 1, 7), NO_OP_TX_HANDLER);
    // THEN
    commitProcess.assertBatchSize(5);
    commitProcess.assertBatchSize(2);
    commitProcess.assertNoMoreBatches();
}
Also used : KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) Test(org.junit.Test)

Example 4 with KernelTransactions

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

the class TransactionTerminationIT method activeTxCount.

private static int activeTxCount(GraphDatabaseService db) {
    DependencyResolver resolver = ((GraphDatabaseAPI) db).getDependencyResolver();
    KernelTransactions kernelTransactions = resolver.resolveDependency(KernelTransactions.class);
    return kernelTransactions.activeTransactions().size();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 5 with KernelTransactions

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

the class NeoStoreDataSource method awaitAllClosingTransactions.

private void awaitAllClosingTransactions() {
    KernelTransactions kernelTransactions = kernelModule.kernelTransactions();
    kernelTransactions.terminateTransactions();
    while (kernelTransactions.haveClosingTransaction()) {
        LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10));
    }
}
Also used : KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions)

Aggregations

KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)5 Test (org.junit.Test)2 Dependencies (org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies)2 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)2 InOrder (org.mockito.InOrder)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 KernelAPI (org.neo4j.kernel.api.KernelAPI)1 Kernel (org.neo4j.kernel.impl.api.Kernel)1 StatementOperationContainer (org.neo4j.kernel.impl.api.StatementOperationContainer)1 TransactionHooks (org.neo4j.kernel.impl.api.TransactionHooks)1 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)1 LegacyIndexStore (org.neo4j.kernel.impl.index.LegacyIndexStore)1 NeoStoreFileListing (org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1