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
に変更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 をトランザクション モードに切り替えると、typeの元の値が a に置き換えられるため、予期されます。Integer
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 トランザクションとディスク オーバーフローを混在させる方法はあるのかということです。