Search in sources :

Example 11 with RpcManager

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

the class RehashClusterPublisherManagerTest method testSegmentMovesToOriginatorJustBeforeSendingRemote.

private void testSegmentMovesToOriginatorJustBeforeSendingRemote(DeliveryGuarantee deliveryGuarantee, boolean parallel, boolean isEntry, boolean useKeys) throws Exception {
    Cache cache0 = cache(0);
    Address cache2Address = address(2);
    CheckPoint checkPoint = new CheckPoint();
    // Always let it finish once released
    checkPoint.triggerForever(Mocks.AFTER_RELEASE);
    // Block on about to send the remote command to node2
    RpcManager original = Mocks.blockingMock(checkPoint, RpcManager.class, cache0, (stub, m) -> stub.when(m).invokeCommand(eq(cache2Address), isA(ReductionPublisherRequestCommand.class), any(), any()));
    int expectedAmount = caches().size();
    // If it is at most once, we don't retry the segment so the count will be off by 1
    if (deliveryGuarantee == DeliveryGuarantee.AT_MOST_ONCE) {
        expectedAmount -= 1;
    }
    // When we are using keys, we explicitly don't pass one of them
    if (useKeys) {
        expectedAmount--;
    }
    try {
        runCommand(deliveryGuarantee, parallel, isEntry, expectedAmount, () -> {
            checkPoint.awaitStrict(Mocks.BEFORE_INVOCATION, 10, TimeUnit.SECONDS);
            triggerRebalanceSegment2MovesToNode0();
            checkPoint.triggerForever(Mocks.BEFORE_RELEASE);
        }, toKeys(useKeys));
    } finally {
        if (original != null) {
            TestingUtil.replaceComponent(cache0, RpcManager.class, original, true);
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) RpcManager(org.infinispan.remoting.rpc.RpcManager) CheckPoint(org.infinispan.test.fwk.CheckPoint) Cache(org.infinispan.Cache) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Example 12 with RpcManager

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

the class IracVersionUnitTest method mockRpcManager.

private static RpcManager mockRpcManager(String siteName) {
    Transport transport = mockTransport(siteName);
    RpcManager rpcManager = Mockito.mock(RpcManager.class);
    Mockito.when(rpcManager.getTransport()).thenReturn(transport);
    return rpcManager;
}
Also used : RpcManager(org.infinispan.remoting.rpc.RpcManager) Transport(org.infinispan.remoting.transport.Transport)

Example 13 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager 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 14 with RpcManager

use of org.infinispan.remoting.rpc.RpcManager 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 15 with RpcManager

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

the class GlobalTxTable method skipReaper.

private boolean skipReaper(Address originator, ByteString cacheName) {
    ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheName);
    if (cr == null) {
        // cache is stopped? doesn't exist? we need to handle it
        return false;
    }
    RpcManager rpcManager = cr.getComponent(RpcManager.class);
    return // we are not the originator. I
    isRemote(rpcManager, originator) && // originator is still in the view.
    rpcManager.getMembers().contains(originator);
}
Also used : 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