Search in sources :

Example 1 with MapResponseCollector

use of org.infinispan.remoting.transport.impl.MapResponseCollector 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)

Example 2 with MapResponseCollector

use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.

the class TxDistributionInterceptor method prepareOnAffectedNodes.

protected CompletionStage<Object> prepareOnAffectedNodes(TxInvocationContext<?> ctx, PrepareCommand command, Collection<Address> recipients) {
    try {
        CompletionStage<Map<Address, Response>> remoteInvocation;
        if (recipients != null) {
            MapResponseCollector collector = MapResponseCollector.ignoreLeavers(recipients.size());
            remoteInvocation = rpcManager.invokeCommand(recipients, command, collector, rpcManager.getSyncRpcOptions());
        } else {
            MapResponseCollector collector = MapResponseCollector.ignoreLeavers(rpcManager.getMembers().size());
            remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
        }
        return remoteInvocation.handle((responses, t) -> {
            transactionRemotelyPrepared(ctx);
            CompletableFutures.rethrowExceptionIfPresent(t);
            PrepareResponse prepareResponse = new PrepareResponse();
            checkTxCommandResponses(responses, command, (LocalTxInvocationContext) ctx, recipients, prepareResponse);
            for (Response r : responses.values()) mergePrepareResponses(r, prepareResponse);
            return prepareResponse;
        });
    } catch (Throwable t) {
        transactionRemotelyPrepared(ctx);
        throw t;
    }
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Response(org.infinispan.remoting.responses.Response) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) Map(java.util.Map) HashMap(java.util.HashMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Example 3 with MapResponseCollector

use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.

the class AnchoredDistributionInterceptor method primaryReturnHandler.

@Override
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);
    DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(command.getSegment());
    Collection<Address> owners = distributionInfo.writeOwners();
    if (owners.size() == 1) {
        // There are no backups, skip the replication part.
        return localResult;
    }
    // Match always on the backups, but save the original matcher for retries
    ValueMatcher originalMatcher = command.getValueMatcher();
    command.setValueMatcher(ValueMatcher.MATCH_ALWAYS);
    CommandCopier commandCopier = new CommandCopier(ctx, command);
    // Ignore the previous value on the backup owners
    assert isSynchronous(command);
    MapResponseCollector collector = MapResponseCollector.ignoreLeavers(isReplicated, owners.size());
    RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
    CompletionStage<Map<Address, Response>> remoteInvocation = rpcManager.invokeCommands(distributionInfo.writeBackups(), commandCopier, collector, rpcOptions);
    return asyncValue(remoteInvocation.handle((responses, t) -> {
        // 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 instanceof RemoteException ? t.getCause() : t);
        return localResult;
    }));
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) AbstractVisitor(org.infinispan.commands.AbstractVisitor) LogFactory(org.infinispan.util.logging.LogFactory) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) HashMap(java.util.HashMap) Metadata(org.infinispan.metadata.Metadata) Function(java.util.function.Function) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) AbstractDataWriteCommand(org.infinispan.commands.write.AbstractDataWriteCommand) InvocationContext(org.infinispan.context.InvocationContext) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Map(java.util.Map) Log(org.infinispan.util.logging.Log) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) ValueMatcher(org.infinispan.commands.write.ValueMatcher) Address(org.infinispan.remoting.transport.Address) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Response(org.infinispan.remoting.responses.Response) RemoveCommand(org.infinispan.commands.write.RemoveCommand) WriteManyCommandHelper(org.infinispan.interceptors.distribution.WriteManyCommandHelper) CommandsFactory(org.infinispan.commands.CommandsFactory) ReplicableCommand(org.infinispan.commands.ReplicableCommand) CacheException(org.infinispan.commons.CacheException) CacheEntry(org.infinispan.container.entries.CacheEntry) Collection(java.util.Collection) PutMapCommand(org.infinispan.commands.write.PutMapCommand) Inject(org.infinispan.factories.annotations.Inject) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) NonTxDistributionInterceptor(org.infinispan.interceptors.distribution.NonTxDistributionInterceptor) DistributionInfo(org.infinispan.distribution.DistributionInfo) VisitableCommand(org.infinispan.commands.VisitableCommand) RemoteException(org.infinispan.remoting.RemoteException) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Address(org.infinispan.remoting.transport.Address) ValueMatcher(org.infinispan.commands.write.ValueMatcher) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) RemoteException(org.infinispan.remoting.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) DistributionInfo(org.infinispan.distribution.DistributionInfo) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Example 4 with MapResponseCollector

