private static List<Duration> calculateRetryIntervals(Configuration config) { long timeout = config.locking().lockAcquisitionTimeout(); List<Duration> intervals = new LinkedList<>(); // Generate exponential back-off intervals for (long interval = timeout; interval > 1; interval /= 10) { intervals.add(0, Duration.ofMillis(interval)); } intervals.add(0, Duration.ZERO); return intervals; } }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
private static List<Duration> calculateRetryIntervals(Configuration config) { long timeout = config.locking().lockAcquisitionTimeout(); List<Duration> intervals = new LinkedList<>(); // Generate exponential back-off intervals for (long interval = timeout; interval > 1; interval /= 10) { intervals.add(0, Duration.ofMillis(interval)); } intervals.add(0, Duration.ZERO); return intervals; } }
private static List<Duration> calculateRetryIntervals(Configuration config) { long timeout = config.locking().lockAcquisitionTimeout(); List<Duration> intervals = new LinkedList<>(); // Generate exponential back-off intervals for (long interval = timeout; interval > 1; interval /= 10) { intervals.add(0, Duration.ofMillis(interval)); } intervals.add(0, Duration.ZERO); return intervals; } }
@Override public void call() { Configuration cfg = cm.getCache().getCacheConfiguration(); assertEquals(IsolationLevel.NONE, cfg.locking().isolationLevel()); } });
@Override public void call() { Configuration cfg = cm.getCache().getCacheConfiguration(); assertEquals(IsolationLevel.READ_COMMITTED, cfg.locking().isolationLevel()); } });
@Override public Properties getCacheProperties(String containerName, String cacheName) { EmbeddedCacheManager manager = this.cm; if (manager == null) { return null; } String realCacheName = "{" + containerName + "}_{" + cacheName + "}"; if (!manager.cacheExists(realCacheName)) { return null; } Configuration conf = manager.getCache(realCacheName).getAdvancedCache() .getCacheConfiguration(); Properties p = new Properties(); p.setProperty(IClusterServices.cacheProps.TRANSACTION_PROP.toString(), conf.transaction().toString()); p.setProperty(IClusterServices.cacheProps.CLUSTERING_PROP.toString(), conf.clustering().toString()); p.setProperty(IClusterServices.cacheProps.LOCKING_PROP.toString(), conf .locking().toString()); return p; }
/** * Checks if the configuration (and the transaction manager) is able to handle client transactions. */ private void validateConfiguration(AdvancedCache<byte[], byte[]> cache) { Configuration configuration = cache.getCacheConfiguration(); if (!configuration.transaction().transactionMode().isTransactional()) { throw log.expectedTransactionalCache(cache.getName()); } if (configuration.locking().isolationLevel() != IsolationLevel.REPEATABLE_READ) { throw log.unexpectedIsolationLevel(cache.getName()); } //TODO because of ISPN-7672, optimistic and total order transactions needs versions. however, versioning is currently broken if (configuration.transaction().lockingMode() == LockingMode.OPTIMISTIC || configuration.transaction().transactionProtocol() == TransactionProtocol.TOTAL_ORDER) { //no Log. see comment above throw new IllegalStateException( String.format("Cache '%s' cannot use Optimistic neither Total Order transactions.", cache.getName())); } }
public void testNullFoundButLoaderReceivedValueLaterInTransaction() throws SystemException, NotSupportedException { assertNotInCacheAndStore("k1"); tm.begin(); try { assertNull(cache.get("k1")); // Now simulate that someone else wrote to the store while during our tx store.write(new MarshalledEntryImpl("k1", "v1", null, sm)); IsolationLevel level = cache.getCacheConfiguration().locking().isolationLevel(); switch(level) { case READ_COMMITTED: assertEquals("v1", cache.get("k1")); break; case REPEATABLE_READ: assertNull(cache.get("k1")); break; default: fail("Unsupported isolation " + level + " - please change test to add desired outcome for isolation level"); } } finally { tm.rollback(); } }
public DistributedCacheManager(LocalDistributableSessionManager manager, Cache<String, Map<Object, Object>> cache, Registry<String, Void> registry, SharedLocalYieldingClusterLockManager lockManager, SessionAttributeStorage<T> attributeStorage, BatchingManager batchingManager, CacheInvoker invoker, KeyAffinityServiceFactory affinityFactory) { this.manager = manager; this.lockManager = lockManager; this.cache = cache; this.attributeStorage = attributeStorage; this.batchingManager = batchingManager; this.invoker = new ForceSynchronousCacheInvoker(invoker); this.lockTimeout = this.cache.getCacheConfiguration().locking().lockAcquisitionTimeout(); Configuration configuration = this.cache.getCacheConfiguration(); this.passivationEnabled = configuration.loaders().passivation() && !configuration.loaders().shared() && !configuration.loaders().cacheLoaders().isEmpty(); this.persistenceEnabled = !configuration.loaders().passivation() && !configuration.loaders().cacheLoaders().isEmpty(); this.registry = registry; this.affinity = affinityFactory.createService(cache, this); }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
public InfinispanCacheProperties(Configuration config) { this.transactional = config.transaction().transactionMode().isTransactional(); this.lockOnWrite = this.transactional && (config.transaction().lockingMode() == LockingMode.PESSIMISTIC); this.lockOnRead = this.lockOnWrite && (config.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ); boolean clustered = config.clustering().cacheMode().needsStateTransfer(); boolean hasStore = config.persistence().usingStores(); this.marshalling = clustered || hasStore; this.persistent = clustered || (hasStore && !config.persistence().passivation()); }
@Test(groups = "functional", expectedExceptions = { CacheException.class }) public void testLockAcquisitionTimeout() throws Exception { AdvancedCache<Object, Object> cache1 = advancedCache(0, "syncReplCache"); AdvancedCache<Object, Object> cache2 = advancedCache(1, "syncReplCache"); cache1.getCacheConfiguration().locking().lockAcquisitionTimeout(10); cache2.getCacheConfiguration().locking().lockAcquisitionTimeout(10); TestingUtil.blockUntilViewsReceived(10000, cache1, cache2); // get a lock on cache 2 and hold on to it. EmbeddedTransactionManager tm = (EmbeddedTransactionManager) TestingUtil.getTransactionManager(cache2); tm.begin(); cache2.put("block", "block"); assertTrue(tm.getTransaction().runPrepare()); tm.suspend(); cache1.put("block", "v"); }
@Test public void testIfSpringEmbeddedCacheManagerFactoryBeanAllowesOverridingConfigurationBuilder() throws Exception { ConfigurationBuilder overriddenBuilder = new ConfigurationBuilder(); overriddenBuilder.locking().concurrencyLevel(100); objectUnderTest = SpringEmbeddedCacheManagerFactoryBeanBuilder .defaultBuilder().fromFile(NAMED_ASYNC_CACHE_CONFIG_LOCATION, getClass()) .withConfigurationBuilder(overriddenBuilder).build(); final SpringEmbeddedCacheManager springEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals( "Concurrency value of LockingLocking for cache configured in" + CACHE_NAME_FROM_CONFIGURATION_FILE + "is equal to 5000. But later Configuration Builder overrides " + "this setting to 100. Obviously created SpringEmbeddedCacheManagerFactoryBean does not support " + "this kind of overriding.", 100, springEmbeddedCacheManager.getNativeCacheManager().getDefaultCacheConfiguration().locking() .concurrencyLevel()); }
@Test public void testIfSpringEmbeddedCacheManagerFactoryBeanAllowesOverridingConfigurationBuilder() throws Exception { ConfigurationBuilder overriddenBuilder = new ConfigurationBuilder(); overriddenBuilder.locking().concurrencyLevel(100); objectUnderTest = SpringEmbeddedCacheManagerFactoryBeanBuilder .defaultBuilder().fromFile(NAMED_ASYNC_CACHE_CONFIG_LOCATION, getClass()) .withConfigurationBuilder(overriddenBuilder).build(); final SpringEmbeddedCacheManager springEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals( "Concurrency value of LockingLocking for cache configured in" + CACHE_NAME_FROM_CONFIGURATION_FILE + "is equal to 5000. But later Configuration Builder overrides " + "this setting to 100. Obviously created SpringEmbeddedCacheManagerFactoryBean does not support " + "this kind of overriding.", 100, springEmbeddedCacheManager.getNativeCacheManager().getDefaultCacheConfiguration().locking() .concurrencyLevel()); }
@Test public void testIfSpringEmbeddedCacheManagerFactoryBeanAllowesOverridingConfigurationBuilder() throws Exception { ConfigurationBuilder overriddenBuilder = new ConfigurationBuilder(); overriddenBuilder.locking().concurrencyLevel(100); objectUnderTest = SpringEmbeddedCacheManagerFactoryBeanBuilder .defaultBuilder().fromFile(NAMED_ASYNC_CACHE_CONFIG_LOCATION, getClass()) .withConfigurationBuilder(overriddenBuilder).build(); final SpringEmbeddedCacheManager springEmbeddedCacheManager = objectUnderTest.getObject(); assertEquals( "Concurrency value of LockingLocking for cache configured in" + CACHE_NAME_FROM_CONFIGURATION_FILE + "is equal to 5000. But later Configuration Builder overrides " + "this setting to 100. Obviously created SpringEmbeddedCacheManagerFactoryBean does not support " + "this kind of overriding.", 100, springEmbeddedCacheManager.getNativeCacheManager().getDefaultCacheConfiguration().locking() .concurrencyLevel()); }
public void testPartialOverride() { ConfigurationBuilder baseBuilder = new ConfigurationBuilder(); baseBuilder.memory().size(200).storageType(StorageType.BINARY); Configuration base = baseBuilder.build(); ConfigurationBuilder overrideBuilder = new ConfigurationBuilder(); overrideBuilder.read(base).locking().concurrencyLevel(31); Configuration override = overrideBuilder.build(); assertEquals(200, base.memory().size()); assertEquals(200, override.memory().size()); assertEquals(StorageType.BINARY, base.memory().storageType()); assertEquals(StorageType.BINARY, override.memory().storageType()); assertEquals(32, base.locking().concurrencyLevel()); assertEquals(31, override.locking().concurrencyLevel()); }
public void testUserDefinedTimeouts() { HotRodServerConfigurationBuilder builder = new HotRodServerConfigurationBuilder(); builder.topologyLockTimeout(26000).topologyReplTimeout(31000); withClusteredServer(builder, (cfg, distSyncTimeout) -> { assertEquals(cfg.locking().lockAcquisitionTimeout(), 26000); assertEquals(cfg.clustering().remoteTimeout(), 31000); assertTrue(cfg.clustering().stateTransfer().fetchInMemoryState()); assertEquals(cfg.clustering().stateTransfer().timeout(), 31000 + distSyncTimeout); assertTrue(cfg.persistence().stores().isEmpty()); }); }
public void testGlobalConfig() throws Exception { ConfigurationBuilderHolder holder = parse(); GlobalConfiguration gc = holder.getGlobalConfigurationBuilder().build(); BlockingThreadPoolExecutorFactory listenerThreadPool = gc.listenerThreadPool().threadPoolFactory(); assertEquals(2, listenerThreadPool.maxThreads()); BlockingThreadPoolExecutorFactory persistenceThreadPool = gc.persistenceThreadPool().threadPoolFactory(); assertEquals(4, persistenceThreadPool.maxThreads()); Properties transportProps = gc.transport().properties(); assertEquals("jgroups-tcp.xml", transportProps.get("configurationFile")); Configuration configuration = holder.getDefaultConfigurationBuilder().build(); assertEquals(IsolationLevel.READ_COMMITTED, configuration.locking().isolationLevel()); } }