Search in sources :

Example 11 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class PutFromLoadValidator method removeFromCache.

/**
 * This methods should be called only from tests; it removes existing validator from the cache structures
 * in order to replace it with new one.
 *
 * @param cache
 */
public static PutFromLoadValidator removeFromCache(AdvancedCache cache) {
    AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
    BasicComponentRegistry cr = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
    chain.removeInterceptor(TxPutFromLoadInterceptor.class);
    chain.removeInterceptor(NonTxPutFromLoadInterceptor.class);
    chain.getInterceptors().stream().filter(BaseInvalidationInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass).ifPresent(invalidationClass -> {
        InvalidationInterceptor invalidationInterceptor = new InvalidationInterceptor();
        cr.replaceComponent(InvalidationInterceptor.class.getName(), invalidationInterceptor, true);
        cr.getComponent(InvalidationInterceptor.class).running();
        chain.replaceInterceptor(invalidationInterceptor, invalidationClass);
    });
    chain.getInterceptors().stream().filter(LockingInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass).ifPresent(invalidationClass -> {
        NonTransactionalLockingInterceptor lockingInterceptor = new NonTransactionalLockingInterceptor();
        cr.replaceComponent(NonTransactionalLockingInterceptor.class.getName(), lockingInterceptor, true);
        cr.getComponent(NonTransactionalLockingInterceptor.class).running();
        chain.replaceInterceptor(lockingInterceptor, LockingInterceptor.class);
    });
    return cr.getComponent(PutFromLoadValidator.class).running();
}
Also used : InvalidationInterceptor(org.infinispan.interceptors.impl.InvalidationInterceptor) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor)

Example 12 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain 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 13 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class SimpleCacheTest method testFindInterceptor.

public void testFindInterceptor() {
    AsyncInterceptorChain interceptorChain = cache().getAdvancedCache().getAsyncInterceptorChain();
    assertNotNull(interceptorChain);
    assertNull(interceptorChain.findInterceptorExtending(InvocationContextInterceptor.class));
}
Also used : AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) InvocationContextInterceptor(org.infinispan.interceptors.impl.InvocationContextInterceptor)

Example 14 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class CacheManagerComponentRegistryTest method testOverridingComponents.

