Search in sources :

Example 1 with AggregateCompletionStage

use of org.infinispan.util.concurrent.AggregateCompletionStage in project infinispan by infinispan.

the class WriteSkewHelper method performWriteSkewCheckAndReturnNewVersions.

public static CompletionStage<Map<Object, IncrementableEntryVersion>> performWriteSkewCheckAndReturnNewVersions(VersionedPrepareCommand prepareCommand, EntryLoader<?, ?> entryLoader, VersionGenerator versionGenerator, TxInvocationContext<?> context, KeySpecificLogic ksl, KeyPartitioner keyPartitioner) {
    if (prepareCommand.getVersionsSeen() == null) {
        // Do not perform the write skew check if this prepare command is being replayed for state transfer
        return CompletableFutures.completedEmptyMap();
    }
    Map<Object, IncrementableEntryVersion> uv = new HashMap<>();
    AggregateCompletionStage<Map<Object, IncrementableEntryVersion>> aggregateCompletionStage = CompletionStages.aggregateCompletionStage(uv);
    for (WriteCommand c : prepareCommand.getModifications()) {
        for (Object k : c.getAffectedKeys()) {
            int segment = SegmentSpecificCommand.extractSegment(c, k, keyPartitioner);
            if (ksl.performCheckOnSegment(segment)) {
                CacheEntry<?, ?> cacheEntry = context.lookupEntry(k);
                if (!(cacheEntry instanceof VersionedRepeatableReadEntry)) {
                    continue;
                }
                VersionedRepeatableReadEntry entry = (VersionedRepeatableReadEntry) cacheEntry;
                CompletionStage<Boolean> skewStage = entry.performWriteSkewCheck(entryLoader, segment, context, prepareCommand.getVersionsSeen().get(k), versionGenerator, c.hasAnyFlag(FlagBitSets.ROLLING_UPGRADE));
                aggregateCompletionStage.dependsOn(skewStage.thenAccept(passSkew -> {
                    if (!passSkew) {
                        throw new WriteSkewException("Write skew detected on key " + entry.getKey() + " for transaction " + context.getCacheTransaction(), entry.getKey());
                    }
                    IncrementableEntryVersion newVersion = incrementVersion(entry, versionGenerator);
                    // Have to synchronize as we could have returns on different threads due to notifications/loaders etc
                    synchronized (uv) {
                        uv.put(entry.getKey(), newVersion);
                    }
                }));
            }
        }
    }
    return aggregateCompletionStage.freeze();
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion) Response(org.infinispan.remoting.responses.Response) CacheEntry(org.infinispan.container.entries.CacheEntry) VersionGenerator(org.infinispan.container.versioning.VersionGenerator) HashMap(java.util.HashMap) CompletionStages(org.infinispan.util.concurrent.CompletionStages) EntryLoader(org.infinispan.persistence.util.EntryLoader) VersionedPrepareCommand(org.infinispan.commands.tx.VersionedPrepareCommand) FlagBitSets(org.infinispan.context.impl.FlagBitSets) CompletionStage(java.util.concurrent.CompletionStage) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) PrepareResponse(org.infinispan.remoting.responses.PrepareResponse) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) Map(java.util.Map) PrivateMetadata(org.infinispan.metadata.impl.PrivateMetadata) SegmentSpecificCommand(org.infinispan.commands.SegmentSpecificCommand) VersionedRepeatableReadEntry(org.infinispan.container.entries.VersionedRepeatableReadEntry) WriteSkewException(org.infinispan.transaction.WriteSkewException) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) WriteCommand(org.infinispan.commands.write.WriteCommand) HashMap(java.util.HashMap) VersionedRepeatableReadEntry(org.infinispan.container.entries.VersionedRepeatableReadEntry) WriteSkewException(org.infinispan.transaction.WriteSkewException) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AggregateCompletionStage

use of org.infinispan.util.concurrent.AggregateCompletionStage in project infinispan by infinispan.

the class EntryWrappingInterceptor method getAllHandle.

