Search in sources :

Example 1 with SuccessfulResponse

use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.

the class RecoveryManagerImpl method forceTransactionCompletionFromCluster.

@Override
public String forceTransactionCompletionFromCluster(XidImpl xid, Address where, boolean commit) {
    CompleteTransactionCommand ctc = commandFactory.buildCompleteTransactionCommand(xid, commit);
    CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommand(where, ctc, MapResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
    Map<Address, Response> responseMap = rpcManager.blocking(completionStage);
    if (responseMap.size() != 1 || responseMap.get(where) == null) {
        log.expectedJustOneResponse(responseMap);
        throw new CacheException("Expected response size is 1, received " + responseMap);
    }
    // noinspection rawtypes
    return (String) ((SuccessfulResponse) responseMap.get(where)).getResponseValue();
}
Also used : CompleteTransactionCommand(org.infinispan.commands.remote.recovery.CompleteTransactionCommand) Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) CacheException(org.infinispan.commons.CacheException) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 2 with SuccessfulResponse

use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.

the class RecoveryManagerImpl method getInDoubtTransactionInfoFromCluster.

@Override
public Set<InDoubtTxInfo> getInDoubtTransactionInfoFromCluster() {
    Map<XidImpl, InDoubtTxInfo> result = new HashMap<>();
    if (rpcManager != null) {
        GetInDoubtTxInfoCommand inDoubtTxInfoCommand = commandFactory.buildGetInDoubtTxInfoCommand();
        CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommandOnAll(inDoubtTxInfoCommand, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
        Map<Address, Response> addressResponseMap = rpcManager.blocking(completionStage);
        for (Map.Entry<Address, Response> re : addressResponseMap.entrySet()) {
            Response r = re.getValue();
            if (!isSuccessful(r)) {
                throw new CacheException("Could not fetch in doubt transactions: " + r);
            }
            // noinspection unchecked
            Set<InDoubtTxInfo> infoInDoubtSet = ((SuccessfulResponse<Set<InDoubtTxInfo>>) r).getResponseValue();
            for (InDoubtTxInfo infoInDoubt : infoInDoubtSet) {
                InDoubtTxInfo inDoubtTxInfo = result.get(infoInDoubt.getXid());
                if (inDoubtTxInfo == null) {
                    inDoubtTxInfo = infoInDoubt;
                    result.put(infoInDoubt.getXid(), inDoubtTxInfo);
                } else {
                    inDoubtTxInfo.setStatus(infoInDoubt.getStatus());
                }
                inDoubtTxInfo.addOwner(re.getKey());
            }
        }
    }
    Set<InDoubtTxInfo> onThisNode = getInDoubtTransactionInfo();
    Iterator<InDoubtTxInfo> iterator = onThisNode.iterator();
    while (iterator.hasNext()) {
        InDoubtTxInfo info = iterator.next();
        InDoubtTxInfo inDoubtTxInfo = result.get(info.getXid());
        if (inDoubtTxInfo != null) {
            inDoubtTxInfo.setLocal(true);
            iterator.remove();
        } else {
            info.setLocal(true);
        }
    }
    HashSet<InDoubtTxInfo> value = new HashSet<>(result.values());
    value.addAll(onThisNode);
    return value;
}
Also used : SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) CacheException(org.infinispan.commons.CacheException) XidImpl(org.infinispan.commons.tx.XidImpl) Response(org.infinispan.remoting.responses.Response) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) GetInDoubtTxInfoCommand(org.infinispan.commands.remote.recovery.GetInDoubtTxInfoCommand) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with SuccessfulResponse

use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.

the class ClusteringInterceptor method getSuccessfulResponseOrFail.

protected static SuccessfulResponse getSuccessfulResponseOrFail(Map<Address, Response> responseMap, CompletableFuture<?> future, Consumer<Response> cacheNotFound) {
    Iterator<Map.Entry<Address, Response>> it = responseMap.entrySet().iterator();
    if (!it.hasNext()) {
        future.completeExceptionally(AllOwnersLostException.INSTANCE);
        return null;
    }
    Map.Entry<Address, Response> e = it.next();
    Address sender = e.getKey();
    Response response = e.getValue();
    if (it.hasNext()) {
        future.completeExceptionally(new IllegalStateException("Too many responses " + responseMap));
    } else if (response instanceof SuccessfulResponse) {
        return (SuccessfulResponse) response;
    } else if (response instanceof CacheNotFoundResponse || response instanceof UnsureResponse) {
        if (cacheNotFound == null) {
            future.completeExceptionally(unexpected(sender, response));
        } else {
            try {
                cacheNotFound.accept(response);
            } catch (Throwable t) {
                future.completeExceptionally(t);
            }
        }
    } else {
        future.completeExceptionally(unexpected(sender, response));
    }
    return null;
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) Response(org.infinispan.remoting.responses.Response) ValidResponse(org.infinispan.remoting.responses.ValidResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) Map(java.util.Map)

Example 4 with SuccessfulResponse

use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.

the class BaseDistributionInterceptor method visitGetKeysInGroupCommand.

