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);
}
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();
}
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();
}
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();
}
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));
}
}
Aggregations