【发布时间】:2019-03-04 05:05:15
【问题描述】:
我们尝试使用 infinispan 作为带有读锁的远程缓存。客户端正在使用“put”进行读取以获取密钥锁定,如 悲观事务缓存部分中描述的 infinispan 文档“当 cache.put(k1,v1) 返回时, k1 被锁定,集群中任何地方运行的其他事务都不能写入它。读取 k1 仍然是可能的。当事务完成(提交或回滚)时,k1 上的锁被释放。 所以场景:
transactionManager.begin();
// read with put to acquire write lock
String value = getRemoteCache().get(key);
getRemoteCache().put(key, value);
// do smthing with the value
getRemoteCache().put(key, newValue);
transactionManager.commit();
远程缓存配置为带有悲观锁定的事务性:
<local-cache name="default"> <locking isolation="REPEATABLE_READ" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
<transaction mode="NON_XA" locking="PESSIMISTIC"/>
</local-cache>
并且客户端正在使用配置访问 remoteCacheManager 作为 HOTROD 客户端:
ConfigurationBuilder builder = new ConfigurationBuilder();
// add more configurations ?
builder.transaction().transactionManagerLookup(GenericTransactionManagerLookup.getInstance());
builder.transaction().transactionMode(TransactionMode.NON_XA);
builder.addServer().host(readServerHostConfiguration()).port(readServerPortConfiguration());
return new RemoteCacheManager(builder.build(), true);
尽管客户端可以同时“使用 put 读取”一个值,但 Concurent 客户端在读取该值时并没有收到异常,而是稍后通过提交事务。这是预期的行为吗?
【问题讨论】:
标签: java caching infinispan infinispan-9