use of org.infinispan.commands.remote.ClusteredGetCommand 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.commands.remote.ClusteredGetCommand in project infinispan by infinispan.
the class AnchoredFetchInterceptor method getRemoteValue.
private CompletionStage<CacheEntry<K, V>> getRemoteValue(Address keyLocation, K key, Integer segment, boolean isWrite) {
ClusteredGetCommand getCommand = cf.buildClusteredGetCommand(key, segment, FlagBitSets.SKIP_OWNERSHIP_CHECK);
getCommand.setTopologyId(0);
getCommand.setWrite(isWrite);
FetchResponseCollector<K, V> collector = new FetchResponseCollector<>(key);
return rpcManager.invokeCommand(keyLocation, getCommand, collector, rpcManager.getSyncRpcOptions());
}
use of org.infinispan.commands.remote.ClusteredGetCommand in project infinispan by infinispan.
the class VersionAwareMarshallerTest method testReplicableCommandsMarshalling.
public void testReplicableCommandsMarshalling() throws Exception {
ByteString cacheName = ByteString.fromString(TestingUtil.getDefaultCacheName(cm));
ClusteredGetCommand c2 = new ClusteredGetCommand("key", cacheName, 0, EnumUtil.EMPTY_BIT_SET);
marshallAndAssertEquality(c2);
// SizeCommand does not have an empty constructor, so doesn't look to be one that is marshallable.
GetKeyValueCommand c4 = new GetKeyValueCommand("key", 0, EnumUtil.EMPTY_BIT_SET);
marshallAndAssertEquality(c4);
PutKeyValueCommand c5 = new PutKeyValueCommand("k", "v", false, new EmbeddedMetadata.Builder().build(), 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
marshallAndAssertEquality(c5);
RemoveCommand c6 = new RemoveCommand("key", null, 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
marshallAndAssertEquality(c6);
// EvictCommand does not have an empty constructor, so doesn't look to be one that is marshallable.
InvalidateCommand c7 = new InvalidateCommand(EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null), "key1", "key2");
marshallAndAssertEquality(c7);
InvalidateCommand c71 = new InvalidateL1Command(EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null), "key1", "key2");
marshallAndAssertEquality(c71);
ReplaceCommand c8 = new ReplaceCommand("key", "oldvalue", "newvalue", new EmbeddedMetadata.Builder().build(), 0, EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
marshallAndAssertEquality(c8);
ClearCommand c9 = new ClearCommand();
marshallAndAssertEquality(c9);
Map<Integer, GlobalTransaction> m1 = new HashMap<>();
for (int i = 0; i < 10; i++) {
GlobalTransaction gtx = gtf.newGlobalTransaction(new JGroupsAddress(UUID.randomUUID()), false);
m1.put(1000 * i, gtx);
}
PutMapCommand c10 = new PutMapCommand(m1, new EmbeddedMetadata.Builder().build(), EnumUtil.EMPTY_BIT_SET, CommandInvocationId.generateId(null));
marshallAndAssertEquality(c10);
Address local = new JGroupsAddress(UUID.randomUUID());
GlobalTransaction gtx = gtf.newGlobalTransaction(local, false);
PrepareCommand c11 = new PrepareCommand(cacheName, gtx, true, c5, c6, c8, c10);
marshallAndAssertEquality(c11);
CommitCommand c12 = new CommitCommand(cacheName, gtx);
marshallAndAssertEquality(c12);
RollbackCommand c13 = new RollbackCommand(cacheName, gtx);
marshallAndAssertEquality(c13);
}
use of org.infinispan.commands.remote.ClusteredGetCommand in project infinispan by infinispan.
the class RpcManagerTest method testInvokeCommandCollection.
public void testInvokeCommandCollection() throws Exception {
ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L);
RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager();
Exceptions.expectException(IllegalArgumentException.class, () -> rpcManager0.invokeCommand(Arrays.asList(address(0)), command, SingleResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions()));
command.setTopologyId(rpcManager0.getTopologyId());
CompletionStage<Map<Address, Response>> stage1 = rpcManager0.invokeCommand(Arrays.asList(address(0)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
assertResponse(Collections.emptyMap(), stage1);
CompletionStage<Map<Address, Response>> stage2 = rpcManager0.invokeCommand(Arrays.asList(address(1)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
assertResponse(Collections.singletonMap(address(1), SUCCESSFUL_EMPTY_RESPONSE), stage2);
CompletionStage<Map<Address, Response>> stage3 = rpcManager0.invokeCommand(Arrays.asList(address(0), address(1)), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
assertResponse(Collections.singletonMap(address(1), SUCCESSFUL_EMPTY_RESPONSE), stage3);
}
use of org.infinispan.commands.remote.ClusteredGetCommand in project infinispan by infinispan.
the class RpcManagerTest method testInvokeCommandCollectionSuspect.
public void testInvokeCommandCollectionSuspect() throws Exception {
ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L);
RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager();
command.setTopologyId(rpcManager0.getTopologyId());
CompletionStage<Map<Address, Response>> stage1 = rpcManager0.invokeCommand(Arrays.asList(SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
Exceptions.expectExecutionException(SuspectException.class, stage1.toCompletableFuture());
CompletionStage<Map<Address, Response>> stage2 = rpcManager0.invokeCommand(Arrays.asList(address(0), SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
Exceptions.expectExecutionException(SuspectException.class, stage2.toCompletableFuture());
CompletionStage<Map<Address, Response>> stage3 = rpcManager0.invokeCommand(Arrays.asList(address(0), address(1), SUSPECT), command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
Exceptions.expectExecutionException(SuspectException.class, stage3.toCompletableFuture());
}
Aggregations