use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.

the class L1ManagerImpl method flushCache.

@Override
public CompletableFuture<?> flushCache(Collection<Object> keys, Address origin, boolean assumeOriginKeptEntryInL1) {
    final Collection<Address> invalidationAddresses = buildInvalidationAddressList(keys, origin, assumeOriginKeptEntryInL1);
    int nodes = invalidationAddresses.size();
    if (nodes > 0) {
        InvalidateCommand ic = commandsFactory.buildInvalidateFromL1Command(origin, EnumUtil.EMPTY_BIT_SET, keys);
        final SingleRpcCommand rpcCommand = commandsFactory.buildSingleRpcCommand(ic);
        // No need to invalidate at all if there is no one to invalidate!
        boolean multicast = isUseMulticast(nodes);
        if (log.isTraceEnabled())
            log.tracef("Invalidating keys %s on nodes %s. Use multicast? %s", keys, invalidationAddresses, multicast);
        // L1 invalidations can ignore a member leaving while sending invalidation
        MapResponseCollector collector = MapResponseCollector.ignoreLeavers();
        CompletionStage<Map<Address, Response>> request;
        if (multicast) {
            request = rpcManager.invokeCommandOnAll(rpcCommand, collector, rpcManager.getSyncRpcOptions());
        } else {
            request = rpcManager.invokeCommand(invalidationAddresses, rpcCommand, collector, rpcManager.getSyncRpcOptions());
        }
        return request.toCompletableFuture();
    } else {
        if (log.isTraceEnabled())
            log.tracef("No L1 caches to invalidate for keys %s", keys);
        return null;
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) SingleRpcCommand(org.infinispan.commands.remote.SingleRpcCommand) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Example 5 with MapResponseCollector

use of org.infinispan.remoting.transport.impl.MapResponseCollector in project infinispan by infinispan.

the class MockTransport method invokeRemotelyAsync.

@Override
public CompletableFuture<Map<Address, Response>> invokeRemotelyAsync(Collection<Address> recipients, ReplicableCommand rpcCommand, ResponseMode mode, long timeout, ResponseFilter responseFilter, DeliverOrder deliverOrder, boolean anycast) {
    Collection<Address> targets = recipients != null ? recipients : members;
    MapResponseCollector collector = mode.isSynchronous() ? MapResponseCollector.ignoreLeavers(shouldIgnoreLeavers(mode), targets.size()) : null;
    return blockRequest(recipients, rpcCommand, collector);
}
Also used : MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector)

Aggregations

MapResponseCollector (org.infinispan.remoting.transport.impl.MapResponseCollector)11 Map (java.util.Map)8 HashMap (java.util.HashMap)5 Address (org.infinispan.remoting.transport.Address)5 Collection (java.util.Collection)3 CompletionStage (java.util.concurrent.CompletionStage)3 CommandsFactory (org.infinispan.commands.CommandsFactory)3 VisitableCommand (org.infinispan.commands.VisitableCommand)3 AbstractDataWriteCommand (org.infinispan.commands.write.AbstractDataWriteCommand)3 PrepareResponse (org.infinispan.remoting.responses.PrepareResponse)3 LocalTransaction (org.infinispan.transaction.impl.LocalTransaction)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BiFunction (java.util.function.BiFunction)2 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)2 SegmentSpecificCommand (org.infinispan.commands.SegmentSpecificCommand)2