XA模式下Ehcache无法将数据溢出到磁盘(NotSerializedException)
我正在使用 Ehcache 试验 XA 事务。目前我正在使用 Spring 事务管理和 Bitronix 作为事务管理器。
我使用以下方法创建、配置和填充缓存:
@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));
}
}
一切工作正常,并且 Ehcache 按已驱逐元素超过 70 个的预期工作。
现在,如果我将 diskPersistent
从 false< /code> 为
true
,当 Ehcache 尝试将某些元素复制到磁盘存储时,它不会立即工作,但出现以下异常:
[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
这是预期将 Ehcache 切换为事务性模式使其用 SoftLock
替换 Integer
类型的原始值:
[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
完整地说,这在使用 Atomikos 事务管理器时也会发生,并且在不使用 XA 模式时可以完美地工作。
问题是:有没有办法混合 XA 事务和磁盘溢出?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一切都应该按照您的预期工作,但您刚刚发现了一个错误,该错误完全阻止开源磁盘持久存储在任何事务模式下工作。
请在 Ehcache JIRA (https://jira.terracotta.org/jira/browse/EHC) 中报告问题,我们将尽快修复。
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.