1

我正在用 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从更改falsetrue,则在 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 切换到事务模式会使其将Integertype 的原始值替换为 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

完整地说,在使用 Atomikos 事务管理器时也会发生这种情况,并且在不使用 XA 模式时可以完美地工作。

问题是:有没有办法混合 XA 事务和磁盘溢出?

4

1 回答 1

2

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

请在 Ehcache JIRA (https://jira.terracotta.org/jira/browse/EHC) 中报告问题,我们会尽快修复。

于 2011-04-26T17:22:18.650 回答