use of org.infinispan.commands.CommandInvocationId in project infinispan by infinispan.
the class TriangleDistributionInterceptor method localWriteInvocation.
private Object localWriteInvocation(InvocationContext context, DataWriteCommand command, DistributionInfo distributionInfo) {
assert context.isOriginLocal();
final CommandInvocationId invocationId = command.getCommandInvocationId();
final boolean sync = isSynchronous(command);
if (sync || command.isReturnValueExpected() && !command.hasAnyFlag(FlagBitSets.PUT_FOR_EXTERNAL_READ)) {
final int topologyId = command.getTopologyId();
Collector<Object> collector = commandAckCollector.create(invocationId.getId(), sync ? distributionInfo.writeBackups() : Collections.emptyList(), topologyId);
try {
// check the topology after registering the collector.
// if we don't, the collector may wait forever (==timeout) for non-existing acknowledges.
checkTopologyId(topologyId, collector);
forwardToPrimary(command, distributionInfo, collector);
return asyncValue(collector.getFuture());
} catch (Throwable t) {
collector.primaryException(t);
throw t;
}
} else {
rpcManager.sendTo(distributionInfo.primary(), command, DeliverOrder.NONE);
return null;
}
}
use of org.infinispan.commands.CommandInvocationId in project infinispan by infinispan.
the class TriangleDistributionInterceptor method remotePrimaryOwnerWrite.
private <C extends DataWriteCommand> Object remotePrimaryOwnerWrite(InvocationContext context, C command, final DistributionInfo distributionInfo, BackupBuilder<C> backupBuilder) {
// we are the primary owner. we need to execute the command, check if successful, send to backups and reply to originator is needed.
if (command.hasAnyFlag(FlagBitSets.COMMAND_RETRY)) {
command.setValueMatcher(command.getValueMatcher().matcherForRetry());
}
return invokeNextThenApply(context, command, (rCtx, rCommand, rv) -> {
// noinspection unchecked
final C dwCommand = (C) rCommand;
final CommandInvocationId id = dwCommand.getCommandInvocationId();
Collection<Address> backupOwners = distributionInfo.writeBackups();
if (!dwCommand.isSuccessful() || backupOwners.isEmpty()) {
if (log.isTraceEnabled()) {
log.tracef("Command %s not successful in primary owner.", id);
}
return rv;
}
sendToBackups(distributionInfo.segmentId(), dwCommand, backupOwners, backupBuilder);
return rv;
});
}
use of org.infinispan.commands.CommandInvocationId in project infinispan by infinispan.
the class TriangleDistributionInterceptor method localPrimaryOwnerWrite.
private <C extends DataWriteCommand> Object localPrimaryOwnerWrite(InvocationContext context, C command, DistributionInfo distributionInfo, BackupBuilder<C> backupBuilder) {
if (command.hasAnyFlag(FlagBitSets.COMMAND_RETRY)) {
command.setValueMatcher(command.getValueMatcher().matcherForRetry());
}
return invokeNextThenApply(context, command, (rCtx, rCommand, rv) -> {
// noinspection unchecked
final C dwCommand = (C) rCommand;
final CommandInvocationId id = dwCommand.getCommandInvocationId();
Collection<Address> backupOwners = distributionInfo.writeBackups();
if (!dwCommand.isSuccessful() || backupOwners.isEmpty()) {
if (log.isTraceEnabled()) {
log.tracef("Not sending command %s to backups", id);
}
return rv;
}
final int topologyId = dwCommand.getTopologyId();
final boolean sync = isSynchronous(dwCommand);
if (sync || dwCommand.isReturnValueExpected()) {
Collector<Object> collector = commandAckCollector.create(id.getId(), sync ? backupOwners : Collections.emptyList(), topologyId);
try {
// check the topology after registering the collector.
// if we don't, the collector may wait forever (==timeout) for non-existing acknowledges.
checkTopologyId(topologyId, collector);
sendToBackups(distributionInfo.segmentId(), dwCommand, backupOwners, backupBuilder);
collector.primaryResult(rv, true);
} catch (Throwable t) {
collector.primaryException(t);
}
return asyncValue(collector.getFuture());
} else {
sendToBackups(distributionInfo.segmentId(), dwCommand, backupOwners, backupBuilder);
return rv;
}
});
}
use of org.infinispan.commands.CommandInvocationId in project infinispan by infinispan.
the class TriangleDistributionInterceptor method sendToBackups.
private <C extends DataWriteCommand> void sendToBackups(int segmentId, C command, Collection<Address> backupOwners, BackupBuilder<C> backupBuilder) {
CommandInvocationId id = command.getCommandInvocationId();
if (log.isTraceEnabled()) {
log.tracef("Command %s send to backup owner %s.", id, backupOwners);
}
long sequenceNumber = triangleOrderManager.next(segmentId, command.getTopologyId());
try {
BackupWriteCommand backupCommand = backupBuilder.build(commandsFactory, command);
backupCommand.setSequence(sequenceNumber);
backupCommand.setSegmentId(segmentId);
if (log.isTraceEnabled()) {
log.tracef("Command %s got sequence %s for segment %s", id, sequenceNumber, segmentId);
}
// TODO Should we use sendToAll in replicated mode?
// we must send the message only after the collector is registered in the map
rpcManager.sendToMany(backupOwners, backupCommand, DeliverOrder.NONE);
} catch (Throwable t) {
sendBackupNoopCommand(command, backupOwners, segmentId, sequenceNumber);
throw t;
}
}
use of org.infinispan.commands.CommandInvocationId in project infinispan by infinispan.
the class CacheNotifierImpl method setSource.
private void setSource(EventImpl<K, V> e, InvocationContext ctx, FlagAffectedCommand command) {
if (ctx != null && ctx.isInTxScope()) {
GlobalTransaction tx = ((TxInvocationContext) ctx).getGlobalTransaction();
e.setSource(tx);
} else if (command instanceof WriteCommand) {
CommandInvocationId invocationId = ((WriteCommand) command).getCommandInvocationId();
e.setSource(invocationId);
}
}
Aggregations