Search in sources :

Example 36 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class BaseCompleteTransactionOperation method completeCache.

/**
 * Completes the transaction for a specific cache.
 */
private CompletionStage<Void> completeCache(ByteString cacheName) throws Throwable {
    TxState state = globalTxTable.getState(new CacheXid(cacheName, xid));
    HotRodServer.ExtendedCacheInfo cacheInfo = server.getCacheInfo(cacheName.toString(), header.getVersion(), header.getMessageId(), true);
    AdvancedCache<?, ?> cache = server.cache(cacheInfo, header, subject);
    RpcManager rpcManager = cache.getRpcManager();
    if (rpcManager == null || rpcManager.getAddress().equals(state.getOriginator())) {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Completing local executed transaction.", xid);
        }
        return asyncCompleteLocalTransaction(cache, state.getTimeout());
    } else if (rpcManager.getMembers().contains(state.getOriginator())) {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Forward remotely executed transaction to %s.", xid, state.getOriginator());
        }
        return forwardCompleteCommand(cacheName, rpcManager, state);
    } else {
        if (log.isTraceEnabled()) {
            log.tracef("[%s] Originator, %s, left the cluster.", xid, state.getOriginator());
        }
        return completeWithRemoteCommand(cache, rpcManager, state);
    }
}
Also used : CacheXid(org.infinispan.server.hotrod.tx.table.CacheXid) RpcManager(org.infinispan.remoting.rpc.RpcManager) TxState(org.infinispan.server.hotrod.tx.table.TxState) HotRodServer(org.infinispan.server.hotrod.HotRodServer)

Example 37 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.

the class GlobalTxTable method onOngoingTransaction.

private void onOngoingTransaction(CacheXid cacheXid, TxState state) {
    if (state.getStatus() == Status.PREPARED && state.isRecoverable()) {
        // recovery will handle prepared transactions
        return;
    }
    ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheXid.getCacheName());
    if (cr == null) {
        // we don't have the cache locally
        return;
    }
    RpcManager rpcManager = cr.getComponent(RpcManager.class);
    if (isRemote(rpcManager, state.getOriginator())) {
        // remotely originated transaction
        // this is a weird state. the originator may crashed or it may be in another partition and communication with the client
        // in any case, we can rollback the tx
        // if we are in the minority partition, updating the global tx table will fail and we do nothing
        // if we are in the majority partition, the originator can't commit/rollback since it would fail to update the global tx table
        rollbackOldTransaction(cacheXid, state, () -> rollbackRemote(cr, cacheXid, state));
    } else {
        // local transaction prepared.
        PerCacheTxTable txTable = cr.getComponent(PerCacheTxTable.class);
        EmbeddedTransaction tx = txTable.getLocalTx(cacheXid.getXid());
        if (tx == null) {
            // local transaction doesn't exists.
            onTransactionCompleted(cacheXid);
        } else {
            blockingManager.runBlocking(() -> rollbackOldTransaction(cacheXid, state, () -> completeLocal(txTable, cacheXid, tx, false)), cacheXid);
        }
    }
}
Also used : EmbeddedTransaction(org.infinispan.transaction.tm.EmbeddedTransaction) RpcManager(org.infinispan.remoting.rpc.RpcManager) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) ComponentRegistry(org.infinispan.factories.ComponentRegistry)

Aggregations

RpcManager (org.infinispan.remoting.rpc.RpcManager)37 Address (org.infinispan.remoting.transport.Address)11 CommandsFactory (org.infinispan.commands.CommandsFactory)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RpcOptions (org.infinispan.remoting.rpc.RpcOptions)7 Transport (org.infinispan.remoting.transport.Transport)7 Map (java.util.Map)5 ComponentRegistry (org.infinispan.factories.ComponentRegistry)5 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)4 RpcManagerImpl (org.infinispan.remoting.rpc.RpcManagerImpl)4 AbstractDelegatingRpcManager (org.infinispan.util.AbstractDelegatingRpcManager)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Cache (org.infinispan.Cache)3 IntSet (org.infinispan.commons.util.IntSet)3 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)3 InitialPublisherCommand (org.infinispan.reactive.publisher.impl.commands.batch.InitialPublisherCommand)3 Response (org.infinispan.remoting.responses.Response)3