private Object getAllHandle(InvocationContext rCtx, GetAllCommand command, Object rv, Throwable t) {
    if (useRepeatableRead) {
        for (Object key : command.getKeys()) {
            CacheEntry cacheEntry = rCtx.lookupEntry(key);
            if (cacheEntry == null) {
                // Data was lost
                if (log.isTraceEnabled())
                    log.tracef(t, "Missing entry for " + key);
            } else {
                cacheEntry.setSkipLookup(true);
            }
        }
    }
    AggregateCompletionStage<Void> stage = CompletionStages.aggregateCompletionStage();
    // instanceof check excludes the case when the command returns UnsuccessfulResponse
    if (t == null && rv instanceof Map) {
        boolean notify = !command.hasAnyFlag(FlagBitSets.SKIP_LISTENER_NOTIFICATION) && notifier.hasListener(CacheEntryVisited.class);
        log.tracef("Notifying getAll? %s; result %s", notify, rv);
        if (notify) {
            Map<Object, Object> map = (Map<Object, Object>) rv;
            for (Map.Entry<Object, Object> entry : map.entrySet()) {
                Object value = entry.getValue();
                if (value != null) {
                    Object finalValue = command.isReturnEntries() ? ((CacheEntry) value).getValue() : entry.getValue();
                    CompletionStage<Void> innerStage = notifier.notifyCacheEntryVisited(entry.getKey(), finalValue, true, rCtx, command);
                    stage.dependsOn(innerStage.thenCompose(ig -> notifier.notifyCacheEntryVisited(entry.getKey(), finalValue, false, rCtx, command)));
                }
            }
        }
    }
    return delayedValue(stage.freeze(), rv, t);
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) IntSets(org.infinispan.commons.util.IntSets) GetCacheEntryCommand(org.infinispan.commands.read.GetCacheEntryCommand) LogFactory(org.infinispan.util.logging.LogFactory) Util.toStr(org.infinispan.commons.util.Util.toStr) WriteSkewHelper.versionFromEntry(org.infinispan.transaction.impl.WriteSkewHelper.versionFromEntry) VersionGenerator(org.infinispan.container.versioning.VersionGenerator) ReplaceCommand(org.infinispan.commands.write.ReplaceCommand) GetKeysInGroupCommand(org.infinispan.commands.remote.GetKeysInGroupCommand) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) RemoveExpiredCommand(org.infinispan.commands.write.RemoveExpiredCommand) OutdatedTopologyException(org.infinispan.statetransfer.OutdatedTopologyException) Map(java.util.Map) TxReadOnlyKeyCommand(org.infinispan.commands.functional.TxReadOnlyKeyCommand) TxReadOnlyManyCommand(org.infinispan.commands.functional.TxReadOnlyManyCommand) DDAsyncInterceptor(org.infinispan.interceptors.DDAsyncInterceptor) EntryFactory.expirationCheckDelay(org.infinispan.container.impl.EntryFactory.expirationCheckDelay) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) RemoveCommand(org.infinispan.commands.write.RemoveCommand) Collection(java.util.Collection) ReadWriteManyEntriesCommand(org.infinispan.commands.functional.ReadWriteManyEntriesCommand) ReadWriteKeyValueCommand(org.infinispan.commands.functional.ReadWriteKeyValueCommand) SingleKeyNonTxInvocationContext(org.infinispan.context.impl.SingleKeyNonTxInvocationContext) GroupManager(org.infinispan.distribution.group.impl.GroupManager) LockingMode(org.infinispan.transaction.LockingMode) InvalidateL1Command(org.infinispan.commands.write.InvalidateL1Command) InvocationSuccessFunction(org.infinispan.interceptors.InvocationSuccessFunction) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Flag(org.infinispan.context.Flag) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) InvocationFinallyFunction(org.infinispan.interceptors.InvocationFinallyFunction) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) AbstractVisitor(org.infinispan.commands.AbstractVisitor) DataCommand(org.infinispan.commands.DataCommand) ComputeCommand(org.infinispan.commands.write.ComputeCommand) ExceptionSyncInvocationStage(org.infinispan.interceptors.ExceptionSyncInvocationStage) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionStages(org.infinispan.util.concurrent.CompletionStages) XSiteStateConsumer(org.infinispan.xsite.statetransfer.XSiteStateConsumer) GetAllCommand(org.infinispan.commands.read.GetAllCommand) ReadOnlyKeyCommand(org.infinispan.commands.functional.ReadOnlyKeyCommand) StateTransferLock(org.infinispan.statetransfer.StateTransferLock) WriteOnlyManyEntriesCommand(org.infinispan.commands.functional.WriteOnlyManyEntriesCommand) Start(org.infinispan.factories.annotations.Start) FlagBitSets(org.infinispan.context.impl.FlagBitSets) AbstractDataWriteCommand(org.infinispan.commands.write.AbstractDataWriteCommand) Configurations(org.infinispan.configuration.cache.Configurations) CacheEntryVisited(org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) IracPutKeyValueCommand(org.infinispan.commands.write.IracPutKeyValueCommand) Log(org.infinispan.util.logging.Log) AbstractDataCommand(org.infinispan.commands.read.AbstractDataCommand) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) ClearCommand(org.infinispan.commands.write.ClearCommand) Address(org.infinispan.remoting.transport.Address) IncrementableEntryVersion(org.infinispan.container.versioning.IncrementableEntryVersion) Response(org.infinispan.remoting.responses.Response) GetKeyValueCommand(org.infinispan.commands.read.GetKeyValueCommand) CacheEntry(org.infinispan.container.entries.CacheEntry) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) WriteOnlyKeyValueCommand(org.infinispan.commands.functional.WriteOnlyKeyValueCommand) EvictCommand(org.infinispan.commands.write.EvictCommand) WriteOnlyManyCommand(org.infinispan.commands.functional.WriteOnlyManyCommand) PutMapCommand(org.infinispan.commands.write.PutMapCommand) EntryFactory(org.infinispan.container.impl.EntryFactory) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) CommitCommand(org.infinispan.commands.tx.CommitCommand) Inject(org.infinispan.factories.annotations.Inject) FunctionalCommand(org.infinispan.commands.functional.FunctionalCommand) ReadOnlyManyCommand(org.infinispan.commands.functional.ReadOnlyManyCommand) MVCCEntry(org.infinispan.container.entries.MVCCEntry) StateConsumer(org.infinispan.statetransfer.StateConsumer) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) IsolationLevel(org.infinispan.util.concurrent.IsolationLevel) ReadWriteKeyCommand(org.infinispan.commands.functional.ReadWriteKeyCommand) ComputeIfAbsentCommand(org.infinispan.commands.write.ComputeIfAbsentCommand) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) WriteOnlyKeyCommand(org.infinispan.commands.functional.WriteOnlyKeyCommand) VisitableCommand(org.infinispan.commands.VisitableCommand) ReadWriteManyCommand(org.infinispan.commands.functional.ReadWriteManyCommand) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) CacheEntryVisited(org.infinispan.notifications.cachelistener.annotation.CacheEntryVisited) CacheEntry(org.infinispan.container.entries.CacheEntry) Map(java.util.Map)

