use of org.infinispan.commands.triangle.BackupWriteCommand in project infinispan by infinispan.
the class TrianglePerCacheInboundInvocationHandler method createMultiKeyBackupRunnable.
private BlockingRunnable createMultiKeyBackupRunnable(BackupWriteCommand command, int commandTopologyId, ReadyAction readyAction) {
readyAction.addListener(this::checkForReadyTasks);
return new DefaultTopologyRunnable(this, command, Reply.NO_OP, TopologyMode.READY_TX_DATA, commandTopologyId, false) {
@Override
public boolean isReady() {
return super.isReady() && readyAction.isReady();
}
@Override
protected void onException(Throwable throwable) {
super.onException(throwable);
onBackupException((BackupWriteCommand) command, throwable, readyAction);
}
@Override
protected void afterInvoke() {
super.afterInvoke();
readyAction.onFinally();
BackupWriteCommand backupCommand = (BackupWriteCommand) command;
sendMultiKeyAck(backupCommand.getCommandInvocationId(), commandTopologyId, backupCommand.getSegmentId(), backupCommand.getFlags());
}
};
}
use of org.infinispan.commands.triangle.BackupWriteCommand in project infinispan by infinispan.
the class TrianglePerCacheInboundInvocationHandler method createSingleKeyBackupRunnable.
private BlockingRunnable createSingleKeyBackupRunnable(BackupWriteCommand command, int commandTopologyId, ReadyAction readyAction) {
readyAction.addListener(this::checkForReadyTasks);
return new DefaultTopologyRunnable(this, command, Reply.NO_OP, TopologyMode.READY_TX_DATA, commandTopologyId, false) {
@Override
public boolean isReady() {
return super.isReady() && readyAction.isReady();
}
@Override
protected void onException(Throwable throwable) {
super.onException(throwable);
onBackupException((BackupWriteCommand) command, throwable, readyAction);
}
@Override
protected void afterInvoke() {
super.afterInvoke();
readyAction.onFinally();
BackupWriteCommand backupCommand = (BackupWriteCommand) command;
sendBackupAck(backupCommand.getCommandInvocationId(), commandTopologyId, backupCommand.getFlags());
}
};
}
use of org.infinispan.commands.triangle.BackupWriteCommand 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.triangle.BackupWriteCommand in project infinispan by infinispan.
the class TriangleDistributionInterceptor method sendToBackups.
private <C extends WriteCommand> void sendToBackups(C command, Collection<Object> keysToSend, LocalizedCacheTopology cacheTopology, MultiKeyBackupBuilder<C> backupBuilder) {
int topologyId = command.getTopologyId();
for (Map.Entry<Integer, Collection<Object>> entry : filterBySegment(cacheTopology, keysToSend).entrySet()) {
int segmentId = entry.getKey();
Collection<Address> backups = cacheTopology.getSegmentDistribution(segmentId).writeBackups();
if (backups.isEmpty()) {
// Only the primary owner. Other segments may have more than one owner, e.g. during rebalance.
continue;
}
long sequence = triangleOrderManager.next(segmentId, topologyId);
try {
BackupWriteCommand backupCommand = backupBuilder.build(commandsFactory, command, entry.getValue());
backupCommand.setSequence(sequence);
backupCommand.setSegmentId(segmentId);
if (log.isTraceEnabled()) {
log.tracef("Command %s got sequence %s for segment %s", command.getCommandInvocationId(), segmentId, sequence);
}
rpcManager.sendToMany(backups, backupCommand, DeliverOrder.NONE);
} catch (Throwable t) {
sendBackupNoopCommand(command, backups, segmentId, sequence);
throw t;
}
}
}
Aggregations