XA模式下Ehcache无法将数据溢出到磁盘(NotSerializedException)

发布于 2024-11-03 17:51:02 字数 1903 浏览 4 评论 0原文

我正在使用 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 个的预期工作。

现在,如果我将 diskPersistentfalse< /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 Integertype 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橪书 2024-11-10 17:51:02

一切都应该按照您的预期工作,但您刚刚发现了一个错误,该错误完全阻止开源磁盘持久存储在任何事务模式下工作。

请在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文