Search in sources :

Example 11 with TransactionCommitProcess

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

the class ReplicatedTransactionStateMachineTest method shouldCommitTransaction.

@Test
public void shouldCommitTransaction() throws Exception {
    // given
    int lockSessionId = 23;
    ReplicatedTransaction tx = ReplicatedTransactionFactory.createImmutableReplicatedTransaction(physicalTx(lockSessionId));
    TransactionCommitProcess localCommitProcess = mock(TransactionCommitProcess.class);
    ReplicatedTransactionStateMachine stateMachine = new ReplicatedTransactionStateMachine(lockState(lockSessionId), batchSize, logProvider);
    stateMachine.installCommitProcess(localCommitProcess, -1L);
    // when
    stateMachine.applyCommand(tx, 0, r -> {
    });
    stateMachine.ensuredApplied();
    // then
    verify(localCommitProcess, times(1)).commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) Test(org.junit.Test)

Example 12 with TransactionCommitProcess

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

the class CommitProcessSwitcher method getMasterImpl.

@Override
protected TransactionCommitProcess getMasterImpl() {
    TransactionCommitProcess commitProcess = new TransactionRepresentationCommitProcess(dependencyResolver.resolveDependency(TransactionAppender.class), dependencyResolver.resolveDependency(StorageEngine.class));
    IntegrityValidator validator = dependencyResolver.resolveDependency(IntegrityValidator.class);
    return new MasterTransactionCommitProcess(commitProcess, txPropagator, validator, monitor, locks, reacquireSharedSchemaLockOnIncomingTransactions);
}
Also used : IntegrityValidator(org.neo4j.kernel.impl.transaction.state.IntegrityValidator) MasterTransactionCommitProcess(org.neo4j.kernel.ha.MasterTransactionCommitProcess) SlaveTransactionCommitProcess(org.neo4j.kernel.ha.SlaveTransactionCommitProcess) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) MasterTransactionCommitProcess(org.neo4j.kernel.ha.MasterTransactionCommitProcess) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 13 with TransactionCommitProcess

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

the class MasterClientTest method clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest.

@Test
public void clientShouldReadAndApplyTransactionLogsOnNewLockSessionRequest() throws Throwable {
    // Given
    MasterImpl master = spy(newMasterImpl(mockMasterImplSpiWith(StoreId.DEFAULT)));
    doReturn(voidResponseWithTransactionLogs()).when(master).newLockSession(any(RequestContext.class));
    newMasterServer(master);
    Dependencies deps = mock(Dependencies.class);
    TransactionCommitProcess commitProcess = mock(TransactionCommitProcess.class);
    when(deps.commitProcess()).thenReturn(commitProcess);
    when(deps.logService()).thenReturn(NullLogService.getInstance());
    when(deps.kernelTransactions()).thenReturn(mock(KernelTransactions.class));
    ResponseUnpacker unpacker = life.add(new TransactionCommittingResponseUnpacker(deps, DEFAULT_BATCH_SIZE, 0));
    MasterClient masterClient = newMasterClient320(StoreId.DEFAULT, unpacker);
    // When
    masterClient.newLockSession(new RequestContext(1, 2, 3, 4, 5));
    // Then
    verify(commitProcess).commit(any(TransactionToApply.class), any(CommitEvent.class), any(TransactionApplicationMode.class));
}
Also used : TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) MasterImpl(org.neo4j.kernel.ha.com.master.MasterImpl) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CommitEvent(org.neo4j.kernel.impl.transaction.tracing.CommitEvent) RequestContext(org.neo4j.com.RequestContext) Dependencies(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker.Dependencies) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) TransactionCommittingResponseUnpacker(org.neo4j.com.storecopy.TransactionCommittingResponseUnpacker) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) MasterImplTest(org.neo4j.kernel.ha.com.master.MasterImplTest) Test(org.junit.Test)

Example 14 with TransactionCommitProcess

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

the class HighlyAvailableEditionModule method createCommitProcessFactory.

