Search in sources :

Example 1 with CacheNotFoundResponse

use of org.infinispan.remoting.responses.CacheNotFoundResponse 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 2 with CacheNotFoundResponse

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

the class ScatteredDistributionInterceptor method handleReadCommand.

private Object handleReadCommand(InvocationContext ctx, AbstractDataCommand command) throws Throwable {
    LocalizedCacheTopology cacheTopology = checkTopology(command);
    // SKIP_OWNERSHIP_CHECK is added when the entry is prefetched from remote node
    // TODO [rvansa]: local lookup and hinted read, see improvements in package-info
    CacheEntry entry = ctx.lookupEntry(command.getKey());
    if (entry != null) {
        return invokeNext(ctx, command);
    }
    DistributionInfo info = cacheTopology.getSegmentDistribution(command.getSegment());
    if (info.isPrimary()) {
        if (log.isTraceEnabled()) {
            log.tracef("In topology %d this is primary owner", cacheTopology.getTopologyId());
        }
        return invokeNext(ctx, command);
    } else if (command.hasAnyFlag(FlagBitSets.SKIP_OWNERSHIP_CHECK)) {
        if (log.isTraceEnabled()) {
            log.trace("Ignoring ownership");
        }
        return invokeNext(ctx, command);
    } else if (info.primary() == null) {
        throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
    } else if (ctx.isOriginLocal()) {
        if (isLocalModeForced(command) || command.hasAnyFlag(FlagBitSets.SKIP_REMOTE_LOOKUP)) {
            entryFactory.wrapExternalEntry(ctx, command.getKey(), NullCacheEntry.getInstance(), false, false);
            return invokeNext(ctx, command);
        }
        ClusteredGetCommand clusteredGetCommand = cf.buildClusteredGetCommand(command.getKey(), info.segmentId(), command.getFlagsBitSet());
        clusteredGetCommand.setTopologyId(command.getTopologyId());
        ResponseCollector<Response> collector = PassthroughSingleResponseCollector.INSTANCE;
        CompletionStage<Response> rpcFuture = rpcManager.invokeCommand(info.primary(), clusteredGetCommand, collector, rpcManager.getSyncRpcOptions());
        Object key = clusteredGetCommand.getKey();
        return asyncInvokeNext(ctx, command, rpcFuture.thenAccept(response -> {
            if (response.isSuccessful()) {
                InternalCacheValue value = (InternalCacheValue) ((SuccessfulResponse) response).getResponseValue();
                if (value != null) {
                    InternalCacheEntry cacheEntry = value.toInternalCacheEntry(key);
                    entryFactory.wrapExternalEntry(ctx, key, cacheEntry, true, false);
                } else {
                    entryFactory.wrapExternalEntry(ctx, key, NullCacheEntry.getInstance(), false, false);
                }
            } else if (response instanceof UnsureResponse) {
                throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
            } else if (response instanceof CacheNotFoundResponse) {
                throw AllOwnersLostException.INSTANCE;
            } else if (response instanceof ExceptionResponse) {
                throw ResponseCollectors.wrapRemoteException(info.primary(), ((ExceptionResponse) response).getException());
            } else {
                throw new IllegalArgumentException("Unexpected response " + response);
            }
        }));
    } else {
        return UnsureResponse.INSTANCE;
    }
}
Also used : ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) DistributionInfo(org.infinispan.distribution.DistributionInfo) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CompletionStage(java.util.concurrent.CompletionStage) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage)

Example 3 with CacheNotFoundResponse

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

the class TxDistributionInterceptor method checkTxCommandResponses.

