use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.
the class WriteSkewHelper method mergePrepareResponses.
public static void mergePrepareResponses(Response r, PrepareResponse aggregateResponse) {
if (r instanceof PrepareResponse && aggregateResponse != null) {
PrepareResponse remoteRsp = (PrepareResponse) r;
aggregateResponse.merge(remoteRsp);
}
}
use of org.infinispan.remoting.responses.PrepareResponse 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.PrepareResponse in project infinispan by infinispan.
the class TxDistributionInterceptor method prepareOnAffectedNodes.
protected CompletionStage<Object> prepareOnAffectedNodes(TxInvocationContext<?> ctx, PrepareCommand command, Collection<Address> recipients) {
try {
CompletionStage<Map<Address, Response>> remoteInvocation;
if (recipients != null) {
MapResponseCollector collector = MapResponseCollector.ignoreLeavers(recipients.size());
remoteInvocation = rpcManager.invokeCommand(recipients, command, collector, rpcManager.getSyncRpcOptions());
} else {
MapResponseCollector collector = MapResponseCollector.ignoreLeavers(rpcManager.getMembers().size());
remoteInvocation = rpcManager.invokeCommandOnAll(command, collector, rpcManager.getSyncRpcOptions());
}
return remoteInvocation.handle((responses, t) -> {
transactionRemotelyPrepared(ctx);
CompletableFutures.rethrowExceptionIfPresent(t);
PrepareResponse prepareResponse = new PrepareResponse();
checkTxCommandResponses(responses, command, (LocalTxInvocationContext) ctx, recipients, prepareResponse);
for (Response r : responses.values()) mergePrepareResponses(r, prepareResponse);
return prepareResponse;
});
} catch (Throwable t) {
transactionRemotelyPrepared(ctx);
throw t;
}
}
use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.
the class OptimisticTxIracLocalSiteInterceptor method afterRemoteTwoPhasePrepare.
private Object afterRemoteTwoPhasePrepare(InvocationContext ctx, PrepareCommand command, Object rv) {
if (isTraceEnabled()) {
getLog().tracef("[IRAC] After successful remote prepare for tx %s. Return Value: %s", command.getGlobalTransaction(), rv);
}
PrepareResponse rsp = PrepareResponse.asPrepareResponse(rv);
Iterator<StreamData> iterator = streamKeysFromModifications(command.getModifications()).filter(this::isPrimaryOwner).distinct().iterator();
Map<Integer, IracEntryVersion> maxVersionSeen = new HashMap<>();
while (iterator.hasNext()) {
StreamData data = iterator.next();
IracEntryVersion versionSeen = getIracVersionFromCacheEntry(ctx.lookupEntry(data.key));
if (versionSeen != null) {
maxVersionSeen.merge(data.segment, versionSeen, IracEntryVersion::merge);
} else {
maxVersionSeen.putIfAbsent(data.segment, null);
}
}
Map<Integer, IracMetadata> segmentMetadata = new HashMap<>();
maxVersionSeen.forEach((segment, version) -> segmentMetadata.put(segment, iracVersionGenerator.generateNewMetadata(segment, version)));
rsp.setNewIracMetadata(segmentMetadata);
if (isTraceEnabled()) {
getLog().tracef("[IRAC] After successful remote prepare for tx %s. New Return Value: %s", command.getGlobalTransaction(), rsp);
}
return rsp;
}
use of org.infinispan.remoting.responses.PrepareResponse in project infinispan by infinispan.
the class OptimisticTxIracLocalSiteInterceptor method afterLocalTwoPhasePrepare.
private void afterLocalTwoPhasePrepare(InvocationContext ctx, PrepareCommand command, Object rv) {
if (isTraceEnabled()) {
getLog().tracef("[IRAC] After successful local prepare for tx %s. Return Value: %s", command.getGlobalTransaction(), rv);
}
PrepareResponse prepareResponse = asPrepareResponse(rv);
Iterator<StreamData> iterator = streamKeysFromModifications(command.getModifications()).iterator();
Map<Integer, IracMetadata> segmentMetadata = new HashMap<>();
while (iterator.hasNext()) {
StreamData data = iterator.next();
IracMetadata metadata;
if (isPrimaryOwner(data)) {
IracEntryVersion versionSeen = getIracVersionFromCacheEntry(ctx.lookupEntry(data.key));
metadata = segmentMetadata.computeIfAbsent(data.segment, segment -> iracVersionGenerator.generateNewMetadata(segment, versionSeen));
} else {
metadata = segmentMetadata.computeIfAbsent(data.segment, prepareResponse::getIracMetadata);
}
assert metadata != null : "[IRAC] metadata is null after successful prepare! Data=" + data;
updateCommandMetadata(data.key, data.command, metadata);
}
}
Aggregations