Search in sources :

Example 1 with RpcOptions

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

the class StateConsumerImpl method start.

// Must run after the PersistenceManager
@Start(priority = 20)
public void start() {
    cacheName = cache.wired().getName();
    isInvalidationMode = configuration.clustering().cacheMode().isInvalidation();
    isTransactional = configuration.transaction().transactionMode().isTransactional();
    timeout = configuration.clustering().stateTransfer().timeout();
    numSegments = configuration.clustering().hash().numSegments();
    isFetchEnabled = isFetchEnabled(configuration.persistence().fetchPersistentState());
    rpcOptions = new RpcOptions(DeliverOrder.NONE, timeout, TimeUnit.MILLISECONDS);
    stateRequestExecutor = new LimitedExecutor("StateRequest-" + cacheName, nonBlockingExecutor, 1);
    persistenceManager.addStoreListener(storeChangeListener);
    running = true;
}
Also used : RpcOptions(org.infinispan.remoting.rpc.RpcOptions) LimitedExecutor(org.infinispan.executors.LimitedExecutor) Start(org.infinispan.factories.annotations.Start)

Example 2 with RpcOptions

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

the class TransactionTable method cleanupTimedOutTransactions.

private void cleanupTimedOutTransactions() {
    if (log.isTraceEnabled())
        log.tracef("About to cleanup remote transactions older than %d ms", configuration.transaction().completedTxTimeout());
    long beginning = timeService.time();
    long cutoffCreationTime = beginning - TimeUnit.MILLISECONDS.toNanos(configuration.transaction().completedTxTimeout());
    List<GlobalTransaction> toKill = new ArrayList<>();
    Map<Address, Collection<GlobalTransaction>> toCheck = new HashMap<>();
    // Check remote transactions.
    for (Map.Entry<GlobalTransaction, RemoteTransaction> e : remoteTransactions.entrySet()) {
        GlobalTransaction gtx = e.getKey();
        RemoteTransaction remoteTx = e.getValue();
        // concurrent map doesn't accept null values
        assert remoteTx != null;
        if (log.isTraceEnabled()) {
            log.tracef("Checking transaction %s", gtx);
        }
        // Check the time.
        long creationTime = remoteTx.getCreationTime();
        if (creationTime - cutoffCreationTime >= 0) {
            // transaction still valid
            continue;
        }
        if (transactionOriginatorChecker.isOriginatorMissing(gtx)) {
            // originator no longer available. Transaction can be rolled back.
            long duration = timeService.timeDuration(creationTime, beginning, TimeUnit.MILLISECONDS);
            log.remoteTransactionTimeout(gtx, duration);
            toKill.add(gtx);
        } else {
            // originator alive or hot rod transaction
            Address orig = gtx.getAddress();
            if (rpcManager.getMembers().contains(orig)) {
                // originator still in view. Check if the transaction is valid.
                Collection<GlobalTransaction> addressCheckList = toCheck.computeIfAbsent(orig, k -> new ArrayList<>());
                addressCheckList.add(gtx);
            }
        // else, it is a hot rod transaction. don't kill it since the server reaper will take appropriate action
        }
    }
    // check if the transaction is running on originator
    for (Map.Entry<Address, Collection<GlobalTransaction>> entry : toCheck.entrySet()) {
        CheckTransactionRpcCommand cmd = commandsFactory.buildCheckTransactionRpcCommand(entry.getValue());
        RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
        rpcManager.invokeCommand(entry.getKey(), cmd, CheckTransactionRpcCommand.responseCollector(), rpcOptions).thenAccept(this::killAllTransactionsAsync);
    }
    // Rollback the orphaned transactions and release any held locks.
    killAllTransactionsAsync(toKill);
}
Also used : Address(org.infinispan.remoting.transport.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) CheckTransactionRpcCommand(org.infinispan.commands.remote.CheckTransactionRpcCommand) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Collection(java.util.Collection) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with RpcOptions

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

