use of org.infinispan.remoting.responses.ExceptionResponse 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.ExceptionResponse in project infinispan by infinispan.
the class DistSyncTxL1FuncTest method testGetOccursAfterReplaceRunningBeforeWithRemoteException.
@Test
public void testGetOccursAfterReplaceRunningBeforeWithRemoteException() throws Exception {
final Cache<Object, String> nonOwnerCache = getFirstNonOwner(key);
final Cache<Object, String> ownerCache = getFirstOwner(key);
ownerCache.put(key, firstValue);
CyclicBarrier barrier = new CyclicBarrier(2);
addBlockingInterceptorBeforeTx(nonOwnerCache, barrier, ReplaceCommand.class, false);
ControlledRpcManager controlledRpcManager = ControlledRpcManager.replaceRpcManager(nonOwnerCache);
try {
// The replace will internally block the get until it gets the remote value
Future<Boolean> futureReplace = fork(() -> nonOwnerCache.replace(key, firstValue, secondValue));
barrier.await(5, TimeUnit.SECONDS);
Future<String> futureGet = fork(() -> nonOwnerCache.get(key));
// The get will blocks locally on the L1WriteSynchronizer registered by the replace command
TestingUtil.assertNotDone(futureGet);
controlledRpcManager.expectNoCommand();
// Continue the replace
barrier.await(5, TimeUnit.SECONDS);
// That also unblocks the get command and allows it to perform the remote get
controlledRpcManager.expectCommand(ClusteredGetCommand.class).skipSend().receive(address(ownerCache), new ExceptionResponse(new TestException()));
Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureReplace);
Exceptions.expectExecutionException(RemoteException.class, TestException.class, futureGet);
} finally {
removeAllBlockingInterceptorsFromCache(nonOwnerCache);
controlledRpcManager.revertRpcManager();
}
}
use of org.infinispan.remoting.responses.ExceptionResponse in project infinispan by infinispan.
the class JGroupsTransport method processRequest.
private void processRequest(org.jgroups.Address src, short flags, byte[] buffer, int offset, int length, long requestId) {
try {
DeliverOrder deliverOrder = decodeDeliverMode(flags);
if (src.equals(((JGroupsAddress) getAddress()).getJGroupsAddress())) {
// DISCARD ignores the DONT_LOOPBACK flag, see https://issues.jboss.org/browse/JGRP-2205
if (log.isTraceEnabled())
log.tracef("Ignoring request %d from self without total order", requestId);
return;
}
ReplicableCommand command = (ReplicableCommand) marshaller.objectFromByteBuffer(buffer, offset, length);
Reply reply;
if (requestId != Request.NO_REQUEST_ID) {
if (log.isTraceEnabled())
log.tracef("%s received request %d from %s: %s", getAddress(), requestId, src, command);
reply = response -> sendResponse(src, response, requestId, command);
} else {
if (log.isTraceEnabled())
log.tracef("%s received command from %s: %s", getAddress(), src, command);
reply = Reply.NO_OP;
}
if (src instanceof SiteAddress) {
String originSite = ((SiteAddress) src).getSite();
XSiteReplicateCommand<?> xsiteCommand = (XSiteReplicateCommand<?>) command;
xsiteCommand.setOriginSite(originSite);
invocationHandler.handleFromRemoteSite(originSite, xsiteCommand, reply, deliverOrder);
} else {
invocationHandler.handleFromCluster(fromJGroupsAddress(src), command, reply, deliverOrder);
}
} catch (Throwable t) {
CLUSTER.errorProcessingRequest(requestId, src, t);
Exception e = t instanceof Exception ? ((Exception) t) : new CacheException(t);
sendResponse(src, new ExceptionResponse(e), requestId, null);
}
}
use of org.infinispan.remoting.responses.ExceptionResponse in project infinispan by infinispan.
the class GlobalInboundInvocationHandler method handleFromRemoteSite.
@Override
public void handleFromRemoteSite(String origin, XSiteReplicateCommand<?> command, Reply reply, DeliverOrder order) {
if (log.isTraceEnabled()) {
log.tracef("Handling command %s from remote site %s", command, origin);
}
LocalSiteCache localCache = findLocalCacheForRemoteSite(origin, command.getCacheName());
if (localCache == null) {
reply.reply(new ExceptionResponse(log.xsiteCacheNotFound(origin, command.getCacheName())));
return;
} else if (localCache.local) {
reply.reply(new ExceptionResponse(log.xsiteInLocalCache(origin, localCache.cacheName)));
return;
}
ComponentRegistry cr = globalComponentRegistry.getNamedComponentRegistry(localCache.cacheName);
if (cr == null) {
reply.reply(new ExceptionResponse(log.xsiteCacheNotStarted(origin, localCache.cacheName)));
return;
}
cr.getComponent(XSiteMetricsCollector.class).recordRequestsReceived(origin);
command.performInLocalSite(cr, order.preserveOrder()).whenComplete(new ResponseConsumer(command, reply));
}
use of org.infinispan.remoting.responses.ExceptionResponse 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