protected void checkTxCommandResponses(Map<Address, Response> responseMap, TransactionBoundaryCommand command, TxInvocationContext<LocalTransaction> context, Collection<Address> recipients, PrepareResponse prepareResponse) {
    LocalizedCacheTopology cacheTopology = checkTopologyId(command);
    for (Map.Entry<Address, Response> e : responseMap.entrySet()) {
        Address recipient = e.getKey();
        Response response = e.getValue();
        mergePrepareResponses(response, prepareResponse);
        if (response == CacheNotFoundResponse.INSTANCE) {
            // We must not register a partial commit when receiving a CacheNotFoundResponse from one of those.
            if (!cacheTopology.getMembers().contains(recipient)) {
                if (log.isTraceEnabled())
                    log.tracef("Ignoring response from node not targeted %s", recipient);
            } else {
                if (checkCacheNotFoundResponseInPartitionHandling(command, context, recipients)) {
                    if (log.isTraceEnabled())
                        log.tracef("Cache not running on node %s, or the node is missing. It will be handled by the PartitionHandlingManager", recipient);
                    return;
                } else {
                    if (log.isTraceEnabled())
                        log.tracef("Cache not running on node %s, or the node is missing", recipient);
                    throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
                }
            }
        } else if (response == UnsureResponse.INSTANCE) {
            if (log.isTraceEnabled())
                log.tracef("Node %s has a newer topology id", recipient);
            throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
        }
    }
}
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) Address(org.infinispan.remoting.transport.Address) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CacheNotFoundResponse

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

the class InboundTransferTask method startTransfer.

/**
 * Request the segments from the source
 *
 * @return A {@code CompletionStage} that completes when the segments have been applied
 */
private CompletionStage<Void> startTransfer(Function<IntSet, CacheRpcCommand> transferCommand) {
    if (isCancelled)
        return completionFuture;
    IntSet segmentsCopy = getSegments();
    if (segmentsCopy.isEmpty()) {
        if (log.isTraceEnabled())
            log.tracef("Segments list is empty, skipping source %s", source);
        completionFuture.complete(null);
        return completionFuture;
    }
    CacheRpcCommand cmd = transferCommand.apply(segmentsCopy);
    if (log.isTraceEnabled()) {
        log.tracef("Requesting state (%s) from node %s for segments %s", cmd, source, segmentsCopy);
    }
    CompletionStage<Response> remoteStage = rpcManager.invokeCommand(source, cmd, PassthroughSingleResponseCollector.INSTANCE, rpcOptions);
    return handleAndCompose(remoteStage, (response, throwable) -> {
        if (throwable != null) {
            if (!isCancelled) {
                log.failedToRequestSegments(cacheName, source, segmentsCopy, throwable);
                completionFuture.completeExceptionally(throwable);
            }
        } else if (response instanceof SuccessfulResponse) {
            if (log.isTraceEnabled()) {
                log.tracef("Successfully requested state (%s) from node %s for segments %s", cmd, source, segmentsCopy);
            }
        } else if (response instanceof CacheNotFoundResponse) {
            if (log.isTraceEnabled())
                log.tracef("State source %s was suspected, another source will be selected", source);
            completionFuture.completeExceptionally(new SuspectException());
        } else {
            Exception e = new CacheException(String.valueOf(response));
            log.failedToRequestSegments(cacheName, source, segmentsCopy, e);
            completionFuture.completeExceptionally(e);
        }
        return completionFuture;
    });
}
Also used : Response(org.infinispan.remoting.responses.Response) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) CacheException(org.infinispan.commons.CacheException) IntSet(org.infinispan.commons.util.IntSet) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) CacheException(org.infinispan.commons.CacheException) CancellationException(java.util.concurrent.CancellationException) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException)

Example 5 with CacheNotFoundResponse

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

the class ScatteredDistributionInterceptor method visitReadOnlyKeyCommand.