the class DistAsyncFuncTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    super.createCacheManagers();
    r1 = new ReplListener(c1, true, true);
    r2 = new ReplListener(c2, true, true);
    r3 = new ReplListener(c3, true, true);
    r4 = new ReplListener(c4, true, true);
    r = new ReplListener[] { r1, r2, r3, r4 };
    listenerLookup = new HashMap<>();
    for (ReplListener rl : r) listenerLookup.put(rl.getCache().getCacheManager().getAddress(), rl);
    for (Cache c : caches) {
        TestingUtil.wrapComponent(c, RpcManager.class, original -> new AbstractDelegatingRpcManager(original) {

            @Override
            protected <T> CompletionStage<T> performRequest(Collection<Address> targets, ReplicableCommand command, ResponseCollector<T> collector, Function<ResponseCollector<T>, CompletionStage<T>> invoker, RpcOptions rpcOptions) {
                if (command instanceof SingleRpcCommand) {
                    command = ((SingleRpcCommand) command).getCommand();
                }
                if (command instanceof InvalidateL1Command) {
                    InvalidateL1Command invalidateL1Command = (InvalidateL1Command) command;
                    log.tracef("Sending invalidation %s to %s", command, targets);
                    Collection<Address> realTargets = targets != null ? targets : cacheAddresses;
                    for (Address target : realTargets) {
                        expectedL1Invalidations.computeIfAbsent(target, ignored -> Collections.synchronizedList(new ArrayList<>())).add(invalidateL1Command);
                    }
                }
                return super.performRequest(targets, command, collector, invoker, rpcOptions);
            }
        });
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) ArrayList(java.util.ArrayList) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) AbstractDelegatingRpcManager(org.infinispan.util.AbstractDelegatingRpcManager) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Collection(java.util.Collection) ReplListener(org.infinispan.test.ReplListener) CompletionStage(java.util.concurrent.CompletionStage) Cache(org.infinispan.Cache)

Example 4 with RpcOptions

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

the class BaseDistributionInterceptor method primaryReturnHandler.

protected Object primaryReturnHandler(InvocationContext ctx, AbstractDataWriteCommand command, Object localResult) {
    if (!command.isSuccessful()) {
        if (log.isTraceEnabled())
            log.tracef("Skipping the replication of the conditional command as it did not succeed on primary owner (%s).", command);
        return localResult;
    }
    LocalizedCacheTopology cacheTopology = checkTopologyId(command);
    int segment = SegmentSpecificCommand.extractSegment(command, command.getKey(), keyPartitioner);
    DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(segment);
    Collection<Address> owners = distributionInfo.writeOwners();
    if (owners.size() == 1) {
        // There are no backups, skip the replication part.
        return localResult;
    }
    // Cache the matcher and reset it if we get OOTE (or any other exception) from backup
    ValueMatcher originalMatcher = command.getValueMatcher();
    // Ignore the previous value on the backup owners
    command.setValueMatcher(ValueMatcher.MATCH_ALWAYS);
    if (!isSynchronous(command)) {
        if (isReplicated) {
            rpcManager.sendToAll(command, DeliverOrder.PER_SENDER);
        } else {
            rpcManager.sendToMany(owners, command, DeliverOrder.PER_SENDER);
        }
        // Switch to the retry policy, in case the primary owner changes before we commit locally
        command.setValueMatcher(originalMatcher.matcherForRetry());
        return localResult;
    }
    VoidResponseCollector collector = VoidResponseCollector.ignoreLeavers();
    RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
    // Mark the command as a backup write so it can skip some checks
    command.addFlags(FlagBitSets.BACKUP_WRITE);
    CompletionStage<Void> remoteInvocation = isReplicated ? rpcManager.invokeCommandOnAll(command, collector, rpcOptions) : rpcManager.invokeCommand(owners, command, collector, rpcOptions);
    return asyncValue(remoteInvocation.handle((ignored, t) -> {
        // Unset the backup write bit as the command will be retried
        command.setFlagsBitSet(command.getFlagsBitSet() & ~FlagBitSets.BACKUP_WRITE);
        // Switch to the retry policy, in case the primary owner changed and the write already succeeded on the new primary
        command.setValueMatcher(originalMatcher.matcherForRetry());
        CompletableFutures.rethrowExceptionIfPresent(t);
        return localResult;
    }));
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) Arrays(java.util.Arrays) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) LogFactory(org.infinispan.util.logging.LogFactory) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) GetKeysInGroupCommand(org.infinispan.commands.remote.GetKeysInGroupCommand) InvocationContext(org.infinispan.context.InvocationContext) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) Map(java.util.Map) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) Collection(java.util.Collection) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) List(java.util.List) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) TopologyAffectedCommand(org.infinispan.commands.TopologyAffectedCommand) ArrayCollector(org.infinispan.commons.util.ArrayCollector) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) HashMap(java.util.HashMap) GetAllCommand(org.infinispan.commands.read.GetAllCommand) RemoteValueRetrievedListener(org.infinispan.distribution.RemoteValueRetrievedListener) Function(java.util.function.Function) ReadOnlyKeyCommand(org.infinispan.commands.functional.ReadOnlyKeyCommand) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) FlagBitSets(org.infinispan.context.impl.FlagBitSets) AbstractDataWriteCommand(org.infinispan.commands.write.AbstractDataWriteCommand) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) Log(org.infinispan.util.logging.Log) BiConsumer(java.util.function.BiConsumer) VoidResponseCollector(org.infinispan.remoting.transport.impl.VoidResponseCollector) AbstractDataCommand(org.infinispan.commands.read.AbstractDataCommand) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) ValueMatcher(org.infinispan.commands.write.ValueMatcher) ClearCommand(org.infinispan.commands.write.ClearCommand) Address(org.infinispan.remoting.transport.Address) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) Response(org.infinispan.remoting.responses.Response) ClusteringInterceptor(org.infinispan.interceptors.impl.ClusteringInterceptor) ReplicableCommand(org.infinispan.commands.ReplicableCommand) GetKeyValueCommand(org.infinispan.commands.read.GetKeyValueCommand) CacheEntry(org.infinispan.container.entries.CacheEntry) ValidResponse(org.infinispan.remoting.responses.ValidResponse) Inject(org.infinispan.factories.annotations.Inject) ReadOnlyManyCommand(org.infinispan.commands.functional.ReadOnlyManyCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) GlobalTransaction(org.infinispan.transaction.xa.GlobalTransaction) DistributionInfo(org.infinispan.distribution.DistributionInfo) VisitableCommand(org.infinispan.commands.VisitableCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Collections(java.util.Collections) BaseClusteredReadCommand(org.infinispan.commands.remote.BaseClusteredReadCommand) TimeService(org.infinispan.commons.time.TimeService) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Address(org.infinispan.remoting.transport.Address) ValueMatcher(org.infinispan.commands.write.ValueMatcher) VoidResponseCollector(org.infinispan.remoting.transport.impl.VoidResponseCollector) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) DistributionInfo(org.infinispan.distribution.DistributionInfo)

