Search in sources :

Example 1 with XSiteResponse

use of org.infinispan.remoting.transport.XSiteResponse in project infinispan by infinispan.

the class SiteProviderTopologyChangeTest method doTopologyChangeDuringXSiteStateTransfer.

/**
 * the test node starts the x-site state transfer and sends a chunk of data. the next chunk is blocked and we trigger
 * the cache topology change.
 */
private void doTopologyChangeDuringXSiteStateTransfer(TopologyEvent event) throws Exception {
    log.debugf("Start topology change during x-site state transfer with %s", event);
    initBeforeTest();
    final TestCaches<Object, Object> testCaches = createTestCache(event, LON);
    log.debugf("Controlled cache=%s, Coordinator cache=%s, Cache to remove=%s", addressOf(testCaches.controllerCache), addressOf(testCaches.coordinator), testCaches.removeIndex < 0 ? "NONE" : addressOf(cache(LON, testCaches.removeIndex)));
    // the test node will start the x-site state transfer and it will block. next, it the topology will change.
    // strategy: let the first push command to proceed a block the next one.
    final CheckPoint checkPoint = new CheckPoint();
    final AtomicBoolean firstChunk = new AtomicBoolean(false);
    wrapGlobalComponent(testCaches.controllerCache.getCacheManager(), Transport.class, new WrapFactory<Transport, Transport, CacheContainer>() {

        @Override
        public Transport wrap(CacheContainer wrapOn, Transport current) {
            return new AbstractDelegatingTransport(current) {

                @Override
                public void start() {
                // no-op; avoid re-start the transport again...
                }

                @Override
                public XSiteResponse backupRemotely(XSiteBackup backup, XSiteReplicateCommand rpcCommand) {
                    if (rpcCommand instanceof XSiteStatePushCommand) {
                        if (firstChunk.compareAndSet(false, true)) {
                            checkPoint.trigger("before-second-chunk");
                            try {
                                checkPoint.awaitStrict("second-chunk", 30, TimeUnit.SECONDS);
                            } catch (InterruptedException | TimeoutException e) {
                                XSiteResponseImpl rsp = new XSiteResponseImpl(TIME_SERVICE, backup);
                                rsp.completeExceptionally(e);
                                return rsp;
                            }
                        }
                    }
                    return super.backupRemotely(backup, rpcCommand);
                }
            };
        }
    }, true);
    log.debug("Start x-site state transfer");
    startStateTransfer(testCaches.coordinator, NYC);
    assertOnline(LON, NYC);
    checkPoint.awaitStrict("before-second-chunk", 30, TimeUnit.SECONDS);
    final Future<Void> topologyEventFuture = triggerTopologyChange(LON, testCaches.removeIndex);
    topologyEventFuture.get();
    checkPoint.triggerForever("second-chunk");
    awaitLocalStateTransfer(LON);
    awaitXSiteStateSent(LON);
    assertData();
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) CacheContainer(org.infinispan.manager.CacheContainer) XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) Transport(org.infinispan.remoting.transport.Transport) XSiteStatePushCommand(org.infinispan.xsite.statetransfer.XSiteStatePushCommand) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Example 2 with XSiteResponse

use of org.infinispan.remoting.transport.XSiteResponse in project infinispan by infinispan.

the class DefaultIracManager method checkAndTrackExpiration.

