Search in sources :

Example 1 with VoidResponseCollector

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

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletionStage (java.util.concurrent.CompletionStage)1 BiConsumer (java.util.function.BiConsumer)1 Function (java.util.function.Function)1 Stream (java.util.stream.Stream)1 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 SegmentSpecificCommand (org.infinispan.commands.SegmentSpecificCommand)1 TopologyAffectedCommand (org.infinispan.commands.TopologyAffectedCommand)1 VisitableCommand (org.infinispan.commands.VisitableCommand)1 ReadOnlyKeyCommand (org.infinispan.commands.functional.ReadOnlyKeyCommand)1 ReadOnlyManyCommand (org.infinispan.commands.functional.ReadOnlyManyCommand)1 AbstractDataCommand (org.infinispan.commands.read.AbstractDataCommand)1 GetAllCommand (org.infinispan.commands.read.GetAllCommand)1