Example 5 with RpcOptions

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

the class ScatteredDistributionInterceptor method visitClearCommand.

@Override
public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable {
    // local mode clear will have unpredictable results
    svm.clearInvalidations();
    if (ctx.isOriginLocal() && !isLocalModeForced(command)) {
        if (isSynchronous(command)) {
            RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
            MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
            return makeStage(asyncInvokeNext(ctx, command, rpcManager.invokeCommandOnAll(command, collector, rpcOptions))).thenApply(ctx, command, clearHandler);
        } else {
            rpcManager.sendToAll(command, DeliverOrder.PER_SENDER);
            return invokeNextThenApply(ctx, command, clearHandler);
        }
    } else {
        return invokeNextThenApply(ctx, command, clearHandler);
    }
}
Also used : RpcOptions(org.infinispan.remoting.rpc.RpcOptions) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector)

Aggregations

RpcOptions (org.infinispan.remoting.rpc.RpcOptions)19 Address (org.infinispan.remoting.transport.Address)12 Collection (java.util.Collection)9 Map (java.util.Map)9 RpcManager (org.infinispan.remoting.rpc.RpcManager)9 CommandsFactory (org.infinispan.commands.CommandsFactory)8 HashMap (java.util.HashMap)7 CompletionStage (java.util.concurrent.CompletionStage)7 ArrayList (java.util.ArrayList)6 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)6 Response (org.infinispan.remoting.responses.Response)6 Log (org.infinispan.util.logging.Log)6 LogFactory (org.infinispan.util.logging.LogFactory)6 DistributionInfo (org.infinispan.distribution.DistributionInfo)5 Inject (org.infinispan.factories.annotations.Inject)5 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ReplicableCommand (org.infinispan.commands.ReplicableCommand)4 IntSet (org.infinispan.commons.util.IntSet)4 CacheEntry (org.infinispan.container.entries.CacheEntry)4