use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.
the class RecoveryManagerImpl method forceTransactionCompletionFromCluster.
@Override
public String forceTransactionCompletionFromCluster(XidImpl xid, Address where, boolean commit) {
CompleteTransactionCommand ctc = commandFactory.buildCompleteTransactionCommand(xid, commit);
CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommand(where, ctc, MapResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
Map<Address, Response> responseMap = rpcManager.blocking(completionStage);
if (responseMap.size() != 1 || responseMap.get(where) == null) {
log.expectedJustOneResponse(responseMap);
throw new CacheException("Expected response size is 1, received " + responseMap);
}
// noinspection rawtypes
return (String) ((SuccessfulResponse) responseMap.get(where)).getResponseValue();
}
use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.
the class RecoveryManagerImpl method getInDoubtTransactionInfoFromCluster.
@Override
public Set<InDoubtTxInfo> getInDoubtTransactionInfoFromCluster() {
Map<XidImpl, InDoubtTxInfo> result = new HashMap<>();
if (rpcManager != null) {
GetInDoubtTxInfoCommand inDoubtTxInfoCommand = commandFactory.buildGetInDoubtTxInfoCommand();
CompletionStage<Map<Address, Response>> completionStage = rpcManager.invokeCommandOnAll(inDoubtTxInfoCommand, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions());
Map<Address, Response> addressResponseMap = rpcManager.blocking(completionStage);
for (Map.Entry<Address, Response> re : addressResponseMap.entrySet()) {
Response r = re.getValue();
if (!isSuccessful(r)) {
throw new CacheException("Could not fetch in doubt transactions: " + r);
}
// noinspection unchecked
Set<InDoubtTxInfo> infoInDoubtSet = ((SuccessfulResponse<Set<InDoubtTxInfo>>) r).getResponseValue();
for (InDoubtTxInfo infoInDoubt : infoInDoubtSet) {
InDoubtTxInfo inDoubtTxInfo = result.get(infoInDoubt.getXid());
if (inDoubtTxInfo == null) {
inDoubtTxInfo = infoInDoubt;
result.put(infoInDoubt.getXid(), inDoubtTxInfo);
} else {
inDoubtTxInfo.setStatus(infoInDoubt.getStatus());
}
inDoubtTxInfo.addOwner(re.getKey());
}
}
}
Set<InDoubtTxInfo> onThisNode = getInDoubtTransactionInfo();
Iterator<InDoubtTxInfo> iterator = onThisNode.iterator();
while (iterator.hasNext()) {
InDoubtTxInfo info = iterator.next();
InDoubtTxInfo inDoubtTxInfo = result.get(info.getXid());
if (inDoubtTxInfo != null) {
inDoubtTxInfo.setLocal(true);
iterator.remove();
} else {
info.setLocal(true);
}
}
HashSet<InDoubtTxInfo> value = new HashSet<>(result.values());
value.addAll(onThisNode);
return value;
}
use of org.infinispan.remoting.responses.SuccessfulResponse 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.SuccessfulResponse in project infinispan by infinispan.
the class BaseDistributionInterceptor method visitGetKeysInGroupCommand.
@Override
public final Object visitGetKeysInGroupCommand(InvocationContext ctx, GetKeysInGroupCommand command) throws Throwable {
if (command.isGroupOwner()) {
// don't go remote if we are an owner.
return invokeNext(ctx, command);
}
Address primaryOwner = distributionManager.getCacheTopology().getDistribution(command.getGroupName()).primary();
CompletionStage<ValidResponse> future = rpcManager.invokeCommand(primaryOwner, command, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
return asyncInvokeNext(ctx, command, future.thenAccept(response -> {
if (response instanceof SuccessfulResponse) {
// noinspection unchecked
List<CacheEntry> cacheEntries = (List<CacheEntry>) response.getResponseValue();
for (CacheEntry entry : cacheEntries) {
wrapRemoteEntry(ctx, entry.getKey(), entry, false);
}
}
}));
}
use of org.infinispan.remoting.responses.SuccessfulResponse in project infinispan by infinispan.
the class TxDistributionInterceptor method handleTxFunctionalCommand.
public <C extends AbstractDataWriteCommand & FunctionalCommand> Object handleTxFunctionalCommand(InvocationContext ctx, C command) {
Object key = command.getKey();
if (ctx.isOriginLocal()) {
CacheEntry entry = ctx.lookupEntry(key);
if (entry == null) {
if (command.hasAnyFlag(SKIP_REMOTE_FLAGS) || command.loadType() == VisitableCommand.LoadType.DONT_LOAD) {
entryFactory.wrapExternalEntry(ctx, key, null, false, true);
return invokeNext(ctx, command);
}
LocalizedCacheTopology cacheTopology = checkTopologyId(command);
int segment = command.getSegment();
DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(segment);
// we could have stale value after state transfer.
if (distributionInfo.isWriteOwner() || forceRemoteReadForFunctionalCommands && !command.hasAnyFlag(FlagBitSets.SKIP_XSITE_BACKUP)) {
return asyncInvokeNext(ctx, command, remoteGetSingleKey(ctx, command, key, true));
}
List<Mutation<Object, Object, ?>> mutationsOnKey = getMutationsOnKey((TxInvocationContext) ctx, command, key);
mutationsOnKey.add(command.toMutation(key));
TxReadOnlyKeyCommand remoteRead = commandsFactory.buildTxReadOnlyKeyCommand(key, null, mutationsOnKey, segment, command.getParams(), command.getKeyDataConversion(), command.getValueDataConversion());
remoteRead.setTopologyId(command.getTopologyId());
CompletionStage<SuccessfulResponse> remoteGet = rpcManager.invokeCommandStaggered(distributionInfo.readOwners(), remoteRead, new RemoteGetSingleKeyCollector(), rpcManager.getSyncRpcOptions());
return asyncValue(remoteGet).thenApply(ctx, command, (rCtx, rCommand, response) -> {
Object responseValue = ((SuccessfulResponse) response).getResponseValue();
return unwrapFunctionalResultOnOrigin(rCtx, rCommand.getKey(), responseValue);
});
}
// It's possible that this is not an owner, but the entry was loaded from L1 - let the command run
return invokeNext(ctx, command);
} else {
if (!checkTopologyId(command).isWriteOwner(key)) {
return null;
}
CacheEntry entry = ctx.lookupEntry(key);
if (entry == null) {
if (command.hasAnyFlag(SKIP_REMOTE_FLAGS) || command.loadType() == VisitableCommand.LoadType.DONT_LOAD) {
// in transactional mode, we always need the entry wrapped
entryFactory.wrapExternalEntry(ctx, key, null, false, true);
} else {
return asyncInvokeNext(ctx, command, remoteGetSingleKey(ctx, command, command.getKey(), true));
}
}
return invokeNextThenApply(ctx, command, (rCtx, rCommand, rv) -> wrapFunctionalResultOnNonOriginOnReturn(rv, entry));
}
}
Aggregations