use of org.infinispan.remoting.transport.impl.VoidResponseCollector in project infinispan by infinispan.
the class BaseDistributionInterceptor method primaryReturnHandler.
protected Object primaryReturnHandler(InvocationContext ctx, AbstractDataWriteCommand command, Object localResult) {
if (!command.isSuccessful()) {
if (log.isTraceEnabled())
log.tracef("Skipping the replication of the conditional command as it did not succeed on primary owner (%s).", command);
return localResult;
}
LocalizedCacheTopology cacheTopology = checkTopologyId(command);
int segment = SegmentSpecificCommand.extractSegment(command, command.getKey(), keyPartitioner);
DistributionInfo distributionInfo = cacheTopology.getSegmentDistribution(segment);
Collection<Address> owners = distributionInfo.writeOwners();
if (owners.size() == 1) {
// There are no backups, skip the replication part.
return localResult;
}
// Cache the matcher and reset it if we get OOTE (or any other exception) from backup
ValueMatcher originalMatcher = command.getValueMatcher();
// Ignore the previous value on the backup owners
command.setValueMatcher(ValueMatcher.MATCH_ALWAYS);
if (!isSynchronous(command)) {
if (isReplicated) {
rpcManager.sendToAll(command, DeliverOrder.PER_SENDER);
} else {
rpcManager.sendToMany(owners, command, DeliverOrder.PER_SENDER);
}
// Switch to the retry policy, in case the primary owner changes before we commit locally
command.setValueMatcher(originalMatcher.matcherForRetry());
return localResult;
}
VoidResponseCollector collector = VoidResponseCollector.ignoreLeavers();
RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
// Mark the command as a backup write so it can skip some checks
command.addFlags(FlagBitSets.BACKUP_WRITE);
CompletionStage<Void> remoteInvocation = isReplicated ? rpcManager.invokeCommandOnAll(command, collector, rpcOptions) : rpcManager.invokeCommand(owners, command, collector, rpcOptions);
return asyncValue(remoteInvocation.handle((ignored, t) -> {
// Unset the backup write bit as the command will be retried
command.setFlagsBitSet(command.getFlagsBitSet() & ~FlagBitSets.BACKUP_WRITE);
// Switch to the retry policy, in case the primary owner changed and the write already succeeded on the new primary
command.setValueMatcher(originalMatcher.matcherForRetry());
CompletableFutures.rethrowExceptionIfPresent(t);
return localResult;
}));
}
Aggregations