public ConsistentHashLocality(Cache<?, ?> cache, ConsistentHash hash) { this.topology = new LocalizedCacheTopology(cache.getCacheConfiguration().clustering().cacheMode(), new CacheTopology(0, 0, hash, null, CacheTopology.Phase.NO_REBALANCE, Collections.emptyList(), Collections.emptyList()), cache.getCacheConfiguration().clustering().hash().keyPartitioner(), cache.getCacheManager().getAddress(), true); }
protected AbstractHashDistAwareResponse createHashDistAwareResp(int topologyId, Map<Address, ServerAddress> serverEndpointsMap, Configuration cfg) { return new HashDistAwareResponse(topologyId, serverEndpointsMap, 0, cfg.clustering().hash().numOwners(), Constants.DEFAULT_CONSISTENT_HASH_VERSION_1x, Integer.MAX_VALUE); }
@Override protected AbstractHashDistAwareResponse createHashDistAwareResp(int topologyId, Map<Address, ServerAddress> serverEndpointsMap, Configuration cfg) { return new HashDistAware11Response(topologyId, serverEndpointsMap, cfg.clustering().hash().numOwners(), Constants.DEFAULT_CONSISTENT_HASH_VERSION_1x, Integer.MAX_VALUE, 1); }
@ManagedAttribute(description = "Number of replicas for each key", displayName = "Replication Degree") public double getReplicationDegree() { switch (cacheConfiguration.clustering().cacheMode()) { case DIST_SYNC: case DIST_ASYNC: return cacheConfiguration.clustering().hash().numOwners(); case REPL_ASYNC: case REPL_SYNC: return rpcManager.getMembers().size(); default: return 1; } }
public ConsistentHashLocality(Cache<?, ?> cache, ConsistentHash hash) { this.topology = new LocalizedCacheTopology(cache.getCacheConfiguration().clustering().cacheMode(), new CacheTopology(0, 0, hash, null, CacheTopology.Phase.NO_REBALANCE, Collections.emptyList(), Collections.emptyList()), cache.getCacheConfiguration().clustering().hash().keyPartitioner(), cache.getCacheManager().getAddress(), true); }
/** * @return how many segments there are across all nodes or 1 if the config is not segmented (all shared) */ protected int calculateTotalSegmentsForAllNodes() { return segmented ? c1.getCacheConfiguration().clustering().hash().numSegments() : 1; }
protected void checkConsistencyAcrossCluster(String cacheName, Configuration configuration) { // Initialize the partitioner to ensure we can compare config equality configuration.clustering().hash().keyPartitioner().init(configuration.clustering().hash()); for (EmbeddedCacheManager m : cacheManagers) { Configuration actualConfiguration = m.getCacheConfiguration(cacheName); assertNotNull("Cache " + cacheName + " missing from " + m, actualConfiguration); assertEquals(configuration, actualConfiguration); Cache<Object, Object> cache = m.getCache(cacheName); assertEquals(cacheManagers.size(), cache.getAdvancedCache().getRpcManager().getMembers().size()); } }
protected MagicKey magicKey(Cache<Object, String> cache1, Cache<Object, String> cache2) { if (cache1.getCacheConfiguration().clustering().hash().numOwners() < 2) { return new MagicKey(cache1); } else { return new MagicKey(cache1, cache2); } }
public void testConsistentHashFactory() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC); Configuration c = cb.build(); Assert.assertNull(c.clustering().hash().consistentHashFactory()); SyncConsistentHashFactory consistentHashFactory = new SyncConsistentHashFactory(); cb.clustering().hash().consistentHashFactory(consistentHashFactory); c = cb.build(); Assert.assertSame(c.clustering().hash().consistentHashFactory(), consistentHashFactory); } }
/** * Enable the clustering.hash.groups configuration if it's not already enabled. * <p> * Infinispan requires this option enabled because we are using fine grained maps. * The function will log a warning if the property is disabled. * * @return the updated configuration */ private static Configuration enableClusteringHashGroups(String cacheName, Configuration configuration) { if ( configuration.clustering().hash().groups().enabled() ) { return configuration; } LOG.clusteringHashGroupsMustBeEnabled( cacheName ); ConfigurationBuilder builder = new ConfigurationBuilder().read( configuration ); builder.clustering().hash().groups().enabled(); return builder.build(); }
/** * Enable the clustering.hash.groups configuration if it's not already enabled. * <p> * Infinispan requires this option enabled because we are using fine grained maps. * The function will log a warning if the property is disabled. * * @return the updated configuration */ private static Configuration enableClusteringHashGroups(String cacheName, Configuration configuration) { if ( configuration.clustering().hash().groups().enabled() ) { return configuration; } LOG.clusteringHashGroupsMustBeEnabled( cacheName ); ConfigurationBuilder builder = new ConfigurationBuilder().read( configuration ); builder.clustering().hash().groups().enabled(); return builder.build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void numVirtualNodes() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC); cb.clustering().hash().numSegments(5); Configuration c = cb.build(); Assert.assertEquals(5, c.clustering().hash().numSegments()); // negative test cb.clustering().hash().numSegments(0); }
public void testNumSegments() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC); cb.clustering().hash().numSegments(5); Configuration c = cb.build(); Assert.assertEquals(5, c.clustering().hash().numSegments()); try { cb.clustering().hash().numSegments(0); Assert.fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } }
public void testNumOwners() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC); cb.clustering().hash().numOwners(5); Configuration c = cb.build(); Assert.assertEquals(5, c.clustering().hash().numOwners()); try { cb.clustering().hash().numOwners(0); Assert.fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNumOwners() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC); cb.clustering().hash().numOwners(5); Configuration c = cb.build(); Assert.assertEquals(5, c.clustering().hash().numOwners()); // negative test cb.clustering().hash().numOwners(0); }
@Override protected void createCacheManagers() throws Throwable { ConfigurationBuilder defaultConfig = getDefaultClusteredCacheConfig(cacheMode); log.debug("defaultConfig = " + defaultConfig.build().clustering().hash().numOwners()); defaultConfig.clustering().l1().disable().stateTransfer().fetchInMemoryState(true); createClusteredCaches(5, defaultConfig); ConsistentHash hash = cache(0).getAdvancedCache().getDistributionManager().getWriteConsistentHash(); List<Address> members = hash.getMembers(); addresses = members.toArray(new Address[members.size()]); }
public void testSimpleDistributedClusterModeDefault() throws Exception { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(DIST_SYNC) .hash().numOwners(3).numSegments(51); cm = TestCacheManagerFactory.createClusteredCacheManager(builder); cm.defineConfiguration("my-cache", builder.build()); Cache<?, ?> cache = cm.getCache("my-cache"); // These are all overridden values ClusteringConfiguration clusteringCfg = cache.getCacheConfiguration().clustering(); assertEquals(DIST_SYNC, clusteringCfg.cacheMode()); assertEquals(3, clusteringCfg.hash().numOwners()); assertEquals(51, clusteringCfg.hash().numSegments()); }
public void testSimpleDistributedClusterModeNamedCache() throws Exception { final String cacheName = "my-cache"; final Configuration config = new ConfigurationBuilder() .clustering().cacheMode(DIST_SYNC) .hash().numOwners(3).numSegments(51).build(); cm = TestCacheManagerFactory.createClusteredCacheManager(); cm.defineConfiguration(cacheName, config); Cache<?, ?> cache = cm.getCache(cacheName); ClusteringConfiguration clusteringCfg = cache.getCacheConfiguration().clustering(); assertEquals(DIST_SYNC, clusteringCfg.cacheMode()); assertEquals(3, clusteringCfg.hash().numOwners()); assertEquals(51, clusteringCfg.hash().numSegments()); }
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder cb = getDefaultStandaloneCacheConfig(false); configurePersistence(cb); EmbeddedCacheManager manager = TestCacheManagerFactory.createCacheManager(cb); cache = manager.getCache(); ComponentRegistry componentRegistry = cache.getAdvancedCache().getComponentRegistry(); PersistenceManagerImpl pm = (PersistenceManagerImpl) componentRegistry.getComponent(PersistenceManager.class); sm = pm.getMarshaller(); store = TestingUtil.getFirstLoader(cache); keys = new Set[cache.getCacheConfiguration().clustering().hash().numSegments()]; return manager; }
private static void assertCounterAndCacheConfiguration(CounterManagerConfiguration config, Configuration cacheConfig) { AssertJUnit.assertEquals(CacheMode.DIST_SYNC, cacheConfig.clustering().cacheMode()); AssertJUnit.assertEquals(config.numOwners(), cacheConfig.clustering().hash().numOwners()); AssertJUnit.assertEquals(config.reliability() == Reliability.CONSISTENT, cacheConfig.clustering().partitionHandling().whenSplit() == PartitionHandling.DENY_READ_WRITES); AssertJUnit.assertFalse(cacheConfig.clustering().l1().enabled()); AssertJUnit.assertEquals(TransactionMode.NON_TRANSACTIONAL, cacheConfig.transaction().transactionMode()); }