Search in sources :

Example 1 with IracTombstonePrimaryCheckCommand

use of org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand in project infinispan by infinispan.

the class DefaultIracTombstoneManager method performCleanup.

private CompletionStage<Void> performCleanup() {
    if (stopped) {
        return CompletableFutures.completedNull();
    }
    scheduler.onTaskStarted(tombstoneMap.size());
    try {
        AggregateCompletionStage<Void> stage = CompletionStages.aggregateCompletionStage();
        RpcOptions rpcOptions = rpcManager.getSyncRpcOptions();
        Map<Address, BackPressure<IracTombstonePrimaryCheckCommand, Void>> staleTombstones = new HashMap<>(tombstoneMap.size());
        for (IracTombstoneInfo tombstone : tombstoneMap.values()) {
            DistributionInfo info = distributionManager.getCacheTopology().getSegmentDistribution(tombstone.getSegment());
            if (!info.isWriteOwner()) {
                // topology changed, no longer an owner
                removeTombstone(tombstone);
                continue;
            }
            // it means the primary owner hasn't sent the update to the remote site.
            if (iracManager.running().containsKey(tombstone.getKey())) {
                continue;
            }
            if (!info.isPrimary()) {
                BackPressure<IracTombstonePrimaryCheckCommand, Void> backPressure = staleTombstones.get(info.primary());
                if (backPressure == null) {
                    backPressure = new BackPressure<>(commandsFactory.buildIracTombstonePrimaryCheckCommand(batchSize), null);
                    staleTombstones.put(info.primary(), backPressure);
                }
                if (backPressure.element.addTombstone(tombstone) == batchSize) {
                    CompletionStage<Void> rsp;
                    if (backPressure.delay == null) {
                        rsp = rpcManager.invokeCommand(info.primary(), backPressure.element, ignoreLeavers(), rpcOptions);
                    } else {
                        ReplicableCommand rCmd = backPressure.element;
                        rsp = backPressure.delay.thenComposeAsync(unused -> rpcManager.invokeCommand(info.primary(), rCmd, ignoreLeavers(), rpcOptions), blockingExecutor);
                    }
                    staleTombstones.put(info.primary(), new BackPressure<>(commandsFactory.buildIracTombstonePrimaryCheckCommand(batchSize), rsp));
                }
                continue;
            }
            stage.dependsOn(new CleanupTask(tombstone).checkRemoteSites());
        }
        // sending any pending stale tombstones
        for (Map.Entry<Address, BackPressure<IracTombstonePrimaryCheckCommand, Void>> entry : staleTombstones.entrySet()) {
            BackPressure<IracTombstonePrimaryCheckCommand, Void> backPressure = entry.getValue();
            if (backPressure.element.isEmpty()) {
                continue;
            }
            if (backPressure.delay == null) {
                rpcManager.sendTo(entry.getKey(), backPressure.element, DeliverOrder.NONE);
            } else {
                backPressure.delay.thenRunAsync(() -> rpcManager.sendTo(entry.getKey(), backPressure.element, DeliverOrder.NONE), blockingExecutor);
            }
        }
        return stage.freeze().whenComplete(scheduler);
    } catch (Throwable t) {
        log.debug("Unexpected exception", t);
        scheduler.scheduleWithCurrentDelay();
        return CompletableFutures.completedNull();
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) VoidResponseCollector.ignoreLeavers(org.infinispan.remoting.transport.impl.VoidResponseCollector.ignoreLeavers) KnownComponentNames(org.infinispan.factories.KnownComponentNames) Predicate(io.reactivex.rxjava3.functions.Predicate) Stop(org.infinispan.factories.annotations.Stop) SiteState(org.infinispan.xsite.status.SiteState) Scopes(org.infinispan.factories.scopes.Scopes) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) 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) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IracXSiteBackup(org.infinispan.xsite.irac.IracXSiteBackup) DefaultIracManager(org.infinispan.xsite.irac.DefaultIracManager) CompletableObserver(io.reactivex.rxjava3.core.CompletableObserver) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) Disposable(io.reactivex.rxjava3.disposables.Disposable) GuardedBy(net.jcip.annotations.GuardedBy) CompletableFutures.toTrueFunction(org.infinispan.util.concurrent.CompletableFutures.toTrueFunction) CompletableFutures.completedNull(org.infinispan.util.concurrent.CompletableFutures.completedNull) BackupConfiguration(org.infinispan.configuration.cache.BackupConfiguration) XSiteStateTransferConfiguration(org.infinispan.configuration.cache.XSiteStateTransferConfiguration) HashMap(java.util.HashMap) IracTombstoneRemoteSiteCheckCommand(org.infinispan.commands.irac.IracTombstoneRemoteSiteCheckCommand) CompletionStages(org.infinispan.util.concurrent.CompletionStages) NonNull(io.reactivex.rxjava3.annotations.NonNull) Function(java.util.function.Function) Start(org.infinispan.factories.annotations.Start) IracTombstoneStateResponseCommand(org.infinispan.commands.irac.IracTombstoneStateResponseCommand) Log(org.infinispan.util.logging.Log) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BiConsumer(java.util.function.BiConsumer) IracTombstonePrimaryCheckCommand(org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand) IracExecutor(org.infinispan.xsite.irac.IracExecutor) Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) Transport(org.infinispan.remoting.transport.Transport) Flowable(io.reactivex.rxjava3.core.Flowable) Executor(java.util.concurrent.Executor) IracTombstoneCleanupCommand(org.infinispan.commands.irac.IracTombstoneCleanupCommand) RpcManager(org.infinispan.remoting.rpc.RpcManager) Completable(io.reactivex.rxjava3.core.Completable) Inject(org.infinispan.factories.annotations.Inject) TimeUnit(java.util.concurrent.TimeUnit) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) CompletableSource(io.reactivex.rxjava3.core.CompletableSource) Configuration(org.infinispan.configuration.cache.Configuration) DistributionInfo(org.infinispan.distribution.DistributionInfo) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) ExponentialBackOff(org.infinispan.util.ExponentialBackOff) IracManager(org.infinispan.xsite.irac.IracManager) VoidResponseCollector.validOnly(org.infinispan.remoting.transport.impl.VoidResponseCollector.validOnly) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) Address(org.infinispan.remoting.transport.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ReplicableCommand(org.infinispan.commands.ReplicableCommand) DistributionInfo(org.infinispan.distribution.DistributionInfo) RpcOptions(org.infinispan.remoting.rpc.RpcOptions) IracTombstonePrimaryCheckCommand(org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with IracTombstonePrimaryCheckCommand

use of org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand in project infinispan by infinispan.

the class IracTombstoneCleanupTest method testBackupOwnerRoundCleanupDoNotCleanupPrimary.

public void testBackupOwnerRoundCleanupDoNotCleanupPrimary(Method method) {
    String key = k(method);
    int segment = getSegment(key);
    Cache<String, String> pCache = findPrimaryOwner(segment);
    Cache<String, String> bCache = findBackupOwner(segment);
    IracMetadata metadata = dummyMetadata(2);
    tombstoneManager(pCache).storeTombstone(segment, key, metadata);
    tombstoneManager(bCache).storeTombstone(segment, key, metadata);
    assertEquals(1, tombstoneManager(pCache).size());
    assertEquals(1, tombstoneManager(bCache).size());
    RecordingRpcManager pRpcManager = recordingRpcManager(pCache);
    RecordingRpcManager bRpcManager = recordingRpcManager(bCache);
    pRpcManager.startRecording();
    bRpcManager.startRecording();
    tombstoneManager(bCache).runCleanupAndWait();
    IracTombstonePrimaryCheckCommand cmd = bRpcManager.findSingleCommand(IracTombstonePrimaryCheckCommand.class);
    assertNotNull(cmd);
    assertEquals(1, cmd.getTombstoneToCheck().size());
    IracTombstoneInfo tombstoneInfo = cmd.getTombstoneToCheck().iterator().next();
    assertEquals(segment, tombstoneInfo.getSegment());
    assertEquals(key, tombstoneInfo.getKey());
    assertEquals(metadata, tombstoneInfo.getMetadata());
    assertFalse(pRpcManager.isCommandSent(IracTombstoneCleanupCommand.class));
    // check if nothing is removed... should we sleep here?
    assertEquals(1, tombstoneManager(pCache).size());
    assertEquals(1, tombstoneManager(bCache).size());
    // remove tombstone to avoid messing up with other tests
    tombstoneManager(pCache).removeTombstone(key);
    tombstoneManager(bCache).removeTombstone(key);
}
Also used : IracTombstoneCleanupCommand(org.infinispan.commands.irac.IracTombstoneCleanupCommand) IracMetadata(org.infinispan.metadata.impl.IracMetadata) IracTombstoneInfo(org.infinispan.container.versioning.irac.IracTombstoneInfo) IracTombstonePrimaryCheckCommand(org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand) ByteString(org.infinispan.util.ByteString)

Aggregations

IracTombstoneCleanupCommand (org.infinispan.commands.irac.IracTombstoneCleanupCommand)2 IracTombstonePrimaryCheckCommand (org.infinispan.commands.irac.IracTombstonePrimaryCheckCommand)2 IracMetadata (org.infinispan.metadata.impl.IracMetadata)2 NonNull (io.reactivex.rxjava3.annotations.NonNull)1 Completable (io.reactivex.rxjava3.core.Completable)1 CompletableObserver (io.reactivex.rxjava3.core.CompletableObserver)1 CompletableSource (io.reactivex.rxjava3.core.CompletableSource)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 Predicate (io.reactivex.rxjava3.functions.Predicate)1 MethodHandles (java.lang.invoke.MethodHandles)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)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 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1