Example 3 with AggregateCompletionStage

use of org.infinispan.util.concurrent.AggregateCompletionStage 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 4 with AggregateCompletionStage

use of org.infinispan.util.concurrent.AggregateCompletionStage in project infinispan by infinispan.

the class PersistenceManagerImpl method disableStore.

@Override
public CompletionStage<Void> disableStore(String storeType) {
    boolean stillHasAStore = false;
    AggregateCompletionStage<Void> aggregateCompletionStage = CompletionStages.aggregateCompletionStage();
    long stamp = lock.writeLock();
    try {
        if (!checkStoreAvailability()) {
            return CompletableFutures.completedNull();
        }
        boolean allAvailable = true;
        Iterator<StoreStatus> statusIterator = stores.iterator();
        while (statusIterator.hasNext()) {
            StoreStatus status = statusIterator.next();
            NonBlockingStore<?, ?> nonBlockingStore = unwrapStore(status.store());
            if (nonBlockingStore.getClass().getName().equals(storeType) || containedInAdapter(nonBlockingStore, storeType)) {
                statusIterator.remove();
                aggregateCompletionStage.dependsOn(nonBlockingStore.stop().whenComplete((v, t) -> {
                    if (t != null) {
                        log.warn("There was an error stopping the store", t);
                    }
                }));
            } else {
                stillHasAStore = true;
                allAvailable = allAvailable && status.availability;
            }
        }
        if (!stillHasAStore) {
            unavailableExceptionMessage = null;
            enabled = false;
            stopAvailabilityTask();
        } else if (allAvailable) {
            unavailableExceptionMessage = null;
        }
        allSegmentedOrShared = allStoresSegmentedOrShared();
        listeners.forEach(l -> l.storeChanged(createStatus()));
        if (!stillHasAStore) {
            AsyncInterceptorChain chain = cache.wired().getAsyncInterceptorChain();
            AsyncInterceptor loaderInterceptor = chain.findInterceptorExtending(CacheLoaderInterceptor.class);
            if (loaderInterceptor == null) {
                PERSISTENCE.persistenceWithoutCacheLoaderInterceptor();
            } else {
                chain.removeInterceptor(loaderInterceptor.getClass());
            }
            AsyncInterceptor writerInterceptor = chain.findInterceptorExtending(CacheWriterInterceptor.class);
            if (writerInterceptor == null) {
                writerInterceptor = chain.findInterceptorWithClass(TransactionalStoreInterceptor.class);
                if (writerInterceptor == null) {
                    PERSISTENCE.persistenceWithoutCacheWriteInterceptor();
                } else {
                    chain.removeInterceptor(writerInterceptor.getClass());
                }
            } else {
                chain.removeInterceptor(writerInterceptor.getClass());
            }
        }
        return aggregateCompletionStage.freeze();
    } finally {
        lock.unlockWrite(stamp);
    }
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) IntSets(org.infinispan.commons.util.IntSets) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) CONFIG(org.infinispan.util.logging.Log.CONFIG) Stop(org.infinispan.factories.annotations.Stop) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Collections.singletonList(java.util.Collections.singletonList) Scopes(org.infinispan.factories.scopes.Scopes) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) AdvancedCache(org.infinispan.AdvancedCache) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) InterceptorChainFactory(org.infinispan.factories.InterceptorChainFactory) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) Predicate(java.util.function.Predicate) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) IntSet(org.infinispan.commons.util.IntSet) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) GuardedBy(net.jcip.annotations.GuardedBy) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PersistenceException(org.infinispan.persistence.spi.PersistenceException) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) CompletableFuture(java.util.concurrent.CompletableFuture) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) AtomicReference(java.util.concurrent.atomic.AtomicReference) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) HashSet(java.util.HashSet) FlagBitSets(org.infinispan.context.impl.FlagBitSets) BiPredicate(java.util.function.BiPredicate) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) Executor(java.util.concurrent.Executor) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Publisher(org.reactivestreams.Publisher) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) LocalizedCacheTopology(org.infinispan.distribution.LocalizedCacheTopology) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) Collections(java.util.Collections) StampedLock(java.util.concurrent.locks.StampedLock) TimeService(org.infinispan.commons.time.TimeService) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor)

