@Override public Affinity getWeakAffinity(I id) { if (this.cache.getCacheConfiguration().clustering().cacheMode().isClustered()) { Node node = this.locatePrimaryOwner(id); Map.Entry<String, ?> entry = this.registry.getEntry(node); if (entry != null) { return new NodeAffinity(entry.getKey()); } } return Affinity.NONE; }
@Override public <K> KeyAffinityService<K> createService(Cache<K, ?> cache, KeyGenerator<K> generator) { CacheMode mode = cache.getCacheConfiguration().clustering().cacheMode(); return mode.isDistributed() || mode.isReplicated() ? new KeyAffinityServiceImpl<>(executor, cache, generator, bufferSize, Collections.singleton(cache.getCacheManager().getAddress()), false) : new SimpleKeyAffinityService<>(generator); } };
public static <K, V> DataContainer<K, V> createDataContainer(ConfigurationBuilder builder, long size, Predicate<K> evictable) { EntrySizeCalculator<? super K, ? super InternalCacheEntry<K, V>> calculator = (key, entry) -> evictable.test(key) ? 1 : 0; return builder.clustering().cacheMode().needsStateTransfer() ? new BoundedSegmentedDataContainer<>(builder.clustering().hash().create().numSegments(), size, calculator) : new EvictableDataContainer<>(size, calculator); } }
private void prepareCommon(CacheMode cacheMode) { BasicComponentRegistry registry = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class); if (cacheMode.isReplicated() || cacheMode.isDistributed()) { AsyncInterceptorChain chain = cache.getAsyncInterceptorChain(); if (cacheMode.isClustered()) { UnorderedReplicationLogic replLogic = new UnorderedReplicationLogic(); registry.replaceComponent(ClusteringDependentLogic.class.getName(), replLogic, true);
private void createEmbeddedCache() { GlobalConfigurationBuilder globalBuilder; if (cacheMode.isClustered()) { globalBuilder = new GlobalConfigurationBuilder(); globalBuilder.transport().defaultTransport(); } else { globalBuilder = new GlobalConfigurationBuilder().nonClusteredDefault(); } globalBuilder.addModule(PrivateGlobalConfigurationBuilder.class).serverMode(true); org.infinispan.configuration.cache.ConfigurationBuilder builder = new org.infinispan.configuration.cache.ConfigurationBuilder(); builder.clustering().cacheMode(cacheMode) .compatibility().enable().marshaller(marshaller); if (cacheMode.isDistributed() && numOwners != DEFAULT_NUM_OWNERS) { builder.clustering().hash().numOwners(numOwners); } if (cacheMode.isDistributed() && l1Enable) { builder.clustering().l1().enable(); } cacheManager = cacheMode.isClustered() ? TestCacheManagerFactory.createClusteredCacheManager(globalBuilder, builder) : TestCacheManagerFactory.createCacheManager(globalBuilder, builder); if (!cacheName.isEmpty()) cacheManager.defineConfiguration(cacheName, builder.build()); embeddedCache = cacheName.isEmpty() ? cacheManager.getCache() : cacheManager.getCache(cacheName); }
private static void validateIndexCaches(String indexName, Cache<?, ?>... caches) { Arrays.stream(caches).filter(Objects::nonNull).forEach(cache -> { ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering(); CacheMode cacheMode = clusteringConfiguration.cacheMode(); if (cacheMode.isClustered() && !cacheMode.isSynchronous()) { throw log.cannotStoreIndexOnAsyncCaches(indexName, cache.getName(), cacheMode); } }); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); HashConfigurationBuilder hashConfiguration = builderUsed.clustering().cacheMode(cacheMode).hash().numSegments(3); if (!cacheMode.isReplicated()) { BaseControlledConsistentHashFactory<? extends ConsistentHash> chf = cacheMode.isScattered() ? new TestScatteredConsistentHashFactory() : new TestDefaultConsistentHashFactory(); hashConfiguration.consistentHashFactory(chf); } if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } if (cacheMode.isClustered()) { builderUsed.clustering().stateTransfer().chunkSize(50); enhanceConfiguration(builderUsed); createClusteredCaches(3, CACHE_NAME, builderUsed); } else { enhanceConfiguration(builderUsed); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(builderUsed); cacheManagers.add(cm); cm.defineConfiguration(CACHE_NAME, builderUsed.build()); } }
public static boolean isTriangleAlgorithm(CacheMode cacheMode, boolean transactional) { return cacheMode.isDistributed() && !transactional; }
protected <K, V> Cache<K, V> getLockOwner(Object key, String cacheName) { Configuration c = getCache(0, cacheName).getCacheConfiguration(); if (c.clustering().cacheMode().isInvalidation()) { return getCache(0, cacheName); //for replicated caches only the coordinator acquires lock } else if (!c.clustering().cacheMode().isClustered()) { throw new IllegalStateException("This is not a clustered cache!"); } else { Address address = getCache(0, cacheName).getAdvancedCache().getDistributionManager().getCacheTopology() .getDistribution(key).primary(); for (Cache<K, V> cache : this.<K, V>caches(cacheName)) { if (cache.getAdvancedCache().getRpcManager().getTransport().getAddress().equals(address)) { return cache; } } throw new IllegalStateException(); } }
@Override public String locate(String sessionId) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(sessionId)).primary() : this.cache.getCacheManager().getAddress(); Node node = (address != null) ? this.factory.createNode(address) : null; Map.Entry<String, Void> entry = (node != null) ? this.registry.getEntry(node) : null; if (entry == null) { entry = this.registry.getEntry(this.registry.getGroup().getLocalMember()); } return (entry != null) ? entry.getKey() : null; } }
public static Mode forCacheMode(CacheMode mode) { return mode.isSynchronous() ? SYNC : ASYNC; }
@Override protected int[][] assignOwners(int numSegments, int numOwners, List<Address> members) { if (cacheMode.isDistributed()) { assertEquals(2, numOwners); switch (members.size()) { case 1: return new int[][]{{0}}; case 2: return new int[][]{{0, 1}}; default: return new int[][]{{members.size() - 1, 0}}; } } else if (cacheMode.isScattered()) { return new int[][]{{0}}; } else { throw new IllegalStateException(); } } }
private int handleModeEstimate(int desired, CacheMode mode) { if (mode.isReplicated()) { // A REPL cache always requires just 1 node as all nodes have all data return 1; } return desired; }
/** * Checks if the specified cache is configured in "stateless mode". * * @param cache The cache to check. * * @return {@code true} if the cache is configured in "stateless mode", * else {@code false}. */ public static boolean detectStatelessMode(final Cache cache) { final boolean isLocal = CacheMode.LOCAL.equals(cache.getCacheConfiguration().clustering().cacheMode()); final boolean isSizeOne = 1 == cache.getCacheConfiguration().eviction().size(); if (isLocal && isSizeOne) { return true; } return false; }
if (!cacheMode.isClustered() || cacheMode.isDistributed() && nodeCount == 1) { return;
private static void validateIndexCaches(String indexName, Cache<?, ?>... caches) { Arrays.stream(caches).filter(Objects::nonNull).forEach(cache -> { ClusteringConfiguration clusteringConfiguration = cache.getCacheConfiguration().clustering(); CacheMode cacheMode = clusteringConfiguration.cacheMode(); if (cacheMode.isClustered() && !cacheMode.isSynchronous()) { throw log.cannotStoreIndexOnAsyncCaches(indexName, cache.getName(), cacheMode); } }); }
protected BaseCacheNotifierImplInitialTransferTest(CacheMode mode) { if (mode.isDistributed()) { throw new IllegalArgumentException("This test only works with non distributed cache modes"); } this.cacheMode = mode; }
Node locatePrimaryOwner(I id) { DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); Address address = (dist != null) && !this.cache.getCacheConfiguration().clustering().cacheMode().isScattered() ? dist.getCacheTopology().getDistribution(new Key<>(id)).primary() : null; Node member = (address != null) ? this.nodeFactory.createNode(address) : null; return (member != null) ? member : this.registry.getGroup().getLocalMember(); }
public static Mode forCacheMode(CacheMode mode) { return mode.isSynchronous() ? SYNC : ASYNC; }
static MassIndexStrategy calculateStrategy(EntityIndexBinding indexBinding, Configuration cacheConfiguration) { Set<IndexManager> indexManagers = indexBinding.getIndexManagerSelector().all(); IndexManager indexManager = indexManagers.iterator().next(); boolean sharded = indexManagers.size() > 1; boolean replicated = cacheConfiguration.clustering().cacheMode().isReplicated(); boolean singleMaster = !sharded && indexManager instanceof InfinispanIndexManager; boolean multiMaster = indexManager instanceof AffinityIndexManager; boolean custom = !(indexManager instanceof DirectoryBasedIndexManager); if (singleMaster || custom) { return MassIndexStrategy.SHARED_INDEX_STRATEGY; } if (multiMaster) { return MassIndexStrategy.PER_NODE_PRIMARY; } if (sharded || replicated) { return MassIndexStrategy.PER_NODE_ALL_DATA; } return MassIndexStrategy.PER_NODE_PRIMARY; } }