@Override
public Object visitReadOnlyKeyCommand(InvocationContext ctx, ReadOnlyKeyCommand command) throws Throwable {
    Object key = command.getKey();
    CacheEntry entry = ctx.lookupEntry(key);
    if (entry != null) {
        // the entry is owned locally (it is NullCacheEntry if it was not found), no need to go remote
        return invokeNext(ctx, command);
    }
    if (!ctx.isOriginLocal()) {
        return UnsureResponse.INSTANCE;
    }
    if (isLocalModeForced(command) || command.hasAnyFlag(FlagBitSets.SKIP_REMOTE_LOOKUP)) {
        if (ctx.lookupEntry(command.getKey()) == null) {
            entryFactory.wrapExternalEntry(ctx, command.getKey(), NullCacheEntry.getInstance(), false, false);
        }
        return invokeNext(ctx, command);
    }
    DistributionInfo info = checkTopology(command).getDistribution(command.getKey());
    if (info.primary() == null) {
        throw AllOwnersLostException.INSTANCE;
    }
    ResponseCollector<Response> collector = PassthroughSingleResponseCollector.INSTANCE;
    CompletionStage<Response> rpc = rpcManager.invokeCommand(info.primary(), command, collector, rpcManager.getSyncRpcOptions());
    return asyncValue(rpc.thenApply(response -> {
        if (response.isSuccessful()) {
            return ((SuccessfulResponse) response).getResponseValue();
        } else if (response instanceof UnsureResponse) {
            throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
        } else if (response instanceof CacheNotFoundResponse) {
            throw AllOwnersLostException.INSTANCE;
        } else if (response instanceof ExceptionResponse) {
            throw ResponseCollectors.wrapRemoteException(info.primary(), ((ExceptionResponse) response).getException());
        } else {
            throw new IllegalArgumentException("Unexpected response " + response);
        }
    }));
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsuccessfulResponse(org.infinispan.remoting.responses.UnsuccessfulResponse) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) ValidResponse(org.infinispan.remoting.responses.ValidResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) Response(org.infinispan.remoting.responses.Response) 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) RemoteMetadata(org.infinispan.container.entries.RemoteMetadata) ClusteredGetAllCommand(org.infinispan.commands.remote.ClusteredGetAllCommand) Map(java.util.Map) RemoveCommand(org.infinispan.commands.write.RemoveCommand) ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) EmbeddedMetadata(org.infinispan.metadata.EmbeddedMetadata) ReadWriteManyEntriesCommand(org.infinispan.commands.functional.ReadWriteManyEntriesCommand) UnsuccessfulResponse(org.infinispan.remoting.responses.UnsuccessfulResponse) Set(java.util.Set) GroupManager(org.infinispan.distribution.group.impl.GroupManager) CacheTopology(org.infinispan.topology.CacheTopology) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) DONT_LOAD(org.infinispan.commands.VisitableCommand.LoadType.DONT_LOAD) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) AbstractVisitor(org.infinispan.commands.AbstractVisitor) ArrayCollector(org.infinispan.commons.util.ArrayCollector) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntryRemoved(org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) ComputeCommand(org.infinispan.commands.write.ComputeCommand) MetadataAwareCommand(org.infinispan.commands.MetadataAwareCommand) EvictionManager(org.infinispan.eviction.EvictionManager) ReadOnlyKeyCommand(org.infinispan.commands.functional.ReadOnlyKeyCommand) ArrayList(java.util.ArrayList) WriteOnlyManyEntriesCommand(org.infinispan.commands.functional.WriteOnlyManyEntriesCommand) Start(org.infinispan.factories.annotations.Start) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) PassthroughSingleResponseCollector(org.infinispan.remoting.transport.impl.PassthroughSingleResponseCollector) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) FunctionalNotifier(org.infinispan.functional.impl.FunctionalNotifier) ValueMatcher(org.infinispan.commands.write.ValueMatcher) ClearCommand(org.infinispan.commands.write.ClearCommand) Address(org.infinispan.remoting.transport.Address) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) CacheEntry(org.infinispan.container.entries.CacheEntry) NotifyHelper(org.infinispan.notifications.cachelistener.NotifyHelper) WriteOnlyKeyValueCommand(org.infinispan.commands.functional.WriteOnlyKeyValueCommand) ValidResponse(org.infinispan.remoting.responses.ValidResponse) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) ReadWriteKeyCommand(org.infinispan.commands.functional.ReadWriteKeyCommand) ReadWriteManyCommand(org.infinispan.commands.functional.ReadWriteManyCommand) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) EntryVersion(org.infinispan.container.versioning.EntryVersion) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) MultiTargetCollector(org.infinispan.util.concurrent.CommandAckCollector.MultiTargetCollector) GetKeysInGroupCommand(org.infinispan.commands.remote.GetKeysInGroupCommand) ActivationManager(org.infinispan.eviction.impl.ActivationManager) RepeatableReadEntry(org.infinispan.container.entries.RepeatableReadEntry) InvocationContext(org.infinispan.context.InvocationContext) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ReadWriteKeyValueCommand(org.infinispan.commands.functional.ReadWriteKeyValueCommand) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) DataOperationOrderer(org.infinispan.util.concurrent.DataOperationOrderer) InequalVersionComparisonResult(org.infinispan.container.versioning.InequalVersionComparisonResult) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) List(java.util.List) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector) InvocationFinallyAction(org.infinispan.interceptors.InvocationFinallyAction) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) TopologyAffectedCommand(org.infinispan.commands.TopologyAffectedCommand) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Metadata(org.infinispan.metadata.Metadata) CompletionStages(org.infinispan.util.concurrent.CompletionStages) GetAllCommand(org.infinispan.commands.read.GetAllCommand) Function(java.util.function.Function) AllOwnersLostException(org.infinispan.statetransfer.AllOwnersLostException) FlagBitSets(org.infinispan.context.impl.FlagBitSets) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) Log(org.infinispan.util.logging.Log) AbstractDataCommand(org.infinispan.commands.read.AbstractDataCommand) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) MetadataImmortalCacheValue(org.infinispan.container.entries.metadata.MetadataImmortalCacheValue) ResponseCollectors(org.infinispan.remoting.transport.ResponseCollectors) Response(org.infinispan.remoting.responses.Response) ClusteringInterceptor(org.infinispan.interceptors.impl.ClusteringInterceptor) GetKeyValueCommand(org.infinispan.commands.read.GetKeyValueCommand) CacheException(org.infinispan.commons.CacheException) Iterator(java.util.Iterator) EvictCommand(org.infinispan.commands.write.EvictCommand) WriteOnlyManyCommand(org.infinispan.commands.functional.WriteOnlyManyCommand) PutMapCommand(org.infinispan.commands.write.PutMapCommand) ReadOnlyManyCommand(org.infinispan.commands.functional.ReadOnlyManyCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) Operation(org.infinispan.util.concurrent.DataOperationOrderer.Operation) WriteOnlyKeyCommand(org.infinispan.commands.functional.WriteOnlyKeyCommand) VisitableCommand(org.infinispan.commands.VisitableCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Collections(java.util.Collections) TimeService(org.infinispan.commons.time.TimeService) ScatteredVersionManager(org.infinispan.scattered.ScatteredVersionManager) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) NullCacheEntry(org.infinispan.container.entries.NullCacheEntry) MetadataImmortalCacheEntry(org.infinispan.container.entries.metadata.MetadataImmortalCacheEntry) DistributionInfo(org.infinispan.distribution.DistributionInfo)

Aggregations

CacheNotFoundResponse (org.infinispan.remoting.responses.CacheNotFoundResponse)6 Response (org.infinispan.remoting.responses.Response)4 SuccessfulResponse (org.infinispan.remoting.responses.SuccessfulResponse)4 Map (java.util.Map)3 ExceptionResponse (org.infinispan.remoting.responses.ExceptionResponse)3 UnsureResponse (org.infinispan.remoting.responses.UnsureResponse)3 ValidResponse (org.infinispan.remoting.responses.ValidResponse)3 HashMap (java.util.HashMap)2 CompletionStage (java.util.concurrent.CompletionStage)2 CacheException (org.infinispan.commons.CacheException)2 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)2 Address (org.infinispan.remoting.transport.Address)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 CancellationException (java.util.concurrent.CancellationException)1