Search in sources :

Example 1 with SetCompletedTransactionFunction

use of org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction in project infinispan by infinispan.

the class GlobalTxTable method rollbackRemote.

private void rollbackRemote(ComponentRegistry cr, CacheXid cacheXid, TxState state) {
    RollbackCommand rpcCommand = cr.getCommandsFactory().buildRollbackCommand(state.getGlobalTransaction());
    RpcManager rpcManager = cr.getComponent(RpcManager.class);
    rpcCommand.setTopologyId(rpcManager.getTopologyId());
    rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).thenRun(() -> {
        // ignore exception so the rollback can be retried.
        // if a node doesn't find the remote transaction, it returns null.
        TxFunction function = new SetCompletedTransactionFunction(false);
        rwMap.eval(cacheXid, function);
    });
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction)

Example 2 with SetCompletedTransactionFunction

use of org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction in project infinispan by infinispan.

the class GlobalTxTable method onTransactionDecision.

private void onTransactionDecision(CacheXid cacheXid, TxState state, boolean commit) {
    ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheXid.getCacheName());
    if (cr == null) {
        // we don't have the cache locally
        return;
    }
    RpcManager rpcManager = cr.getComponent(RpcManager.class);
    if (rpcManager == null || state.getOriginator().equals(rpcManager.getAddress())) {
        // local
        PerCacheTxTable txTable = cr.getComponent(PerCacheTxTable.class);
        EmbeddedTransaction tx = txTable.getLocalTx(cacheXid.getXid());
        if (tx == null) {
            // transaction completed
            onTransactionCompleted(cacheXid);
        } else {
            blockingManager.runBlocking(() -> completeLocal(txTable, cacheXid, tx, commit), cacheXid);
        }
    } else {
        if (commit) {
            TransactionBoundaryCommand rpcCommand;
            if (cr.getComponent(Configuration.class).transaction().lockingMode() == LockingMode.PESSIMISTIC) {
                rpcCommand = cr.getCommandsFactory().buildPrepareCommand(state.getGlobalTransaction(), state.getModifications(), true);
            } else {
                rpcCommand = cr.getCommandsFactory().buildCommitCommand(state.getGlobalTransaction());
            }
            rpcCommand.setTopologyId(rpcManager.getTopologyId());
            rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).handle((aVoid, throwable) -> {
                // TODO?
                TxFunction function = new SetCompletedTransactionFunction(true);
                rwMap.eval(cacheXid, function);
                return null;
            });
        } else {
            rollbackRemote(cr, cacheXid, state);
        }
    }
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) RpcManager(org.infinispan.remoting.rpc.RpcManager) TransactionBoundaryCommand(org.infinispan.commands.tx.TransactionBoundaryCommand) Configuration(org.infinispan.configuration.cache.Configuration) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction)

Example 3 with SetCompletedTransactionFunction

use of org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction 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());
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) ArrayList(java.util.ArrayList) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction) CreateStateFunction(org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction) PreparingDecisionFunction(org.infinispan.server.hotrod.tx.table.functions.PreparingDecisionFunction) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable) SetDecisionFunction(org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction) SetPreparedFunction(org.infinispan.server.hotrod.tx.table.functions.SetPreparedFunction)

Example 4 with SetCompletedTransactionFunction

use of org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction in project infinispan by infinispan.

the class Util method completeLocalTransaction.

private static void completeLocalTransaction(AdvancedCache<?, ?> cache, XidImpl xid, long timeout, boolean commit) throws HeuristicRollbackException, HeuristicMixedException, RollbackException {
    PerCacheTxTable perCacheTxTable = cache.getComponentRegistry().getComponent(PerCacheTxTable.class);
    GlobalTxTable globalTxTable = cache.getComponentRegistry().getGlobalComponentRegistry().getComponent(GlobalTxTable.class);
    try {
        // local transaction
        EmbeddedTransaction tx = perCacheTxTable.getLocalTx(xid);
        tx.runCommit(!commit);
        CacheXid cacheXid = new CacheXid(ByteString.fromString(cache.getName()), xid);
        TxFunction function = new SetCompletedTransactionFunction(commit);
        globalTxTable.update(cacheXid, function, timeout);
    } finally {
        perCacheTxTable.removeLocalTx(xid);
    }
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) SetCompletedTransactionFunction(org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction) TxFunction(org.infinispan.server.hotrod.tx.table.functions.TxFunction) PerCacheTxTable(org.infinispan.server.hotrod.tx.table.PerCacheTxTable) GlobalTxTable(org.infinispan.server.hotrod.tx.table.GlobalTxTable)

Aggregations

SetCompletedTransactionFunction (org.infinispan.server.hotrod.tx.table.functions.SetCompletedTransactionFunction)4 TxFunction (org.infinispan.server.hotrod.tx.table.functions.TxFunction)4 RpcManager (org.infinispan.remoting.rpc.RpcManager)2 CacheXid (org.infinispan.server.hotrod.tx.table.CacheXid)2 GlobalTxTable (org.infinispan.server.hotrod.tx.table.GlobalTxTable)2 EmbeddedTransaction (org.infinispan.transaction.tm.EmbeddedTransaction)2 ArrayList (java.util.ArrayList)1 RollbackCommand (org.infinispan.commands.tx.RollbackCommand)1 TransactionBoundaryCommand (org.infinispan.commands.tx.TransactionBoundaryCommand)1 Configuration (org.infinispan.configuration.cache.Configuration)1 ComponentRegistry (org.infinispan.factories.ComponentRegistry)1 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)1 PerCacheTxTable (org.infinispan.server.hotrod.tx.table.PerCacheTxTable)1 CreateStateFunction (org.infinispan.server.hotrod.tx.table.functions.CreateStateFunction)1 PreparingDecisionFunction (org.infinispan.server.hotrod.tx.table.functions.PreparingDecisionFunction)1 SetDecisionFunction (org.infinispan.server.hotrod.tx.table.functions.SetDecisionFunction)1 SetPreparedFunction (org.infinispan.server.hotrod.tx.table.functions.SetPreparedFunction)1 GlobalTransaction (org.infinispan.transaction.xa.GlobalTransaction)1