Search in sources :

Example 1 with ClusteringDependentLogic

use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.

the class ClusteredCacheTest method findCache.

private Optional<Cache<Object, Person>> findCache(Ownership ownership, Object key) {
    List<Cache<Object, Person>> caches = caches();
    ClusteringDependentLogic cdl = cache1.getAdvancedCache().getComponentRegistry().getComponent(ClusteringDependentLogic.class);
    DistributionInfo distribution = cdl.getCacheTopology().getDistribution(key);
    Predicate<Cache<?, ?>> predicate = null;
    switch(ownership) {
        case PRIMARY:
            predicate = c -> c.getAdvancedCache().getRpcManager().getAddress().equals(distribution.primary());
            break;
        case BACKUP:
            predicate = c -> distribution.writeBackups().contains(c.getAdvancedCache().getRpcManager().getAddress());
            break;
        case NON_OWNER:
            predicate = c -> !distribution.writeOwners().contains(c.getAdvancedCache().getRpcManager().getAddress());
    }
    return caches.stream().filter(predicate).findFirst();
}
Also used : ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) DistributionInfo(org.infinispan.distribution.DistributionInfo) Cache(org.infinispan.Cache)

Example 2 with ClusteringDependentLogic

use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.

the class ClusteringDependentLogicFactory method construct.

@Override
public Object construct(String componentName) {
    CacheMode cacheMode = configuration.clustering().cacheMode();
    ClusteringDependentLogic cdl;
    if (!cacheMode.isClustered()) {
        cdl = new ClusteringDependentLogic.LocalLogic();
    } else if (cacheMode.isInvalidation()) {
        cdl = new ClusteringDependentLogic.InvalidationLogic();
    } else if (cacheMode.isReplicated()) {
        cdl = new ClusteringDependentLogic.ReplicationLogic();
    } else if (cacheMode.isDistributed()) {
        cdl = new ClusteringDependentLogic.DistributionLogic();
    } else if (cacheMode.isScattered()) {
        cdl = new ClusteringDependentLogic.ScatteredLogic();
    } else {
        throw CONTAINER.factoryCannotConstructComponent(componentName);
    }
    return cdl;
}
Also used : ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) CacheMode(org.infinispan.configuration.cache.CacheMode)

Example 3 with ClusteringDependentLogic

use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.

the class NonTxStateTransferOverwritingValue2Test method blockEntryCommit.

private void blockEntryCommit(final CheckPoint checkPoint, AdvancedCache<Object, Object> cache) {
    ClusteringDependentLogic cdl1 = TestingUtil.extractComponent(cache, ClusteringDependentLogic.class);
    ClusteringDependentLogic replaceCdl = new ClusteringDependentLogicDelegator(cdl1) {

        @Override
        public CompletionStage<Void> commitEntry(CacheEntry entry, FlagAffectedCommand command, InvocationContext ctx, Flag trackFlag, boolean l1Invalidation) {
            // skip for clear command!
            if (entry instanceof ClearCacheEntry) {
                return super.commitEntry(entry, command, ctx, trackFlag, l1Invalidation);
            }
            final Address source = ctx.getOrigin();
            CacheEntry newEntry = new CacheEntryDelegator(entry) {

                @Override
                public void commit(DataContainer container) {
                    checkPoint.trigger("pre_commit_entry_" + getKey() + "_from_" + source);
                    try {
                        checkPoint.awaitStrict("resume_commit_entry_" + getKey() + "_from_" + source, 10, SECONDS);
                    } catch (InterruptedException | TimeoutException e) {
                        throw new RuntimeException(e);
                    }
                    super.commit(container);
                    checkPoint.trigger("post_commit_entry_" + getKey() + "_from_" + source);
                }
            };
            return super.commitEntry(newEntry, command, ctx, trackFlag, l1Invalidation);
        }
    };
    TestingUtil.replaceComponent(cache, ClusteringDependentLogic.class, replaceCdl, true);
}
Also used : Address(org.infinispan.remoting.transport.Address) ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) CacheEntryDelegator(org.infinispan.test.fwk.CacheEntryDelegator) ClearCacheEntry(org.infinispan.container.entries.ClearCacheEntry) CacheEntry(org.infinispan.container.entries.CacheEntry) Flag(org.infinispan.context.Flag) ClearCacheEntry(org.infinispan.container.entries.ClearCacheEntry) FlagAffectedCommand(org.infinispan.commands.FlagAffectedCommand) DataContainer(org.infinispan.container.DataContainer) InvocationContext(org.infinispan.context.InvocationContext) ClusteringDependentLogicDelegator(org.infinispan.test.fwk.ClusteringDependentLogicDelegator) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with ClusteringDependentLogic

use of org.infinispan.interceptors.locking.ClusteringDependentLogic in project infinispan by infinispan.

the class ClusteredConditionalCommandTest method create.

private <K, V> CacheHelper<K, V> create(List<Cache<K, V>> cacheList) {
    CacheHelper<K, V> cacheHelper = new CacheHelper<>();
    for (Cache<K, V> cache : cacheList) {
        ClusteringDependentLogic clusteringDependentLogic = extractComponent(cache, ClusteringDependentLogic.class);
        DistributionInfo distributionInfo = clusteringDependentLogic.getCacheTopology().getDistribution(key);
        log.debugf("owners for key %s are %s", key, distributionInfo.writeOwners());
        if (distributionInfo.isPrimary()) {
            log.debug("Cache " + address(cache) + " is the primary owner");
            assertTrue(cacheHelper.addCache(Ownership.PRIMARY, cache));
        } else if (distributionInfo.isWriteBackup()) {
            log.debug("Cache " + address(cache) + " is the backup owner");
            assertTrue(cacheHelper.addCache(Ownership.BACKUP, cache));
        } else {
            log.debug("Cache " + address(cache) + " is the non owner");
            assertTrue(cacheHelper.addCache(Ownership.NON_OWNER, cache) || cacheMode.isScattered());
        }
    }
    return cacheHelper;
}
Also used : ClusteringDependentLogic(org.infinispan.interceptors.locking.ClusteringDependentLogic) DistributionInfo(org.infinispan.distribution.DistributionInfo)

Aggregations

ClusteringDependentLogic (org.infinispan.interceptors.locking.ClusteringDependentLogic)4 DistributionInfo (org.infinispan.distribution.DistributionInfo)2 TimeoutException (java.util.concurrent.TimeoutException)1 Cache (org.infinispan.Cache)1 FlagAffectedCommand (org.infinispan.commands.FlagAffectedCommand)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1 DataContainer (org.infinispan.container.DataContainer)1 CacheEntry (org.infinispan.container.entries.CacheEntry)1 ClearCacheEntry (org.infinispan.container.entries.ClearCacheEntry)1 Flag (org.infinispan.context.Flag)1 InvocationContext (org.infinispan.context.InvocationContext)1 Address (org.infinispan.remoting.transport.Address)1 CacheEntryDelegator (org.infinispan.test.fwk.CacheEntryDelegator)1 ClusteringDependentLogicDelegator (org.infinispan.test.fwk.ClusteringDependentLogicDelegator)1