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;
}
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;
}
}
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;
}
}
}
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;
});
}
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);
}
}));
}
Aggregations