@SuppressWarnings("deprecation") @Override public void accept(ConfigurationBuilder builder) { ClusteringConfigurationBuilder clustering = builder.clustering(); CacheMode mode = clustering.cacheMode(); clustering.cacheMode(mode.needsStateTransfer() ? CacheMode.REPL_SYNC : CacheMode.LOCAL); // don't use DefaultConsistentHashFactory for REPL caches (WFLY-9276) clustering.hash().consistentHashFactory(null); clustering.l1().disable(); // Workaround for ISPN-8722 AttributeSet attributes = TemplateConfigurationServiceConfigurator.getAttributes(clustering); attributes.attribute(ClusteringConfiguration.BIAS_ACQUISITION).reset(); attributes.attribute(ClusteringConfiguration.BIAS_LIFESPAN).reset(); attributes.attribute(ClusteringConfiguration.INVALIDATION_BATCH_SIZE).reset(); // Ensure we use the default data container builder.dataContainer().dataContainer(null); // Disable expiration builder.expiration().lifespan(-1).maxIdle(-1); // Disable eviction builder.memory().size(-1).evictionStrategy(EvictionStrategy.MANUAL); builder.persistence().clearStores(); StateTransferConfigurationBuilder stateTransfer = clustering.stateTransfer().fetchInMemoryState(mode.needsStateTransfer()); attributes = TemplateConfigurationServiceConfigurator.getAttributes(stateTransfer); attributes.attribute(StateTransferConfiguration.AWAIT_INITIAL_TRANSFER).reset(); attributes.attribute(StateTransferConfiguration.TIMEOUT).reset(); } }
@Override public PartitionHandlingConfiguration get() { return new ConfigurationBuilder().clustering().partitionHandling() .whenSplit(this.enabled ? PartitionHandling.DENY_READ_WRITES : PartitionHandling.ALLOW_READ_WRITES) .mergePolicy(MergePolicy.NONE) .create(); }
@Override public void accept(ConfigurationBuilder builder) { builder.clustering() .cacheMode(this.mode) .remoteTimeout(this.remoteTimeout, TimeUnit.MILLISECONDS) ; super.accept(builder); } }
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); } }
@Override public void accept(ConfigurationBuilder builder) { super.accept(builder); builder.clustering().partitionHandling().read(this.partitionHandling.get()); builder.clustering().stateTransfer().read(this.stateTransfer.get()); SitesConfigurationBuilder sitesBuilder = builder.sites(); sitesBuilder.read(this.backups.get()); } }
@Override public void call() { ConfigurationBuilder builder = new ConfigurationBuilder(); CacheMode cacheMode = CacheMode.DIST_ASYNC; // DIST_ASYNC isn't default so it should stay applied builder.clustering().cacheMode(cacheMode); String distCacheName = "dist-cache"; cm.defineConfiguration(distCacheName, builder.build()); String templateName = "template"; cm.defineConfiguration(templateName, new ConfigurationBuilder().template(true).build()); Cache cache = cm.getCache(distCacheName, templateName); assertEquals(cacheMode, cache.getCacheConfiguration().clustering().cacheMode()); } });
@Test public void testDefaultSegmented() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .cacheMode(CacheMode.DIST_ASYNC).build(); assertEquals(DefaultSegmentedDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); 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()); } }
static AdvancedCache getTargetCache(EmbeddedCacheManager manager, Properties properties) { StoreProperties props = new StoreProperties(TARGET, properties); ConfigurationBuilder configBuilder = new ConfigurationBuilder(); String segmentCountString = props.get(SEGMENT_COUNT); // 0 means not enabled int segmentCount = 0; if (segmentCountString != null) { segmentCount = Integer.parseInt(segmentCountString); if (segmentCount < 0) { throw new IllegalArgumentException("Segment count must be > 0"); } } if (segmentCount > 0) { configBuilder.clustering().hash().numSegments(segmentCount); } configBuilder.persistence().addStore(getInitializedStoreBuilder(props)) .purgeOnStartup(true) .segmented(segmentCount > 0); configBuilder.invocationBatching().transaction() .transactionMode(TransactionMode.TRANSACTIONAL) .transactionManagerLookup(new EmbeddedTransactionManagerLookup()); String cacheName = props.cacheName(); manager.defineConfiguration(cacheName, configBuilder.build()); return manager.getCache(cacheName).getAdvancedCache().withFlags(Flag.SKIP_CACHE_LOAD); }
protected void createCacheManagers() throws Throwable { ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.REPL_SYNC) .remoteTimeout(30000) .transaction().transactionMode(TransactionMode.TRANSACTIONAL) .invocationBatching().enable() .locking().lockAcquisitionTimeout(60000).useLockStriping(false); EmbeddedCacheManager container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache1 = container.getCache(TEST_CACHE); assert cache1.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); cache1.start(); container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache2 = container.getCache(TEST_CACHE); assert cache2.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); }
@Override protected void createCacheManagers() throws Throwable { builderUsed = new ConfigurationBuilder(); builderUsed.clustering().cacheMode(cacheMode); if (transactional) { builderUsed.transaction().transactionMode(TransactionMode.TRANSACTIONAL); } builderUsed.clustering().hash().numOwners(2); builderUsed.clustering().stateTransfer().chunkSize(50); createClusteredCaches(1, CACHE_NAME, builderUsed); }
private Configuration getInternalCacheConfig() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); // allow the registry to work for local caches as well as clustered caches CacheMode cacheMode = cacheManager.getGlobalComponentRegistry().getGlobalConfiguration().isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL; configurationBuilder.clustering().cacheMode(cacheMode); // use invocation batching (cache-only transactions) for high consistency as writes are expected to be rare in this cache configurationBuilder.transaction().transactionMode(TransactionMode.TRANSACTIONAL) .transactionManagerLookup(null).invocationBatching().enable(); configurationBuilder.security().authorization().disable(); return configurationBuilder.build(); }
public void testForceUnsharedComponents() { ConfigurationBuilder defaultCfg = getDefaultClusteredCacheConfig(CacheMode.REPL_SYNC); defaultCfg .clustering() .stateTransfer() .fetchInMemoryState(false); // cache manager with default configuration cm = TestCacheManagerFactory.createClusteredCacheManager(defaultCfg); // default cache with no overrides Cache c = cm.getCache(); ConfigurationBuilder overrides = TestCacheManagerFactory.getDefaultCacheConfiguration(true); overrides.transaction().transactionManagerLookup(new EmbeddedTransactionManagerLookup()); cm.defineConfiguration("transactional", overrides.build()); Cache transactional = cm.getCache("transactional"); // assert components. assert TestingUtil.extractComponent(c, EvictionManager.class) != null; assert TestingUtil.extractComponent(transactional, EvictionManager.class) != null; assert TestingUtil.extractComponent(c, EvictionManager.class) != TestingUtil.extractComponent(transactional, EvictionManager.class); }
@Override public void call() { // DIST_ASYNC isn't default so it should stay applied CacheMode cacheMode = CacheMode.DIST_ASYNC; String templateName = "dist-cache-template"; cm.defineConfiguration(templateName, new ConfigurationBuilder().clustering().cacheMode(cacheMode).template(true).build()); CacheMode overrideCacheMode = CacheMode.REPL_ASYNC; Configuration overrideConfiguration = new ConfigurationBuilder().clustering().cacheMode(overrideCacheMode).build(); String ourCacheName = "my-cache"; cm.defineConfiguration(ourCacheName, templateName, overrideConfiguration); Cache cache = cm.getCache(ourCacheName); // We expect the override to take precedence assertEquals(overrideCacheMode, cache.getCacheConfiguration().clustering().cacheMode()); } });
public void testClusterCacheTest() { waitForClusterToForm(); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.DIST_SYNC); Configuration configuration = builder.build(); Cache<Object, Object> cache = manager(0).administration().createCache("a", configuration); waitForClusterToForm("a"); assertEquals(cacheManagers.size(), cache.getAdvancedCache().getRpcManager().getMembers().size()); checkConsistencyAcrossCluster("a", configuration); addClusterEnabledCacheManager(); checkConsistencyAcrossCluster("a", configuration); Exceptions.expectException(CacheConfigurationException.class, "ISPN000374: No such template 'nonExistingTemplate' when declaring 'b'", () -> manager(0).administration().createCache("b", "nonExistingTemplate")); // attempt to create an existing cache Exceptions.expectException(CacheConfigurationException.class, "ISPN000507: Cache a already exists", () -> manager(0).administration().createCache("a", configuration)); // getOrCreate should work manager(0).administration().getOrCreateCache("a", configuration); manager(1).administration().removeCache("a"); checkCacheExistenceAcrossCluster("a", false); addClusterEnabledCacheManager(); checkCacheExistenceAcrossCluster("a", false); }
@BeforeMethod protected void setUp() throws Exception { ConfigurationBuilder configurationBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(true); configurationBuilder.transaction().invocationBatching().enable() .clustering().cacheMode(CacheMode.DIST_SYNC) .clustering().hash().numOwners(1) .clustering().stateTransfer().fetchInMemoryState(false); manager1 = TestCacheManagerFactory.createClusteredCacheManager(configurationBuilder); manager1.defineConfiguration("test", configurationBuilder.build()); cache1 = manager1.getCache("test").getAdvancedCache(); ex1 = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator1")); keyAffinityService1 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache1, new RndKeyGenerator(), ex1, KEY_QUEUE_SIZE); log.trace("Address for manager1: " + manager1.getAddress()); manager2 = TestCacheManagerFactory.createClusteredCacheManager(configurationBuilder); manager2.defineConfiguration("test", configurationBuilder.build()); cache2 = manager2.getCache("test").getAdvancedCache(); ex2 = Executors.newSingleThreadExecutor(getTestThreadFactory("KeyGenerator2")); keyAffinityService2 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache2, new RndKeyGenerator(), ex2, KEY_QUEUE_SIZE); log.trace("Address for manager2: " + manager2.getAddress()); TestingUtil.blockUntilViewsReceived(60000, cache1, cache2); Thread.sleep(5000); }
@Override public void call() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.clustering().cacheMode(CacheMode.DIST_SYNC).l1().disable(); cm.defineConfiguration("testConfigCache", cb.build()); Cache<Object, Object> cache = cm.getCache("testConfigCache"); assert !cache.getCacheConfiguration().clustering().l1().enabled(); } });
private Cache getCache() { GlobalConfigurationBuilder gc = GlobalConfigurationBuilder.defaultClusteredBuilder(); ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.REPL_SYNC) .remoteTimeout(30000) .transaction().invocationBatching().enable() .locking().lockAcquisitionTimeout(60000).useLockStriping(false); EmbeddedCacheManager container = TestCacheManagerFactory.createClusteredCacheManager(gc, c); cacheContainers.add(container); container.defineConfiguration("TestCache", c.build()); return container.getCache("TestCache"); } }
private EmbeddedCacheManager createCacheManager(String name1, JChannel ch1) { GlobalConfigurationBuilder gcb1 = new GlobalConfigurationBuilder(); gcb1.transport().nodeName(ch1.getName()).distributedSyncTimeout(10, SECONDS); CustomChannelLookup.registerChannel(gcb1, ch1, name1, false); ConfigurationBuilder replCfg = new ConfigurationBuilder(); replCfg.clustering().cacheMode(CacheMode.REPL_SYNC); replCfg.clustering().stateTransfer().timeout(10, SECONDS); EmbeddedCacheManager cm1 = new DefaultCacheManager(gcb1.build(), replCfg.build(), false); registerCacheManager(cm1); cm1.defineConfiguration(CACHE_NAME, replCfg.build()); return cm1; }
@Test public void testSegmentedL1() { dataContainerFactory.configuration = new ConfigurationBuilder().clustering() .cacheMode(CacheMode.DIST_ASYNC) .l1().enable().build(); assertEquals(L1SegmentedDataContainer.class, this.dataContainerFactory.construct(COMPONENT_NAME).getClass()); }