Search in sources :

Example 1 with TouchMode

use of org.infinispan.expiration.TouchMode in project infinispan by infinispan.

the class ClusteringInterceptor method visitTouchCommand.

@Override
public Object visitTouchCommand(InvocationContext ctx, TouchCommand command) throws Throwable {
    if (command.hasAnyFlag(FlagBitSets.CACHE_MODE_LOCAL | FlagBitSets.SKIP_REMOTE_LOOKUP)) {
        return invokeNext(ctx, command);
    }
    LocalizedCacheTopology cacheTopology = checkTopologyId(command);
    DistributionInfo info = cacheTopology.getSegmentDistribution(command.getSegment());
    // Scattered any node could be a backup, so we have to touch all members
    List<Address> owners = isScattered ? cacheTopology.getActualMembers() : info.readOwners();
    if (touchMode == TouchMode.ASYNC) {
        if (ctx.isOriginLocal()) {
            // Send to all the owners
            rpcManager.sendToMany(owners, command, DeliverOrder.NONE);
        }
        return invokeNext(ctx, command);
    }
    if (info.isPrimary()) {
        AbstractTouchResponseCollector collector = isScattered ? ScatteredTouchResponseCollector.INSTANCE : TouchResponseCollector.INSTANCE;
        CompletionStage<Boolean> remoteInvocation = rpcManager.invokeCommand(owners, command, collector, rpcManager.getSyncRpcOptions());
        return invokeNextThenApply(ctx, command, (rCtx, rCommand, rValue) -> {
            Boolean touchedLocally = (Boolean) rValue;
            if (touchedLocally) {
                return asyncValue(remoteInvocation);
            }
            // If primary can't touch - it doesn't matter about others
            return Boolean.FALSE;
        });
    } else if (ctx.isOriginLocal()) {
        // Send to the primary owner
        CompletionStage<ValidResponse> remoteInvocation = rpcManager.invokeCommand(info.primary(), command, SingleResponseCollector.validOnly(), rpcManager.getSyncRpcOptions());
        return asyncValue(remoteInvocation).thenApply(ctx, command, (rCtx, rCommand, rResponse) -> ((ValidResponse) rResponse).getResponseValue());
    }
    return invokeNext(ctx, command);
}
Also used : CacheNotFoundResponse(org.infinispan.remoting.responses.CacheNotFoundResponse) UnsureResponse(org.infinispan.remoting.responses.UnsureResponse) CompletableFuture(java.util.concurrent.CompletableFuture) AllOwnersLostException(org.infinispan.statetransfer.AllOwnersLostException) LockManager(org.infinispan.util.concurrent.locks.LockManager) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InvocationContext(org.infinispan.context.InvocationContext) SingleResponseCollector(org.infinispan.remoting.transport.impl.SingleResponseCollector) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) Map(java.util.Map) Address(org.infinispan.remoting.transport.Address) Response(org.infinispan.remoting.responses.Response) CommandsFactory(org.infinispan.commands.CommandsFactory) CacheException(org.infinispan.commons.CacheException) Iterator(java.util.Iterator) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) ValidResponseCollector(org.infinispan.remoting.transport.ValidResponseCollector) TouchMode(org.infinispan.expiration.TouchMode) ValidResponse(org.infinispan.remoting.responses.ValidResponse) EntryFactory(org.infinispan.container.impl.EntryFactory) Inject(org.infinispan.factories.annotations.Inject) Consumer(java.util.function.Consumer) List(java.util.List) TouchCommand(org.infinispan.expiration.impl.TouchCommand) CompletionStage(java.util.concurrent.CompletionStage) SuccessfulResponse(org.infinispan.remoting.responses.SuccessfulResponse) CLUSTER(org.infinispan.util.logging.Log.CLUSTER) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) DistributionInfo(org.infinispan.distribution.DistributionInfo) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) TopologyAffectedCommand(org.infinispan.commands.TopologyAffectedCommand) DistributionManager(org.infinispan.distribution.DistributionManager) Address(org.infinispan.remoting.transport.Address) ValidResponse(org.infinispan.remoting.responses.ValidResponse) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) DistributionInfo(org.infinispan.distribution.DistributionInfo) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Consumer (java.util.function.Consumer)1 CommandsFactory (org.infinispan.commands.CommandsFactory)1 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)1 TopologyAffectedCommand (org.infinispan.commands.TopologyAffectedCommand)1 CacheException (org.infinispan.commons.CacheException)1 EntryFactory (org.infinispan.container.impl.EntryFactory)1 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)1 InvocationContext (org.infinispan.context.InvocationContext)1 FlagBitSets (org.infinispan.context.impl.FlagBitSets)1 DistributionInfo (org.infinispan.distribution.DistributionInfo)1 DistributionManager (org.infinispan.distribution.DistributionManager)1 LocalizedCacheTopology (org.infinispan.distribution.LocalizedCacheTopology)1 TouchMode (org.infinispan.expiration.TouchMode)1 TouchCommand (org.infinispan.expiration.impl.TouchCommand)1 Inject (org.infinispan.factories.annotations.Inject)1