Example 5 with AggregateCompletionStage

use of org.infinispan.util.concurrent.AggregateCompletionStage in project infinispan by infinispan.

the class CacheNotifierImpl method doNotifyPassivated.

private CompletionStage<Void> doNotifyPassivated(K key, V value, boolean pre, FlagAffectedCommand command) {
    EventImpl<K, V> e = EventImpl.createEvent(cache.wired(), CACHE_ENTRY_PASSIVATED);
    boolean isLocalNodePrimaryOwner = isLocalNodePrimaryOwner(key);
    AggregateCompletionStage aggregateCompletionStage = null;
    for (CacheEntryListenerInvocation<K, V> listener : cacheEntryPassivatedListeners) {
        // Need a wrapper per invocation since converter could modify the entry in it
        key = convertKey(listener, key);
        value = convertValue(listener, value);
        e.setPre(pre);
        e.setKey(key);
        e.setValue(value);
        aggregateCompletionStage = composeStageIfNeeded(aggregateCompletionStage, listener.invoke(new EventWrapper<>(key, e, command), isLocalNodePrimaryOwner));
    }
    return aggregateCompletionStage != null ? aggregateCompletionStage.freeze() : CompletableFutures.completedNull();
}
Also used : AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage)

Aggregations

AggregateCompletionStage (org.infinispan.util.concurrent.AggregateCompletionStage)16 CompletionStage (java.util.concurrent.CompletionStage)13 CompletionStages (org.infinispan.util.concurrent.CompletionStages)11 Collection (java.util.Collection)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Inject (org.infinispan.factories.annotations.Inject)9 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)9 Log (org.infinispan.util.logging.Log)9 LogFactory (org.infinispan.util.logging.LogFactory)9 List (java.util.List)8 FlagBitSets (org.infinispan.context.impl.FlagBitSets)8 Start (org.infinispan.factories.annotations.Start)8 Map (java.util.Map)7 WriteCommand (org.infinispan.commands.write.WriteCommand)7 Configuration (org.infinispan.configuration.cache.Configuration)7 InvocationContext (org.infinispan.context.InvocationContext)7 DistributionManager (org.infinispan.distribution.DistributionManager)7 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)7 ComponentName (org.infinispan.factories.annotations.ComponentName)7 Completable (io.reactivex.rxjava3.core.Completable)6