use of org.infinispan.transaction.impl.TransactionCoordinator in project infinispan by infinispan.
the class StaleLocksWithCommitDuringStateTransferTest method doTestSuspect.
/**
* Check that the transaction commit/rollback recovers if the remote node dies during the RPC
*/
private void doTestSuspect(boolean commit) throws Exception {
MagicKey k1 = new MagicKey("k1", c1);
MagicKey k2 = new MagicKey("k2", c2);
tm(c1).begin();
c1.put(k1, "v1");
c1.put(k2, "v2");
// We split the transaction commit in two phases by calling the TransactionCoordinator methods directly
TransactionTable txTable = TestingUtil.extractComponent(c1, TransactionTable.class);
TransactionCoordinator txCoordinator = TestingUtil.extractComponent(c1, TransactionCoordinator.class);
// Execute the prepare on both nodes
LocalTransaction localTx = txTable.getLocalTransaction(tm(c1).getTransaction());
CompletionStages.join(txCoordinator.prepare(localTx));
// Delay the commit on the remote node. Can't used blockNewTransactions because we don't want a StateTransferInProgressException
AsyncInterceptorChain c2ic = c2.getAdvancedCache().getAsyncInterceptorChain();
c2ic.addInterceptorBefore(new DelayCommandInterceptor(), StateTransferInterceptor.class);
// Schedule the remote node to stop on another thread since the main thread will be busy with the commit call
Thread worker = new Thread("RehasherSim,StaleLocksWithCommitDuringStateTransferTest") {
@Override
public void run() {
try {
// should be much larger than the lock acquisition timeout
Thread.sleep(1000);
manager(c2).stop();
// stLock.unblockNewTransactions(1000);
} catch (InterruptedException e) {
log.errorf(e, "Error stopping cache");
}
}
};
worker.start();
try {
// finally commit or rollback the transaction
if (commit) {
CompletionStages.join(txCoordinator.commit(localTx, false));
} else {
CompletionStages.join(txCoordinator.rollback(localTx));
}
// make the transaction manager forget about our tx so that we don't get rollback exceptions in the log
tm(c1).suspend();
} finally {
// don't leak threads
worker.join();
}
// test that we don't leak locks
assertEventuallyNotLocked(c1, k1);
assertEventuallyNotLocked(c1, k2);
}
use of org.infinispan.transaction.impl.TransactionCoordinator in project infinispan by infinispan.
the class StaleLocksWithCommitDuringStateTransferTest method doStateTransferInProgressTest.
/**
* Check that the transaction commit/rollback recovers if we receive a StateTransferInProgressException from the remote node
*/
private void doStateTransferInProgressTest(boolean commit, final boolean failOnOriginator) throws Exception {
MagicKey k1 = new MagicKey("k1", c1);
MagicKey k2 = new MagicKey("k2", c2);
tm(c1).begin();
c1.put(k1, "v1");
c1.put(k2, "v2");
// We split the transaction commit in two phases by calling the TransactionCoordinator methods directly
TransactionTable txTable = TestingUtil.extractComponent(c1, TransactionTable.class);
TransactionCoordinator txCoordinator = TestingUtil.extractComponent(c1, TransactionCoordinator.class);
// Execute the prepare on both nodes
LocalTransaction localTx = txTable.getLocalTransaction(tm(c1).getTransaction());
CompletionStages.join(txCoordinator.prepare(localTx));
final CountDownLatch commitLatch = new CountDownLatch(1);
Thread worker = new Thread("RehasherSim,StaleLocksWithCommitDuringStateTransferTest") {
@Override
public void run() {
try {
// Before calling commit we block transactions on one of the nodes to simulate a state transfer
final StateTransferLock blockFirst = TestingUtil.extractComponent(failOnOriginator ? c1 : c2, StateTransferLock.class);
final StateTransferLock blockSecond = TestingUtil.extractComponent(failOnOriginator ? c2 : c1, StateTransferLock.class);
try {
blockFirst.acquireExclusiveTopologyLock();
blockSecond.acquireExclusiveTopologyLock();
commitLatch.countDown();
// should be much larger than the lock acquisition timeout
Thread.sleep(1000);
} finally {
blockSecond.releaseExclusiveTopologyLock();
blockFirst.releaseExclusiveTopologyLock();
}
} catch (Throwable t) {
log.errorf(t, "Error blocking/unblocking transactions");
}
}
};
worker.start();
commitLatch.await(10, TimeUnit.SECONDS);
try {
// finally commit or rollback the transaction
if (commit) {
tm(c1).commit();
} else {
tm(c1).rollback();
}
// make the transaction manager forget about our tx so that we don't get rollback exceptions in the log
tm(c1).suspend();
} finally {
// don't leak threads
worker.join();
}
// test that we don't leak locks
assertEventuallyNotLocked(c1, k1);
assertEventuallyNotLocked(c2, k1);
assertEventuallyNotLocked(c1, k2);
assertEventuallyNotLocked(c2, k2);
}
use of org.infinispan.transaction.impl.TransactionCoordinator in project infinispan by infinispan.
the class TransactionXaAdapterTmIntegrationTest method setUp.
@BeforeMethod
public void setUp() throws XAException {
Configuration configuration = new ConfigurationBuilder().build();
XaTransactionTable txTable = new XaTransactionTable();
txCoordinator = new TransactionCoordinator();
TestingUtil.inject(txTable, configuration, txCoordinator, TransactionOriginatorChecker.LOCAL);
txTable.start();
txTable.startXidMapping();
TransactionFactory gtf = new TransactionFactory();
gtf.init(false, false, true, false);
GlobalTransaction globalTransaction = gtf.newGlobalTransaction(null, false);
EmbeddedBaseTransactionManager tm = new EmbeddedBaseTransactionManager();
localTx = new LocalXaTransaction(new EmbeddedTransaction(tm), globalTransaction, false, 1, 0);
xid = EmbeddedTransaction.createXid(uuid);
InvocationContextFactory icf = new TransactionalInvocationContextFactory();
CommandsFactory commandsFactory = mock(CommandsFactory.class);
AsyncInterceptorChain invoker = mock(AsyncInterceptorChain.class);
when(invoker.invokeAsync(any(), any())).thenReturn(CompletableFutures.completedNull());
TestingUtil.inject(txCoordinator, commandsFactory, icf, invoker, txTable, configuration);
xaAdapter = new TransactionXaAdapter(localTx, txTable);
xaAdapter.start(xid, 0);
}
Aggregations