You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by smurphy <sm...@trustwave.com> on 2018/02/02 21:51:57 UTC
SpringTransactionManager and ChainedTransactionManager
Hello,
I am using SpringTransactionManager & HibernateTransactionManager in a
Spring ChainedTransactionManager in order to rollback all database and cache
updates
in the event of there being any failures in either transaction manager.
I am finding that rollbacks in HibernateTransactionManager do cause
rollbacks in SpringTransactionManager but not vice versa - database changes
are not rolled back when Ignite transactions rollback.
Here are the logs from my test:
2018-02-02 15:09:00,509 DEBUG [unknown 192.168.1.10] main unknown unknown
{AbstractPlatformTransactionManager.java:367} - Creating new transaction
with name [com.dna.chain.service.impl.TestServiceImpl.testeroo]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT; 'chainedTransactionManager'
2018-02-02 15:09:00,514 DEBUG [unknown 192.168.1.10] main unknown unknown
{AbstractPlatformTransactionManager.java:851} - Initiating transaction
rollback
2018-02-02 15:09:00,514 DEBUG [unknown 192.168.1.10] main unknown unknown
{AbstractPlatformTransactionManager.java:1020} - Resuming suspended
transaction after completion of inner transaction
Here are the configured transaction managers:
@Bean
public ChainedTransactionManager chainedTransactionManager(
PlatformTransactionManager hibernateTxMgr, PlatformTransactionManager
igniteTxMgr) {
ChainedTransactionManager transactionManager = new
ChainedTransactionManager(
new PlatformTransactionManager[] { hibernateTxMgr, igniteTxMgr
});
return transactionManager;
}
@Bean
public PlatformTransactionManager hibernateTxMgr(SessionFactory
sessionFactory) {
HibernateTransactionManager manager = new
HibernateTransactionManager(sessionFactory);
return manager;
}
@Bean
public PlatformTransactionManager igniteTxMgr(IgniteSpringBean ignite)
throws IOException {
SpringTransactionManager igniteTxMgr = new
SpringTransactionManager();
igniteTxMgr.setGridName(ignite.getConfiguration().getGridName());
return igniteTxMgr;
}
And test code:
@Transactional("chainedTransactionManager")
public void testeroo(Consumer<Params> consumer, Params params) {
consumer.accept(params);
}
// Inserts params into databases first and then puts params into cache and
throws exception
public final class Scenario2 implements Consumer<Params> {
@Override
public void accept(Params params) {
scheduleDao.saveOrUpdate(schedule);
jobConfigDao.saveOrUpdate(jobConfig);
cache_1.put(pair.getFirst(), pair.getSecond());
throw new RuntimeException("inbound is null")
}
}
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: SpringTransactionManager and ChainedTransactionManager
Posted by smurphy <sm...@trustwave.com>.
In actuality I rewrote the tests and removed the
AbstractTransactionalJUnit4SpringContextTests super class and the
transactions worked. I also rewrote the the test as an integration test on a
tomcat server and confirmed that the transaction managers worked.
I did see the same javadoc comments that you mentioned and found that the
order was not important. Also, from the following article that is references
in Spring's Transaction documentation:
ChainedTransactionManager which is ‘a crude implementation of a transaction
manager just links together a list of other transaction managers to
implement the transaction synchronization. If the business processing is
successful they all commit, and if not they all roll back.”
Full article:
https://www.javaworld.com/article/2077963/open-source-tools/distributed-transactions-in-spring--with-and-without-xa.html?page=2
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: SpringTransactionManager and ChainedTransactionManager
Posted by vkulichenko <va...@gmail.com>.
ChainedTransactionManager doesn't guarantee that both transactions will be
rolled back in both cases, here is a quote from JavaDoc:
Using this implementation assumes that errors causing a transaction rollback
will usually happen before the transaction completion or during the commit
of the *most inner PlatformTransactionManager*.
So behavior basically depends on the order transaction managers are
provided. If you want to have a single transaction that spawns two data
sources, you should use JTA. Ignite has integration with it:
https://apacheignite.readme.io/docs/transactions#integration-with-jta
-Val
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/