private CommitProcessFactory createCommitProcessFactory(Dependencies dependencies, LogService logging, Monitors monitors, Config config, LifeSupport paxosLife, ClusterClient clusterClient, ClusterMembers members, JobScheduler jobScheduler, Master master, RequestContextFactory requestContextFactory, ComponentSwitcherContainer componentSwitcherContainer, Supplier<LogEntryReader<ReadableClosablePositionAwareChannel>> logEntryReader) {
    DefaultSlaveFactory slaveFactory = dependencies.satisfyDependency(new DefaultSlaveFactory(logging.getInternalLogProvider(), monitors, config.get(HaSettings.com_chunk_size).intValue(), logEntryReader));
    HostnamePort me = config.get(ClusterSettings.cluster_server);
    Slaves slaves = dependencies.satisfyDependency(paxosLife.add(new HighAvailabilitySlaves(members, clusterClient, slaveFactory, me)));
    TransactionPropagator transactionPropagator = new TransactionPropagator(TransactionPropagator.from(config), logging.getInternalLog(TransactionPropagator.class), slaves, new CommitPusher(jobScheduler));
    paxosLife.add(transactionPropagator);
    DelegateInvocationHandler<TransactionCommitProcess> commitProcessDelegate = new DelegateInvocationHandler<>(TransactionCommitProcess.class);
    CommitProcessSwitcher commitProcessSwitcher = new CommitProcessSwitcher(transactionPropagator, master, commitProcessDelegate, requestContextFactory, lockManager, monitors, dependencies, config.get(GraphDatabaseSettings.release_schema_lock_while_building_constraint));
    componentSwitcherContainer.add(commitProcessSwitcher);
    return new HighlyAvailableCommitProcessFactory(commitProcessDelegate);
}
Also used : TransactionPropagator(org.neo4j.kernel.ha.transaction.TransactionPropagator) CommitPusher(org.neo4j.kernel.ha.transaction.CommitPusher) HostnamePort(org.neo4j.helpers.HostnamePort) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) CommitProcessSwitcher(org.neo4j.kernel.ha.cluster.modeswitch.CommitProcessSwitcher) HighAvailabilitySlaves(org.neo4j.kernel.ha.cluster.member.HighAvailabilitySlaves) Slaves(org.neo4j.kernel.ha.com.master.Slaves) HighAvailabilitySlaves(org.neo4j.kernel.ha.cluster.member.HighAvailabilitySlaves)

Example 15 with TransactionCommitProcess

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

the class LabelAndIndexUpdateBatchingIT method indexShouldIncludeNodesCreatedPreviouslyInBatch.

@Test
public void indexShouldIncludeNodesCreatedPreviouslyInBatch() throws Exception {
    // GIVEN a transaction stream leading up to this issue
    // perform the transactions from db-level and extract the transactions as commands
    // so that they can be applied batch-wise they way we'd like to later.
    // a bunch of nodes (to have the index population later on to decide to use label scan for population)
    List<TransactionRepresentation> transactions;
    GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    String nodeN = "our guy";
    String otherNode = "just to create the tokens";
    try {
        try (Transaction tx = db.beginTx()) {
            db.createNode(LABEL).setProperty(PROPERTY_KEY, otherNode);
            for (int i = 0; i < 10_000; i++) {
                db.createNode();
            }
            tx.success();
        }
        // node N
        try (Transaction tx = db.beginTx()) {
            db.createNode(LABEL).setProperty(PROPERTY_KEY, nodeN);
            tx.success();
        }
        // uniqueness constraint affecting N
        try (Transaction tx = db.beginTx()) {
            db.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
            tx.success();
        }
        transactions = extractTransactions(db);
    } finally {
        db.shutdown();
    }
    db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
    TransactionCommitProcess commitProcess = db.getDependencyResolver().resolveDependency(TransactionCommitProcess.class);
    try {
        int cutoffIndex = findCutoffIndex(transactions);
        commitProcess.commit(toApply(transactions.subList(0, cutoffIndex)), NULL, EXTERNAL);
        // WHEN applying the two transactions (node N and the constraint) in the same batch
        commitProcess.commit(toApply(transactions.subList(cutoffIndex, transactions.size())), NULL, EXTERNAL);
        // THEN node N should've ended up in the index too
        try (Transaction tx = db.beginTx()) {
            assertNotNull("Verification node not found", // just to verify
            singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, otherNode)));
            assertNotNull("Node N not found", singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, nodeN)));
            tx.success();
        }
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) 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