public void testOverridingComponents() {
    cm = TestCacheManagerFactory.createClusteredCacheManager(new ConfigurationBuilder());
    // default cache with no overrides
    Cache c = cm.getCache();
    ConfigurationBuilder overrides = new ConfigurationBuilder();
    overrides.invocationBatching().enable();
    cm.defineConfiguration("overridden", overrides.build());
    Cache overridden = cm.getCache("overridden");
    // assert components.
    AsyncInterceptorChain initialChain = c.getAdvancedCache().getAsyncInterceptorChain();
    assert !initialChain.containsInterceptorType(BatchingInterceptor.class);
    AsyncInterceptorChain overriddenChain = overridden.getAdvancedCache().getAsyncInterceptorChain();
    assert overriddenChain.containsInterceptorType(BatchingInterceptor.class);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) BatchingInterceptor(org.infinispan.interceptors.impl.BatchingInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Cache(org.infinispan.Cache)

Example 15 with AsyncInterceptorChain

use of org.infinispan.interceptors.AsyncInterceptorChain in project infinispan by infinispan.

the class DomainDataRegionImpl method prepareCommon.

private void prepareCommon(CacheMode cacheMode) {
    BasicComponentRegistry registry = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);
    if (cacheMode.isReplicated() || cacheMode.isDistributed()) {
        AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
        LockingInterceptor lockingInterceptor = new LockingInterceptor();
        registry.registerComponent(LockingInterceptor.class, lockingInterceptor, true);
        registry.getComponent(LockingInterceptor.class).running();
        if (!chain.addInterceptorBefore(lockingInterceptor, NonTransactionalLockingInterceptor.class)) {
            throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
        }
        chain.removeInterceptor(NonTransactionalLockingInterceptor.class);
        UnorderedDistributionInterceptor distributionInterceptor = new UnorderedDistributionInterceptor();
        registry.registerComponent(UnorderedDistributionInterceptor.class, distributionInterceptor, true);
        registry.getComponent(UnorderedDistributionInterceptor.class).running();
        if (!chain.addInterceptorBefore(distributionInterceptor, NonTxDistributionInterceptor.class) && !chain.addInterceptorBefore(distributionInterceptor, TriangleDistributionInterceptor.class)) {
            throw new IllegalStateException("Misconfigured cache, interceptor chain is " + chain);
        }
        chain.removeInterceptor(NonTxDistributionInterceptor.class);
        chain.removeInterceptor(TriangleDistributionInterceptor.class);
    }
    // ClusteredExpirationManager sends RemoteExpirationCommands to remote nodes which causes
    // undesired overhead. When get() triggers a RemoteExpirationCommand executed in async executor
    // this locks the entry for the duration of RPC, and putFromLoad with ZERO_LOCK_ACQUISITION_TIMEOUT
    // fails as it finds the entry being blocked.
    ComponentRef<InternalExpirationManager> ref = registry.getComponent(InternalExpirationManager.class);
    InternalExpirationManager expirationManager = ref.running();
    if (expirationManager instanceof ClusterExpirationManager) {
        registry.replaceComponent(InternalExpirationManager.class.getName(), new ExpirationManagerImpl<>(), true);
        registry.getComponent(InternalExpirationManager.class).running();
        registry.rewire();
        // re-registering component does not stop the old one
        ((ClusterExpirationManager) expirationManager).stop();
    } else if (expirationManager instanceof ExpirationManagerImpl) {
    // do nothing
    } else {
        throw new IllegalStateException("Expected clustered expiration manager, found " + expirationManager);
    }
    registry.registerComponent(InfinispanDataRegion.class, this, true);
    if (cacheMode.isClustered()) {
        UnorderedReplicationLogic replLogic = new UnorderedReplicationLogic();
        registry.replaceComponent(ClusteringDependentLogic.class.getName(), replLogic, true);
        registry.getComponent(ClusteringDependentLogic.class).running();
        registry.rewire();
    }
}
Also used : ClusterExpirationManager(org.infinispan.expiration.impl.ClusterExpirationManager) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) LockingInterceptor(org.infinispan.hibernate.cache.commons.access.LockingInterceptor) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) UnorderedDistributionInterceptor(org.infinispan.hibernate.cache.commons.access.UnorderedDistributionInterceptor) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) NonTransactionalLockingInterceptor(org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor) UnorderedReplicationLogic(org.infinispan.hibernate.cache.commons.access.UnorderedReplicationLogic) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) ExpirationManagerImpl(org.infinispan.expiration.impl.ExpirationManagerImpl)

Aggregations

AsyncInterceptorChain (org.infinispan.interceptors.AsyncInterceptorChain)53 InvocationContext (org.infinispan.context.InvocationContext)15 CompletableFuture (java.util.concurrent.CompletableFuture)13 VisitableCommand (org.infinispan.commands.VisitableCommand)9 AsyncInterceptor (org.infinispan.interceptors.AsyncInterceptor)9 Future (java.util.concurrent.Future)8 SingleKeyNonTxInvocationContext (org.infinispan.context.impl.SingleKeyNonTxInvocationContext)8 BaseAsyncInterceptor (org.infinispan.interceptors.BaseAsyncInterceptor)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 TestException (org.infinispan.test.TestException)7 CompletableFutures (org.infinispan.util.concurrent.CompletableFutures)7 SECONDS (java.util.concurrent.TimeUnit.SECONDS)6 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 LockControlCommand (org.infinispan.commands.control.LockControlCommand)5 Test (org.testng.annotations.Test)5 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)4 EntryWrappingInterceptor (org.infinispan.interceptors.impl.EntryWrappingInterceptor)4 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)4 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)4