问题描述
我正在使用Ehcache进行XA事务处理.目前,我正在使用Spring事务管理和Bitronix作为事务管理器.
我使用以下方法创建,配置和填充缓存:
@Transactional公共无效createCache(){this.cacheConfiguration = new CacheConfiguration("MyCache",5000).diskPersistent(false).eternal(false).diskExpiryThreadIntervalSeconds(1).maxElementsInMemory(70).transactionalMode(TransactionalMode.XA);最终配置config = new Configuration();config.setDefaultCacheConfiguration(this.cacheConfiguration);最后的DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();diskStoreConfiguration.setPath("cache");config.addDiskStore(diskStoreConfiguration);this.cacheManager = new CacheManager(config);this.cacheConfiguration.name("primaryCache");this.cache =新的Cache(this.cacheConfiguration);this.cacheManager.addCache(this.cache);对于(int i = 0; i< 100; i ++){最终的Integer值= Integer.valueOf(i);this.cache.put(new Element(value,value));}}
一切正常,Ehcache的运行正常,超过了70个被逐出的元素.
现在,如果我将 diskPersistent
从 false
更改为 true
,则当Ehcache尝试将某些元素复制到磁盘时,该功能将无法正常工作存储,但以下情况除外:
[primaryCache.data]错误n.s.e.s.c.f.DiskStorageFactory btm-gtrid = 737072696E672D62746D0000012F9296448C00000000-磁盘写入0失败(它将被逐出):java.io.NotSerializableException:net.sf.ehcache.transaction.ReadCommittedSoftLockImpl
这是预期,因为将Ehcache切换为事务模式会使其将 Integer
类型的原始值替换为 SoftLock
:
[main]调试n.s.e.t.local.LocalTransactionStore ehcache-txid = 0,btm-gtrid = 737072696E672D62746D0000012F9296448C00000000-放置:缓存[primaryCache]密钥[0]不在,已插入软锁
为完整起见,这在使用Atomikos事务管理器时也会发生,并且在不使用XA模式时也可以正常工作.
问题是:有没有办法混合XA事务和磁盘溢出?
一切都应按您预期的方式运行,但是您刚刚发现了一个错误,该错误完全阻止了开源磁盘持久性存储以任何事务模式工作./p>
请在Ehcache JIRA(https://jira.terracotta.org/jira/browse/EHC)中报告该问题,我们将尽快解决.
I'm experimenting XA transactions with Ehcache. Currently I'm using Spring transaction management and Bitronix as transaction manager.
I create, configure and fill up a cache using the method below:
@Transactional
public void createCache() {
this.cacheConfiguration = new CacheConfiguration("MyCache", 5000).diskPersistent(false).eternal(false)
.diskExpiryThreadIntervalSeconds(1).maxElementsInMemory(70).transactionalMode(TransactionalMode.XA);
final Configuration config = new Configuration();
config.setDefaultCacheConfiguration(this.cacheConfiguration);
final DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
diskStoreConfiguration.setPath("cache");
config.addDiskStore(diskStoreConfiguration);
this.cacheManager = new CacheManager(config);
this.cacheConfiguration.name("primaryCache");
this.cache = new Cache(this.cacheConfiguration);
this.cacheManager.addCache(this.cache);
for (int i = 0; i < 100; i++) {
final Integer value = Integer.valueOf(i);
this.cache.put(new Element(value, value));
}
}
Everything is working fine and Ehcache works as expected by evicted elements over the count of 70.
Now if I change diskPersistent
from false
to true
, it does not work as soon as Ehcache attempt to copy some element to the disk storage with the following exception:
[primaryCache.data] ERROR n.s.e.s.c.f.DiskStorageFactory btm-gtrid=737072696E672D62746D0000012F9296448C00000000 - Disk Write of 0 failed (it will be evicted instead):
java.io.NotSerializableException: net.sf.ehcache.transaction.ReadCommittedSoftLockImpl
This is expected as switching Ehcache to transactional mode makes it replace the original values of Integer
type by a SoftLock
:
[main] DEBUG n.s.e.t.local.LocalTransactionStore ehcache-txid=0, btm-gtrid=737072696E672D62746D0000012F9296448C00000000 - put: cache [primaryCache] key [0] was not in, soft lock inserted
To be complete, this also happens when using the Atomikos transaction manager and works flawlessly when not using XA mode.
The question is: is there a way to mix XA transactions and disk overflow ?
Everything should work as you expect them to but you've just found a bug which completely prevents the Open Source disk persistent store from working with any transactional mode.
Please report the problem in the Ehcache JIRA (https://jira.terracotta.org/jira/browse/EHC) and we'll fix it as soon as we can.
这篇关于Ehcache无法在XA模式下将数据溢出到磁盘(NotSerializableException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!