use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class RecoveryWithDefaultCacheDistTest method testNodeCrashesAfterPrepare.
public void testNodeCrashesAfterPrepare() throws Exception {
EmbeddedTransaction t1_1 = beginAndSuspendTx(cache(1));
prepareTransaction(t1_1);
EmbeddedTransaction t1_2 = beginAndSuspendTx(cache(1));
prepareTransaction(t1_2);
EmbeddedTransaction t1_3 = beginAndSuspendTx(cache(1));
prepareTransaction(t1_3);
manager(1).stop();
super.cacheManagers.remove(1);
TestingUtil.blockUntilViewReceived(cache(0), 1, 60000, false);
eventually(() -> {
int size = rm(cache(0)).getInDoubtTransactionInfo().size();
return size == 3;
});
List<XidImpl> inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
assertEquals(3, inDoubtTransactions.size());
assert inDoubtTransactions.contains(t1_1.getXid());
assert inDoubtTransactions.contains(t1_2.getXid());
assert inDoubtTransactions.contains(t1_3.getXid());
configuration.transaction().transactionMode(TransactionMode.TRANSACTIONAL);
startCacheManager();
TestingUtil.blockUntilViewsReceived(60000, cache(0), cache(1));
EmbeddedTransaction t1_4 = beginAndSuspendTx(cache(1));
prepareTransaction(t1_4);
log.trace("Before main recovery call.");
assertPrepared(4, t1_4);
// now second call would only return 1 prepared tx as we only go over the network once
assertPrepared(1, t1_4);
commitTransaction(t1_4);
assertPrepared(0, t1_4);
inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
assertEquals(3, inDoubtTransactions.size());
assert inDoubtTransactions.contains(t1_1.getXid());
assert inDoubtTransactions.contains(t1_2.getXid());
assert inDoubtTransactions.contains(t1_3.getXid());
// now let's start to forget transactions
t1_4.firstEnlistedResource().forget(t1_1.getXid());
log.info("returned");
eventually(() -> rm(cache(0)).getInDoubtTransactionInfo().size() == 2);
inDoubtTransactions = rm(cache(0)).getInDoubtTransactions();
assertEquals(2, inDoubtTransactions.size());
assert inDoubtTransactions.contains(t1_2.getXid());
assert inDoubtTransactions.contains(t1_3.getXid());
t1_4.firstEnlistedResource().forget(t1_2.getXid());
t1_4.firstEnlistedResource().forget(t1_3.getXid());
eventually(() -> rm(cache(0)).getInDoubtTransactionInfo().size() == 0);
assertEquals(0, rm(cache(0)).getInDoubtTransactionInfo().size());
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class TransactionXaAdapterTmIntegrationTest method test1PcAndNonExistentXid.
public void test1PcAndNonExistentXid() {
Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.INVALIDATION_ASYNC).build();
TestingUtil.inject(txCoordinator, configuration);
try {
XidImpl doesNotExists = EmbeddedTransaction.createXid(uuid);
xaAdapter.commit(doesNotExists, false);
assert false;
} catch (XAException e) {
assertEquals(XAException.XAER_NOTA, e.errorCode);
}
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class TransactionXaAdapterTmIntegrationTest method test1PcAndNonExistentXid2.
public void test1PcAndNonExistentXid2() {
Configuration configuration = new ConfigurationBuilder().clustering().cacheMode(CacheMode.DIST_SYNC).build();
TestingUtil.inject(txCoordinator, configuration);
try {
XidImpl doesNotExists = EmbeddedTransaction.createXid(uuid);
xaAdapter.commit(doesNotExists, true);
assert false;
} catch (XAException e) {
assertEquals(XAException.XAER_NOTA, e.errorCode);
}
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class GlobalTxTable method getPreparedTransactions.
public Collection<XidImpl> getPreparedTransactions() {
long currentTimestamp = timeService.time();
// remove duplicates!
Collection<XidImpl> preparedTx = new HashSet<>();
for (Map.Entry<CacheXid, TxState> entry : storage.entrySet()) {
XidImpl xid = entry.getKey().getXid();
TxState state = entry.getValue();
if (log.isTraceEnabled()) {
log.tracef("Checking transaction xid=%s for recovery. TimedOut?=%s, Recoverable?=%s, Status=%s", xid, state.hasTimedOut(currentTimestamp), state.isRecoverable(), state.getStatus());
}
if (state.hasTimedOut(currentTimestamp) && state.isRecoverable() && state.getStatus() == Status.PREPARED) {
preparedTx.add(xid);
}
}
return preparedTx;
}
use of org.infinispan.commons.tx.XidImpl in project infinispan by infinispan.
the class Encoder2x method recoveryResponse.
@Override
public ByteBuf recoveryResponse(HotRodHeader header, HotRodServer server, Channel channel, Collection<XidImpl> xids) {
ByteBuf buf = writeHeader(header, server, channel, OperationStatus.Success);
writeUnsignedInt(xids.size(), buf);
for (XidImpl xid : xids) {
writeXid(xid, buf);
}
return buf;
}
Aggregations