@Override
public final Object visitGetKeysInGroupCommand(InvocationContext ctx, GetKeysInGroupCommand command) throws Throwable {
    if (command.isGroupOwner()) {
        // don't go remote if we are an owner.
        return invokeNext(ctx, command);
    }
    Address primaryOwner = distributionManager.getCacheTopology().getDistribution(command.getGroupName()).primary();
    CompletionStage<ValidResponse> future = rpcManager.invokeCommand(primaryOwner, command, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
    return asyncInvokeNext(ctx, command, future.thenAccept(response -> {
        if (response instanceof SuccessfulResponse) {
            // noinspection unchecked
            List<CacheEntry> cacheEntries = (List<CacheEntry>) response.getResponseValue();
            for (CacheEntry entry : cacheEntries) {
                wrapRemoteEntry(ctx, entry.getKey(), entry, false);
            }
        }
    }));
}
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) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) Address(org.infinispan.remoting.transport.Address) ValidResponse(org.infinispan.remoting.responses.ValidResponse) List(java.util.List) ArrayList(java.util.ArrayList) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry)

Example 5 with SuccessfulResponse

use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.

the class TxDistributionInterceptor method handleTxFunctionalCommand.

public <C extends AbstractDataWriteCommand & FunctionalCommand> Object handleTxFunctionalCommand(InvocationContext ctx, C command) {
    Object key = command.getKey();
    if (ctx.isOriginLocal()) {
        CacheEntry entry = ctx.lookupEntry(key);
        if (entry == null) {
            if (command.hasAnyFlag(SKIP_REMOTE_FLAGS) || command.loadType() == VisitableCommand.LoadType.DONT_LOAD) {
                entryFactory.wrapExternalEntry(ctx, key, null, false, true);
                return invokeNext(ctx, command);
            }
            LocalizedCacheTopology cacheTopology = checkTopologyId(command);
            int segment = command.getSegment();
            DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(segment);
            // we could have stale value after state transfer.
            if (distributionInfo.isWriteOwner() || forceRemoteReadForFunctionalCommands && !command.hasAnyFlag(FlagBitSets.SKIP_XSITE_BACKUP)) {
                return asyncInvokeNext(ctx, command, remoteGetSingleKey(ctx, command, key, true));
            }
            List<Mutation<Object, Object, ?>> mutationsOnKey = getMutationsOnKey((TxInvocationContext) ctx, command, key);
            mutationsOnKey.add(command.toMutation(key));
            TxReadOnlyKeyCommand remoteRead = commandsFactory.buildTxReadOnlyKeyCommand(key, null, mutationsOnKey, segment, command.getParams(), command.getKeyDataConversion(), command.getValueDataConversion());
            remoteRead.setTopologyId(command.getTopologyId());
            CompletionStage<SuccessfulResponse> remoteGet = rpcManager.invokeCommandStaggered(distributionInfo.readOwners(), remoteRead, new RemoteGetSingleKeyCollector(), rpcManager.getSyncRpcOptions());
            return asyncValue(remoteGet).thenApply(ctx, command, (rCtx, rCommand, response) -> {
                Object responseValue = ((SuccessfulResponse) response).getResponseValue();
                return unwrapFunctionalResultOnOrigin(rCtx, rCommand.getKey(), responseValue);
            });
        }
        // It's possible that this is not an owner, but the entry was loaded from L1 - let the command run
        return invokeNext(ctx, command);
    } else {
        if (!checkTopologyId(command).isWriteOwner(key)) {
            return null;
        }
        CacheEntry entry = ctx.lookupEntry(key);
        if (entry == null) {
            if (command.hasAnyFlag(SKIP_REMOTE_FLAGS) || command.loadType() == VisitableCommand.LoadType.DONT_LOAD) {
                // in transactional mode, we always need the entry wrapped
                entryFactory.wrapExternalEntry(ctx, key, null, false, true);
            } else {
                return asyncInvokeNext(ctx, command, remoteGetSingleKey(ctx, command, command.getKey(), true));
            }
        }
        return invokeNextThenApply(ctx, command, (rCtx, rCommand, rv) -> wrapFunctionalResultOnNonOriginOnReturn(rv, entry));
    }
}
Also used : SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) TxReadOnlyKeyCommand(org.infinispan.commands.functional.TxReadOnlyKeyCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Mutation(org.infinispan.commands.functional.Mutation) CacheEntry(org.infinispan.container.entries.CacheEntry) DistributionInfo(org.infinispan.distribution.DistributionInfo)

Aggregations

SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)22 Address (org.infinispan.remoting.transport.Address)16 Response (org.infinispan.remoting.responses.Response)15 Map (java.util.Map)11 HashMap (java.util.HashMap)8 CacheException (org.infinispan.commons.CacheException)7 CacheEntry (org.infinispan.container.entries.CacheEntry)7 InternalCacheValue (org.infinispan.container.entries.InternalCacheValue)7 InternalCacheEntry (org.infinispan.container.entries.InternalCacheEntry)6 CacheNotFoundResponse (org.infinispan.remoting.responses.CacheNotFoundResponse)6 UnsureResponse (org.infinispan.remoting.responses.UnsureResponse)6 ValidResponse (org.infinispan.remoting.responses.ValidResponse)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 CompletionStage (java.util.concurrent.CompletionStage)5 NullCacheEntry (org.infinispan.container.entries.NullCacheEntry)5 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 ReadOnlyKeyCommand (org.infinispan.commands.functional.ReadOnlyKeyCommand)4