Search in sources :

Example 1 with BackupWriteCommand

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());
        }
    };
}
Also used : MultiEntriesFunctionalBackupWriteCommand(org.infinispan.commands.triangle.MultiEntriesFunctionalBackupWriteCommand) SingleKeyBackupWriteCommand(org.infinispan.commands.triangle.SingleKeyBackupWriteCommand) PutMapBackupWriteCommand(org.infinispan.commands.triangle.PutMapBackupWriteCommand) MultiKeyFunctionalBackupWriteCommand(org.infinispan.commands.triangle.MultiKeyFunctionalBackupWriteCommand) SingleKeyFunctionalBackupWriteCommand(org.infinispan.commands.triangle.SingleKeyFunctionalBackupWriteCommand) BackupWriteCommand(org.infinispan.commands.triangle.BackupWriteCommand)

Example 2 with BackupWriteCommand

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());
        }
    };
}
Also used : MultiEntriesFunctionalBackupWriteCommand(org.infinispan.commands.triangle.MultiEntriesFunctionalBackupWriteCommand) SingleKeyBackupWriteCommand(org.infinispan.commands.triangle.SingleKeyBackupWriteCommand) PutMapBackupWriteCommand(org.infinispan.commands.triangle.PutMapBackupWriteCommand) MultiKeyFunctionalBackupWriteCommand(org.infinispan.commands.triangle.MultiKeyFunctionalBackupWriteCommand) SingleKeyFunctionalBackupWriteCommand(org.infinispan.commands.triangle.SingleKeyFunctionalBackupWriteCommand) BackupWriteCommand(org.infinispan.commands.triangle.BackupWriteCommand)

Example 3 with BackupWriteCommand

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;
    }
}
Also used : BackupWriteCommand(org.infinispan.commands.triangle.BackupWriteCommand) CommandInvocationId(org.infinispan.commands.CommandInvocationId)

Example 4 with BackupWriteCommand

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;
        }
    }
}
Also used : Address(org.infinispan.remoting.transport.Address) Collection(java.util.Collection) BackupWriteCommand(org.infinispan.commands.triangle.BackupWriteCommand) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BackupWriteCommand (org.infinispan.commands.triangle.BackupWriteCommand)4 MultiEntriesFunctionalBackupWriteCommand (org.infinispan.commands.triangle.MultiEntriesFunctionalBackupWriteCommand)2 MultiKeyFunctionalBackupWriteCommand (org.infinispan.commands.triangle.MultiKeyFunctionalBackupWriteCommand)2 PutMapBackupWriteCommand (org.infinispan.commands.triangle.PutMapBackupWriteCommand)2 SingleKeyBackupWriteCommand (org.infinispan.commands.triangle.SingleKeyBackupWriteCommand)2 SingleKeyFunctionalBackupWriteCommand (org.infinispan.commands.triangle.SingleKeyFunctionalBackupWriteCommand)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CommandInvocationId (org.infinispan.commands.CommandInvocationId)1 Address (org.infinispan.remoting.transport.Address)1