I am trying to set external transaction manager for Ignite Cache , however it appers that Factory is ignored and create is not called... The Factory Implementation is:
public class TransactionManagerFactory implements Factory<TransactionManager> {
private static final long serialVersionUID = 1L;
private transient IgniteCache igniteCache;
public TransactionManagerFactory(IgniteCache igniteCache) {
this.igniteCache=igniteCache;
}
@Override
public TransactionManager create() {
return this.igniteCache.getTransactionManager();
}
}
The Ignite transaction client configuration is set is following:
TransactionConfiguration txConfiguration=new TransactionConfiguration();
txConfiguration.setDeadlockTimeout(acquireTimeout);
txConfiguration.setDefaultTxIsolation(TransactionIsolation.READ_COMMITTED);
txConfiguration.setDefaultTxConcurrency(TransactionConcurrency.PESSIMISTIC);
TransactionManagerFactory txFactory=new TransactionManagerFactory(this);
txConfiguration.setTxManagerFactory(txFactory);
this.clientConfig.setTransactionConfiguration(txConfiguration);
The cache is getting created as:
CacheConfiguration<Object, Object> cacheCfg = new CacheConfiguration<Object, Object>(this.name);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
this.cache = this.instance.getOrCreateCache(cacheCfg);
However when in tests cache is created and connected to remote node and transaction is created by calling transactionManager.begin(); The instance.transactions().tx() is returning null , while transactionManager.getTransaction() return TransactionImpl{xid=Xid{formatId=1, globalTransactionId=8EA3F99497B60948C0E22AEBA1F54C460000000000000002,branchQualifier=8EA3F99497B60948C0E22AEBA1F54C460000000000000002}, status=ACTIVE}
And whenever the transaction is rolled back , the wrotten items persist in cache. Also TransactionManagerFactory.create is not executed at any time.
How can i correctly integrate external transaction manager with ignite cache?
I think you need to add ignite-jta
module to your project in order for Ignite to do anything with transaction manager. Otherwise, NoOp implementation is used.
I'm not sure what you're trying to do with your transient IgniteCache logic. It will be null after deserialization and NPE will happen.