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