use of org.infinispan.commands.read.GetAllCommand in project infinispan by infinispan.
the class CacheMgmtInterceptorTest method testVisitGetAllCommand.
public void testVisitGetAllCommand() throws Throwable {
GetAllCommand command = new GetAllCommand(Collections.singleton(KEY), 0, false);
InvocationStage stage = makeStage(interceptor.visitGetAllCommand(ctx, command));
assertFalse(stage.isDone());
timeService.advance(1);
nextInterceptor.completeLastInvocation(Collections.emptyMap());
assertEquals(Collections.emptyMap(), stage.get());
assertEquals(1, interceptor.getAverageReadTime());
}
use of org.infinispan.commands.read.GetAllCommand in project infinispan by infinispan.
the class ScatteredDistributionInterceptor method visitGetAllCommand.
@Override
public Object visitGetAllCommand(InvocationContext ctx, GetAllCommand command) throws Throwable {
LocalizedCacheTopology cacheTopology = checkTopology(command);
if (command.hasAnyFlag(FlagBitSets.CACHE_MODE_LOCAL | FlagBitSets.SKIP_REMOTE_LOOKUP | FlagBitSets.SKIP_OWNERSHIP_CHECK)) {
return invokeNext(ctx, command);
}
if (ctx.isOriginLocal()) {
Map<Address, List<Object>> remoteKeys = new HashMap<>();
for (Object key : command.getKeys()) {
if (ctx.lookupEntry(key) != null) {
continue;
}
DistributionInfo info = cacheTopology.getDistribution(key);
if (info.primary() == null) {
throw OutdatedTopologyException.RETRY_NEXT_TOPOLOGY;
} else if (!info.isPrimary()) {
remoteKeys.computeIfAbsent(info.primary(), k -> new ArrayList<>()).add(key);
}
}
if (remoteKeys.isEmpty()) {
return invokeNext(ctx, command);
}
ClusteredGetAllFuture sync = new ClusteredGetAllFuture(remoteKeys.size());
for (Map.Entry<Address, List<Object>> remote : remoteKeys.entrySet()) {
List<Object> keys = remote.getValue();
ClusteredGetAllCommand clusteredGetAllCommand = cf.buildClusteredGetAllCommand(keys, command.getFlagsBitSet(), null);
clusteredGetAllCommand.setTopologyId(command.getTopologyId());
SingletonMapResponseCollector collector = SingletonMapResponseCollector.ignoreLeavers();
CompletionStage<Map<Address, Response>> rpcFuture = rpcManager.invokeCommand(remote.getKey(), clusteredGetAllCommand, collector, rpcManager.getSyncRpcOptions());
rpcFuture.whenComplete(((responseMap, throwable) -> handleGetAllResponse(responseMap, throwable, ctx, keys, sync)));
}
return asyncInvokeNext(ctx, command, sync);
} else {
// remote
for (Object key : command.getKeys()) {
if (ctx.lookupEntry(key) == null) {
return UnsureResponse.INSTANCE;
}
}
return invokeNext(ctx, command);
}
}
use of org.infinispan.commands.read.GetAllCommand in project infinispan by infinispan.
the class EntryWrappingInterceptor method getAllHandle.
private Object getAllHandle(InvocationContext rCtx, GetAllCommand command, Object rv, Throwable t) {
if (useRepeatableRead) {
for (Object key : command.getKeys()) {
CacheEntry cacheEntry = rCtx.lookupEntry(key);
if (cacheEntry == null) {
// Data was lost
if (log.isTraceEnabled())
log.tracef(t, "Missing entry for " + key);
} else {
cacheEntry.setSkipLookup(true);
}
}
}
AggregateCompletionStage<Void> stage = CompletionStages.aggregateCompletionStage();
// instanceof check excludes the case when the command returns UnsuccessfulResponse
if (t == null && rv instanceof Map) {
boolean notify = !command.hasAnyFlag(FlagBitSets.SKIP_LISTENER_NOTIFICATION) && notifier.hasListener(CacheEntryVisited.class);
log.tracef("Notifying getAll? %s; result %s", notify, rv);
if (notify) {
Map<Object, Object> map = (Map<Object, Object>) rv;
for (Map.Entry<Object, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value != null) {
Object finalValue = command.isReturnEntries() ? ((CacheEntry) value).getValue() : entry.getValue();
CompletionStage<Void> innerStage = notifier.notifyCacheEntryVisited(entry.getKey(), finalValue, true, rCtx, command);
stage.dependsOn(innerStage.thenCompose(ig -> notifier.notifyCacheEntryVisited(entry.getKey(), finalValue, false, rCtx, command)));
}
}
}
}
return delayedValue(stage.freeze(), rv, t);
}
use of org.infinispan.commands.read.GetAllCommand in project infinispan by infinispan.
the class CacheImpl method getAllCacheEntries.
public final Map<K, CacheEntry<K, V>> getAllCacheEntries(Set<?> keys, long explicitFlags, InvocationContext ctx) {
GetAllCommand command = commandsFactory.buildGetAllCommand(keys, explicitFlags, true);
Map<K, CacheEntry<K, V>> map = invocationHelper.invoke(ctx, command);
map.entrySet().removeIf(entry -> entry.getValue() == null);
return map;
}
use of org.infinispan.commands.read.GetAllCommand in project infinispan by infinispan.
the class ClusteredGetAllCommand method invokeGetAll.
private CompletionStage<Object> invokeGetAll(ComponentRegistry cr) {
// make sure the get command doesn't perform a remote call
// as our caller is already calling the ClusteredGetCommand on all the relevant nodes
GetAllCommand command = cr.getCommandsFactory().buildGetAllCommand(keys, getFlagsBitSet(), true);
command.setTopologyId(topologyId);
InvocationContext invocationContext = cr.getInvocationContextFactory().running().createRemoteInvocationContextForCommand(command, getOrigin());
CompletionStage<Object> future = cr.getInterceptorChain().running().invokeAsync(invocationContext, command);
return future.thenApply(rv -> {
if (log.isTraceEnabled())
log.trace("Found: " + rv);
if (rv == null || rv instanceof Response) {
return rv;
}
Map<K, CacheEntry<K, V>> map = (Map<K, CacheEntry<K, V>>) rv;
InternalCacheValue<V>[] values = new InternalCacheValue[keys.size()];
int i = 0;
for (Object key : keys) {
CacheEntry<K, V> entry = map.get(key);
InternalCacheValue<V> value;
if (entry == null) {
value = null;
} else if (entry instanceof InternalCacheEntry) {
value = ((InternalCacheEntry<K, V>) entry).toInternalCacheValue();
} else {
value = cr.getInternalEntryFactory().running().createValue(entry);
value.setInternalMetadata(entry.getInternalMetadata());
}
values[i++] = value;
}
return values;
});
}
Aggregations