@Override
public CompletionStage<Boolean> checkAndTrackExpiration(Object key) {
    if (log.isTraceEnabled()) {
        log.tracef("Checking remote backup sites to see if key %s has been touched recently", key);
    }
    IracTouchKeyCommand command = commandsFactory.buildIracTouchCommand(key);
    AtomicBoolean expired = new AtomicBoolean(true);
    // TODO: technically this waits for all backups to respond - we can optimize so
    // we return early
    // if at least one backup says it isn't expired
    AggregateCompletionStage<AtomicBoolean> collector = CompletionStages.aggregateCompletionStage(expired);
    for (XSiteBackup backup : asyncBackups) {
        if (takeOfflineManager.getSiteState(backup.getSiteName()) == SiteState.OFFLINE) {
            if (log.isTraceEnabled()) {
                log.tracef("Skipping %s as it is offline", backup.getSiteName());
            }
            // backup is offline
            continue;
        }
        if (log.isTraceEnabled()) {
            log.tracef("Sending irac touch key command to %s", backup);
        }
        XSiteResponse<Boolean> response = sendToRemoteSite(backup, command);
        collector.dependsOn(response.thenAccept(touched -> {
            if (touched) {
                if (log.isTraceEnabled()) {
                    log.tracef("Key %s was recently touched on a remote site %s", key, backup);
                }
                expired.set(false);
            } else if (log.isTraceEnabled()) {
                log.tracef("Entry %s was expired on remote site %s", key, backup);
            }
        }));
    }
    return collector.freeze().thenApply(AtomicBoolean::get);
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) JmxStatisticsExposer(org.infinispan.jmx.JmxStatisticsExposer) XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) XSiteState(org.infinispan.xsite.statetransfer.XSiteState) VoidResponseCollector.ignoreLeavers(org.infinispan.remoting.transport.impl.VoidResponseCollector.ignoreLeavers) IracTouchKeyCommand(org.infinispan.commands.irac.IracTouchKeyCommand) KnownComponentNames(org.infinispan.factories.KnownComponentNames) SiteState(org.infinispan.xsite.status.SiteState) Scopes(org.infinispan.factories.scopes.Scopes) MBean(org.infinispan.jmx.annotations.MBean) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) ManagedOperation(org.infinispan.jmx.annotations.ManagedOperation) Map(java.util.Map) Scope(org.infinispan.factories.scopes.Scope) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) XSiteBackup(org.infinispan.xsite.XSiteBackup) IracMetadata(org.infinispan.metadata.impl.IracMetadata) CommandsFactory(org.infinispan.commands.CommandsFactory) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheTopology(org.infinispan.topology.CacheTopology) Collectors(java.util.stream.Collectors) ResponseCollector(org.infinispan.remoting.transport.ResponseCollector) Objects(java.util.Objects) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) MeasurementType(org.infinispan.jmx.annotations.MeasurementType) IracCleanupKeyCommand(org.infinispan.commands.irac.IracCleanupKeyCommand) ExponentialBackOffImpl(org.infinispan.util.ExponentialBackOffImpl) IntSets.mutableCopyFrom(org.infinispan.commons.util.IntSets.mutableCopyFrom) LongAdder(java.util.concurrent.atomic.LongAdder) InternalCacheEntry(org.infinispan.container.entries.InternalCacheEntry) BackupConfiguration(org.infinispan.configuration.cache.BackupConfiguration) XSiteStateTransferConfiguration(org.infinispan.configuration.cache.XSiteStateTransferConfiguration) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) DataType(org.infinispan.jmx.annotations.DataType) Function(java.util.function.Function) Start(org.infinispan.factories.annotations.Start) IracTombstoneManager(org.infinispan.container.versioning.irac.IracTombstoneManager) Log(org.infinispan.util.logging.Log) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) Address(org.infinispan.remoting.transport.Address) IntSets.mutableEmptySet(org.infinispan.commons.util.IntSets.mutableEmptySet) Transport(org.infinispan.remoting.transport.Transport) XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) Flowable(io.reactivex.rxjava3.core.Flowable) Executor(java.util.concurrent.Executor) Util(org.infinispan.commons.util.Util) RpcManager(org.infinispan.remoting.rpc.RpcManager) Completable(io.reactivex.rxjava3.core.Completable) Inject(org.infinispan.factories.annotations.Inject) PrimitiveIterator(java.util.PrimitiveIterator) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) ManagedAttribute(org.infinispan.jmx.annotations.ManagedAttribute) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) IracStateResponseCommand(org.infinispan.commands.irac.IracStateResponseCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) ExponentialBackOff(org.infinispan.util.ExponentialBackOff) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IracTouchKeyCommand(org.infinispan.commands.irac.IracTouchKeyCommand) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Transport (org.infinispan.remoting.transport.Transport)2 XSiteResponse (org.infinispan.remoting.transport.XSiteResponse)2 XSiteBackup (org.infinispan.xsite.XSiteBackup)2 XSiteReplicateCommand (org.infinispan.xsite.XSiteReplicateCommand)2 Completable (io.reactivex.rxjava3.core.Completable)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 PrimitiveIterator (java.util.PrimitiveIterator)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Executor (java.util.concurrent.Executor)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1