use of org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction in project infinispan by infinispan.
the class GlobalTxTable method markTx.
private void markTx(XidImpl xid, boolean commit, CacheNameCollector collector) {
if (log.isTraceEnabled()) {
log.tracef("[%s] Set Transaction Decision to %s", xid, commit ? "Commit" : "Rollback");
}
final List<CacheXid> cacheXids = getKeys(xid);
if (log.isTraceEnabled()) {
log.tracef("[%s] Fetched CacheXids=%s", xid, cacheXids);
}
final int size = cacheXids.size();
if (size == 0) {
collector.noTransactionFound();
return;
}
collector.expectedSize(size);
SetDecisionFunction function = new SetDecisionFunction(commit);
for (CacheXid cacheXid : cacheXids) {
rwMap.eval(cacheXid, function).handle((statusValue, throwable) -> {
Status status;
if (throwable == null) {
status = Status.valueOf(statusValue);
} else {
status = Status.ERROR;
}
collector.addCache(cacheXid.getCacheName(), status);
return null;
});
}
}
use of org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction in project infinispan by infinispan.
the class TxReaperAndRecoveryTest method initGlobalTxTable.
private void initGlobalTxTable(int index, XidImpl xid, Address address, boolean recoverable, Status status) {
GlobalTxTable globalTxTable = globalTxTable(index);
CacheXid cacheXid = new CacheXid(fromString(cacheName()), xid);
List<TxFunction> functions = new ArrayList<>(5);
GlobalTransaction gtx = address == null ? newGlobalTransaction(cacheName(), index) : newGlobalTransaction(cacheName(), index, address);
switch(status) {
case ACTIVE:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
break;
case PREPARING:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
break;
case PREPARED:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
functions.add(new SetPreparedFunction());
break;
case MARK_ROLLBACK:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
functions.add(new SetPreparedFunction());
functions.add(new SetDecisionFunction(false));
break;
case MARK_COMMIT:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
functions.add(new SetPreparedFunction());
functions.add(new SetDecisionFunction(true));
break;
case ROLLED_BACK:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
functions.add(new SetPreparedFunction());
functions.add(new SetDecisionFunction(false));
functions.add(new SetCompletedTransactionFunction(false));
break;
case COMMITTED:
functions.add(new CreateStateFunction(gtx, recoverable, 1));
functions.add(new PreparingDecisionFunction(Collections.emptyList()));
functions.add(new SetPreparedFunction());
functions.add(new SetDecisionFunction(true));
functions.add(new SetCompletedTransactionFunction(true));
break;
default:
throw new IllegalStateException();
}
for (TxFunction function : functions) {
assertEquals(Status.OK, globalTxTable.update(cacheXid, function, 30000));
}
assertEquals(status, globalTxTable.getState(cacheXid).getStatus());
}
Aggregations