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); } }
KeyPartitioner keyPartitioner = registry.getComponent(KeyPartitioner.class); if (configuration.segmented()) { handler = new SegmentedRocksDBHandler(cache.getCacheConfiguration().clustering().hash().numSegments(), keyPartitioner); } else {
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); } }
/** * @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; }
public void testKeySegmentFilter() { Cache<Integer, String> cache = getCache(0); int range = 12; // First populate the cache with a bunch of values IntStream.range(0, range).boxed().forEach(i -> cache.put(i, i + "-value")); assertEquals(range, cache.size()); CacheSet<Map.Entry<Integer, String>> entrySet = cache.entrySet(); // Take the first half of the segments int segments = cache.getCacheConfiguration().clustering().hash().numSegments() / 2; AtomicInteger realCount = new AtomicInteger(); KeyPartitioner keyPartitioner = cache.getAdvancedCache().getComponentRegistry().getComponent(KeyPartitioner.class); cache.forEach((k, v) -> { if (segments >= keyPartitioner.getSegment(k)) { realCount.incrementAndGet(); } }); assertEquals(realCount.get(), createStream(entrySet).filterKeySegments( IntStream.range(0, segments).boxed().collect(Collectors.toSet())).count()); }
@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) { } }
@Override public void initialize(Properties properties, BuildContext buildContext) { ServiceManager serviceManager = buildContext.getServiceManager(); ComponentRegistryService componentRegistryService = serviceManager.requestService(ComponentRegistryService.class); this.componentRegistry = componentRegistryService.getComponentRegistry(); CacheManagerService cacheManagerService = serviceManager.requestService(CacheManagerService.class); EmbeddedCacheManager embeddedCacheManager = cacheManagerService.getEmbeddedCacheManager(); rpcManager = componentRegistry.getComponent(RpcManager.class); String cacheName = componentRegistry.getCacheName(); ClusteringConfiguration clusteringConfiguration = embeddedCacheManager.getCacheConfiguration(cacheName).clustering(); int numberOfShards = getNumberOfShards(properties); shardAllocatorManager = this.componentRegistry.getComponent(ShardAllocatorManager.class); shardAllocatorManager.initialize(numberOfShards, clusteringConfiguration.hash().numSegments()); if (log.isDebugEnabled()) { log.debugf("Initializing ShardIdProvider with %d shards", numberOfShards); } }
@Override public void initialize(Properties properties, BuildContext buildContext) { ServiceManager serviceManager = buildContext.getServiceManager(); ComponentRegistryService componentRegistryService = serviceManager.requestService(ComponentRegistryService.class); this.componentRegistry = componentRegistryService.getComponentRegistry(); CacheManagerService cacheManagerService = serviceManager.requestService(CacheManagerService.class); EmbeddedCacheManager embeddedCacheManager = cacheManagerService.getEmbeddedCacheManager(); rpcManager = componentRegistry.getComponent(RpcManager.class); String cacheName = componentRegistry.getCacheName(); ClusteringConfiguration clusteringConfiguration = embeddedCacheManager.getCacheConfiguration(cacheName).clustering(); Integer numberOfShards = getNumberOfShards(properties); shardAllocatorManager = this.componentRegistry.getComponent(ShardAllocatorManager.class); shardAllocatorManager.initialize(numberOfShards, clusteringConfiguration.hash().numSegments()); if (log.isDebugEnabled()) { log.debugf("Initializing ShardIdProvider with %d shards", numberOfShards); } }
void countWithSegments(ToIntBiFunction<SegmentedAdvancedLoadWriteStore<?, ?>, IntSet> countFunction) { Cache<byte[], byte[]> cache = localCacheManager.getCache(REMOTE_CACHE); RemoteStore rs = (RemoteStore) cl; rs.write(marshalledEntry(internalCacheEntry("k1", "v1", 100))); Iterator<byte[]> iter = cache.keySet().iterator(); assertTrue(iter.hasNext()); byte[] key = iter.next(); assertFalse(iter.hasNext()); KeyPartitioner keyPartitioner = TestingUtil.extractComponent(cache, KeyPartitioner.class); int segment = keyPartitioner.getSegment(key); // Publish keys should return our key if we use a set that contains that segment assertEquals(1, countFunction.applyAsInt(rs, IntSets.immutableSet(segment))); // Create int set that includes all segments but the one that maps to the key int maxSegments = cache.getCacheConfiguration().clustering().hash().numSegments(); IntSet intSet = IntSets.mutableEmptySet(maxSegments); for (int i = 0; i < maxSegments; ++i) { if (i != segment) { intSet.set(i); } } // Publish keys shouldn't return our key since the IntSet doesn't contain our segment assertEquals(0, countFunction.applyAsInt(rs, intSet)); }
@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; }
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()); }
assertTrue(c.clustering().l1().enabled()); assertEquals(0.0f, c.clustering().hash().capacityFactor()); if (!deprecated) assertEquals(1000, c.clustering().hash().numSegments());
assertEquals(4, c.clustering().hash().numOwners()); assertEquals(35000, c.clustering().remoteTimeout()); assertEquals(2, c.clustering().hash().numSegments()); assertTrue(c.clustering().hash().consistentHashFactory() instanceof SyncConsistentHashFactory); assertTrue(c.clustering().partitionHandling().enabled());