You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by akash shinde <ak...@gmail.com> on 2018/03/23 11:42:11 UTC
JTA transactions in Iginte
Hello,
My requirement is to achieve ignite cache update operation and
database write operation in single transaction.
Right now I am trying to use JTA transaction management. I have created
below IgniteConfiguration using transactionConfiguration. But I am not
sure how to configure XAResource to this transaction manager.
I will be needing two XAResource here 1)Datasource(JDBC data source)
2)Ignite cache.
Please suggest how can I achieve this JTA transaction using two XAResources.
Please also suggest after all these configuration how to
get JtaTransactionManager instance to initiate the transaction. Currently I
am using Narayana JTA implementation.
private IgniteConfiguration getIgniteConfiguration(IgniteSpringBean ignite) {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName("springDataNode");
cfg.setPeerClassLoadingEnabled(false);
cfg.setRebalanceThreadPoolSize(4);
* cfg.setTransactionConfiguration(transactionConfiguration());*
cfg.setCacheConfiguration(getIPContainerCacheConfiguration(),getIPContainerIPV4CacheConfiguration(),getUserPermissionCacheConfiguration(),getUserAccountCacheConfiguration());
return cfg;
}
@Bean
public TransactionConfiguration transactionConfiguration(){
TransactionConfiguration configuration = new TransactionConfiguration();
Factory factory = new Factory() {
@Override
public Object create() {
return jtaTransactionManager();
}
};
configuration.setTxManagerFactory(factory);
*configuration.setUseJtaSynchronization(true);*
return configuration;
}
@Bean
public PlatformTransactionManager jtaTransactionManager() {
JtaTransactionManager tm = new JtaTransactionManager();
tm.setTransactionManager(transactionManager());
return tm;
}
@Bean
public TransactionManager transactionManager() {
return new TransactionManagerImple();
}
Thanks,
Akash
Re: JTA transactions in Iginte
Posted by vkulichenko <va...@gmail.com>.
Prasad,
1. JTA is an abstraction that is not related to Ignite, so exact details
would depend on how your application is organized. But basically you need to
do the following:
- Acquire the transaction manager (from a container, from Spring app context
or whatever you use for management of such things).
- Start a new JTA transaction (not Ignite transaction!).
- Invoke Ignite cache operations as well as other DB operations - all of
them would be enlisted into this transaction.
- Commit transaction.
2. TMService is just an example of a transaction manager (i.e. one of the
implementation of JTA abstraction). You're not required to use specifically
this one.
3. This happens automatically when you follow the process described in point
1 above, as long as Ignite is aware of transaction manager that is used
there. To achieve this, it needs to be provided via
TransactionConfiguration.
-Val
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: JTA transactions in Iginte
Posted by Prasad Bhalerao <pr...@gmail.com>.
Val,
Thank you for the response. As per your suggestion I will first test it
with write through approach before moving to JTA.
About JTA, I still have some doubts about how to use it.
As per the example given in this link
https://apacheignite.readme.io/v2.4/docs/transactions (Integration With JTA
section
<https://apacheignite.readme.io/v2.4/docs/transactions#section-integration-with-jta>
),
I have few questions about following code.
1) As per the ignite doc, the transaction manager should be configured
suing TransactionConfiguration#setTxManagerFactory method and then this
transaction configuration should be set in ignite configuration.
How do I get this transaction in my code?
Does this code "IgniteTransactions transactions =
ignite.transactions();" provides JTA transaction?
How to and when to enlist jdbc data source in this transaction manager?
2) How to configure TMService bean ?
3) In following example how to enlist xa jdbc datasource in this
transaction? How xa resource for ignite cache is enlisted in transaction in
following example?
// Get an instance of JTA transaction manager.
TMService tms = appCtx.getComponent(TMService.class);
// Get an instance of Ignite cache.
IgniteCache<String, Integer> cache = cache();
UserTransaction jtaTx = tms.getUserTransaction();
// Start JTA transaction.
jtaTx.begin();
try{
// Do some cache operations.
cache.put("key1",1);
cache.put("key2",2);
// Commit the transaction.
jtaTx.commit();
}
finally{
// Rollback in a case of exception.
if(jtaTx.getStatus()==Status.STATUS_ACTIVE)
jtaTx.rollback();
}
Thanks,
Prasad
On Tue, Mar 27, 2018 at 8:45 AM, vkulichenko <va...@gmail.com>
wrote:
> Prasad,
>
> First, I'm not sure why you think write-though would be slower than using
> JTA. I'm probably missing something, but I believe you should at least test
> this before making decision.
>
> In any case, if you use JTA, Ignite would automatically enlist any cache
> operations into ongoing JTA transaction. You only need to do the following:
> - JTA transaction manager instance provided in Ignite's
> TransactionConfiguration is the same that starts transactions.
> - Cache operations are invoked within the same thread that started a
> transaction.
>
> Hope this helps.
>
> -Val
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: JTA transactions in Iginte
Posted by vkulichenko <va...@gmail.com>.
Prasad,
First, I'm not sure why you think write-though would be slower than using
JTA. I'm probably missing something, but I believe you should at least test
this before making decision.
In any case, if you use JTA, Ignite would automatically enlist any cache
operations into ongoing JTA transaction. You only need to do the following:
- JTA transaction manager instance provided in Ignite's
TransactionConfiguration is the same that starts transactions.
- Cache operations are invoked within the same thread that started a
transaction.
Hope this helps.
-Val
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: JTA transactions in Iginte
Posted by "slava.koptilin" <sl...@gmail.com>.
Hello,
> Can you please provide an example to configure jta with ignite?
You can check the following tests that illustrate the JTA configuration[1]
from Apache Ignite point of view.
https://github.com/apache/ignite/tree/master/modules/jta/src/test/java/org/apache/ignite/internal/processors/cache/jta
> I am not sure how to configure XAResource to this transaction manager.
I think you need to check official documentation provided by Oracle (JDBC
Developer's Guide[2])
- Distributed Transactions
https://docs.oracle.com/database/121/JJDBC/xadistra.htm#JJDBC28000
- Data Sources and URLs
https://docs.oracle.com/database/121/JJDBC/urls.htm#JJDBC28267
[1]
https://apacheignite.readme.io/docs/transactions#section-integration-with-jta
[2] https://docs.oracle.com/database/121/JJDBC/toc.htm
[3] http://narayana.io//docs/project/index.html#d0e2748
Thanks!
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: JTA transactions in Iginte
Posted by Prasad Bhalerao <pr...@gmail.com>.
Hi Val/Denis
Can you please answer this?
Thanks,
prasad
On Sat, Mar 24, 2018, 1:58 PM Prasad Bhalerao <pr...@gmail.com>
wrote:
> Hi,
> I can't use write through approach. I will be doing CRUD batch operations
> on oracle tables to avoid frequent calls to db.
> Now to keep ignite cache and oracle db consistent I have to use JTA
> transaction.
> Note: I have also enabled ignite persistance.
>
> Can you please provide an example to configure jta with ignite?
> I have already gone through the ignite documentation,but it's not clear to
> me how to use it.
> I have configured the transaction manager in ignite configuration as shown
> by the Akash in his mail.
> But how to enlist oracle data source in transaction?
> As per the ignite doc, it uses user transaction. But how get the user
> transaction in first place?
> How to attach xa data source to this user transaction?
> Please advise, I stuck at this point.
>
>
> On Sat, Mar 24, 2018, 12:12 PM Denis Magda <dm...@gridgain.com> wrote:
>
>> Do you use Ignite as a distributed cache of your database? If it’s so,
>> then you can hook Ignite up with the database using CacheStore interface.
>> After that, Ignite will write-through changes automatically including
>> transactions.
>>
>> Denis
>>
>> On Friday, March 23, 2018, Prasad Bhalerao <pr...@gmail.com>
>> wrote:
>>
>>> Can someone please answer this?
>>> I am also facing the similar problem.
>>>
>>>
>>>
>>>
>>> On Fri, Mar 23, 2018, 5:12 PM akash shinde <ak...@gmail.com>
>>> wrote:
>>>
>>>> Hello,
>>>> My requirement is to achieve ignite cache update operation and
>>>> database write operation in single transaction.
>>>> Right now I am trying to use JTA transaction management. I have
>>>> created below IgniteConfiguration using transactionConfiguration. But I am
>>>> not sure how to configure XAResource to this transaction manager.
>>>> I will be needing two XAResource here 1)Datasource(JDBC data source)
>>>> 2)Ignite cache.
>>>>
>>>> Please suggest how can I achieve this JTA transaction using two
>>>> XAResources.
>>>>
>>>> Please also suggest after all these configuration how to
>>>> get JtaTransactionManager instance to initiate the transaction. Currently
>>>> I am using Narayana JTA implementation.
>>>>
>>>>
>>>> private IgniteConfiguration getIgniteConfiguration(IgniteSpringBean ignite) {
>>>>
>>>> IgniteConfiguration cfg = new IgniteConfiguration();
>>>> cfg.setIgniteInstanceName("springDataNode");
>>>> cfg.setPeerClassLoadingEnabled(false);
>>>> cfg.setRebalanceThreadPoolSize(4);
>>>>
>>>> * cfg.setTransactionConfiguration(transactionConfiguration());*
>>>>
>>>> cfg.setCacheConfiguration(getIPContainerCacheConfiguration(),getIPContainerIPV4CacheConfiguration(),getUserPermissionCacheConfiguration(),getUserAccountCacheConfiguration());
>>>> return cfg;
>>>> }
>>>>
>>>>
>>>> @Bean
>>>> public TransactionConfiguration transactionConfiguration(){
>>>> TransactionConfiguration configuration = new TransactionConfiguration();
>>>> Factory factory = new Factory() {
>>>> @Override
>>>> public Object create() {
>>>> return jtaTransactionManager();
>>>> }
>>>> };
>>>> configuration.setTxManagerFactory(factory);
>>>> *configuration.setUseJtaSynchronization(true);*
>>>> return configuration;
>>>> }
>>>>
>>>> @Bean
>>>> public PlatformTransactionManager jtaTransactionManager() {
>>>> JtaTransactionManager tm = new JtaTransactionManager();
>>>> tm.setTransactionManager(transactionManager());
>>>> return tm;
>>>> }
>>>>
>>>> @Bean
>>>> public TransactionManager transactionManager() {
>>>> return new TransactionManagerImple();
>>>> }
>>>>
>>>>
>>>> Thanks,
>>>> Akash
>>>>
>>>
Re: JTA transactions in Iginte
Posted by Prasad Bhalerao <pr...@gmail.com>.
Hi,
I can't use write through approach. I will be doing CRUD batch operations
on oracle tables to avoid frequent calls to db.
Now to keep ignite cache and oracle db consistent I have to use JTA
transaction.
Note: I have also enabled ignite persistance.
Can you please provide an example to configure jta with ignite?
I have already gone through the ignite documentation,but it's not clear to
me how to use it.
I have configured the transaction manager in ignite configuration as shown
by the Akash in his mail.
But how to enlist oracle data source in transaction?
As per the ignite doc, it uses user transaction. But how get the user
transaction in first place?
How to attach xa data source to this user transaction?
Please advise, I stuck at this point.
On Sat, Mar 24, 2018, 12:12 PM Denis Magda <dm...@gridgain.com> wrote:
> Do you use Ignite as a distributed cache of your database? If it’s so,
> then you can hook Ignite up with the database using CacheStore interface.
> After that, Ignite will write-through changes automatically including
> transactions.
>
> Denis
>
> On Friday, March 23, 2018, Prasad Bhalerao <pr...@gmail.com>
> wrote:
>
>> Can someone please answer this?
>> I am also facing the similar problem.
>>
>>
>>
>>
>> On Fri, Mar 23, 2018, 5:12 PM akash shinde <ak...@gmail.com> wrote:
>>
>>> Hello,
>>> My requirement is to achieve ignite cache update operation and
>>> database write operation in single transaction.
>>> Right now I am trying to use JTA transaction management. I have created
>>> below IgniteConfiguration using transactionConfiguration. But I am not
>>> sure how to configure XAResource to this transaction manager.
>>> I will be needing two XAResource here 1)Datasource(JDBC data source)
>>> 2)Ignite cache.
>>>
>>> Please suggest how can I achieve this JTA transaction using two
>>> XAResources.
>>>
>>> Please also suggest after all these configuration how to
>>> get JtaTransactionManager instance to initiate the transaction. Currently
>>> I am using Narayana JTA implementation.
>>>
>>>
>>> private IgniteConfiguration getIgniteConfiguration(IgniteSpringBean ignite) {
>>>
>>> IgniteConfiguration cfg = new IgniteConfiguration();
>>> cfg.setIgniteInstanceName("springDataNode");
>>> cfg.setPeerClassLoadingEnabled(false);
>>> cfg.setRebalanceThreadPoolSize(4);
>>>
>>> * cfg.setTransactionConfiguration(transactionConfiguration());*
>>>
>>> cfg.setCacheConfiguration(getIPContainerCacheConfiguration(),getIPContainerIPV4CacheConfiguration(),getUserPermissionCacheConfiguration(),getUserAccountCacheConfiguration());
>>> return cfg;
>>> }
>>>
>>>
>>> @Bean
>>> public TransactionConfiguration transactionConfiguration(){
>>> TransactionConfiguration configuration = new TransactionConfiguration();
>>> Factory factory = new Factory() {
>>> @Override
>>> public Object create() {
>>> return jtaTransactionManager();
>>> }
>>> };
>>> configuration.setTxManagerFactory(factory);
>>> *configuration.setUseJtaSynchronization(true);*
>>> return configuration;
>>> }
>>>
>>> @Bean
>>> public PlatformTransactionManager jtaTransactionManager() {
>>> JtaTransactionManager tm = new JtaTransactionManager();
>>> tm.setTransactionManager(transactionManager());
>>> return tm;
>>> }
>>>
>>> @Bean
>>> public TransactionManager transactionManager() {
>>> return new TransactionManagerImple();
>>> }
>>>
>>>
>>> Thanks,
>>> Akash
>>>
>>
Re: JTA transactions in Iginte
Posted by Denis Magda <dm...@gridgain.com>.
Do you use Ignite as a distributed cache of your database? If it’s so, then
you can hook Ignite up with the database using CacheStore interface. After
that, Ignite will write-through changes automatically including
transactions.
Denis
On Friday, March 23, 2018, Prasad Bhalerao <pr...@gmail.com>
wrote:
> Can someone please answer this?
> I am also facing the similar problem.
>
>
>
>
> On Fri, Mar 23, 2018, 5:12 PM akash shinde <ak...@gmail.com> wrote:
>
>> Hello,
>> My requirement is to achieve ignite cache update operation and
>> database write operation in single transaction.
>> Right now I am trying to use JTA transaction management. I have created
>> below IgniteConfiguration using transactionConfiguration. But I am not
>> sure how to configure XAResource to this transaction manager.
>> I will be needing two XAResource here 1)Datasource(JDBC data source)
>> 2)Ignite cache.
>>
>> Please suggest how can I achieve this JTA transaction using two
>> XAResources.
>>
>> Please also suggest after all these configuration how to
>> get JtaTransactionManager instance to initiate the transaction. Currently
>> I am using Narayana JTA implementation.
>>
>>
>> private IgniteConfiguration getIgniteConfiguration(IgniteSpringBean ignite) {
>>
>> IgniteConfiguration cfg = new IgniteConfiguration();
>> cfg.setIgniteInstanceName("springDataNode");
>> cfg.setPeerClassLoadingEnabled(false);
>> cfg.setRebalanceThreadPoolSize(4);
>>
>> * cfg.setTransactionConfiguration(transactionConfiguration());*
>>
>> cfg.setCacheConfiguration(getIPContainerCacheConfiguration(),getIPContainerIPV4CacheConfiguration(),getUserPermissionCacheConfiguration(),getUserAccountCacheConfiguration());
>> return cfg;
>> }
>>
>>
>> @Bean
>> public TransactionConfiguration transactionConfiguration(){
>> TransactionConfiguration configuration = new TransactionConfiguration();
>> Factory factory = new Factory() {
>> @Override
>> public Object create() {
>> return jtaTransactionManager();
>> }
>> };
>> configuration.setTxManagerFactory(factory);
>> *configuration.setUseJtaSynchronization(true);*
>> return configuration;
>> }
>>
>> @Bean
>> public PlatformTransactionManager jtaTransactionManager() {
>> JtaTransactionManager tm = new JtaTransactionManager();
>> tm.setTransactionManager(transactionManager());
>> return tm;
>> }
>>
>> @Bean
>> public TransactionManager transactionManager() {
>> return new TransactionManagerImple();
>> }
>>
>>
>> Thanks,
>> Akash
>>
>
Re: JTA transactions in Iginte
Posted by Prasad Bhalerao <pr...@gmail.com>.
Can someone please answer this?
I am also facing the similar problem.
On Fri, Mar 23, 2018, 5:12 PM akash shinde <ak...@gmail.com> wrote:
> Hello,
> My requirement is to achieve ignite cache update operation and
> database write operation in single transaction.
> Right now I am trying to use JTA transaction management. I have created
> below IgniteConfiguration using transactionConfiguration. But I am not
> sure how to configure XAResource to this transaction manager.
> I will be needing two XAResource here 1)Datasource(JDBC data source)
> 2)Ignite cache.
>
> Please suggest how can I achieve this JTA transaction using two
> XAResources.
>
> Please also suggest after all these configuration how to
> get JtaTransactionManager instance to initiate the transaction. Currently
> I am using Narayana JTA implementation.
>
>
> private IgniteConfiguration getIgniteConfiguration(IgniteSpringBean ignite) {
>
> IgniteConfiguration cfg = new IgniteConfiguration();
> cfg.setIgniteInstanceName("springDataNode");
> cfg.setPeerClassLoadingEnabled(false);
> cfg.setRebalanceThreadPoolSize(4);
>
> * cfg.setTransactionConfiguration(transactionConfiguration());*
>
> cfg.setCacheConfiguration(getIPContainerCacheConfiguration(),getIPContainerIPV4CacheConfiguration(),getUserPermissionCacheConfiguration(),getUserAccountCacheConfiguration());
> return cfg;
> }
>
>
> @Bean
> public TransactionConfiguration transactionConfiguration(){
> TransactionConfiguration configuration = new TransactionConfiguration();
> Factory factory = new Factory() {
> @Override
> public Object create() {
> return jtaTransactionManager();
> }
> };
> configuration.setTxManagerFactory(factory);
> *configuration.setUseJtaSynchronization(true);*
> return configuration;
> }
>
> @Bean
> public PlatformTransactionManager jtaTransactionManager() {
> JtaTransactionManager tm = new JtaTransactionManager();
> tm.setTransactionManager(transactionManager());
> return tm;
> }
>
> @Bean
> public TransactionManager transactionManager() {
> return new TransactionManagerImple();
> }
>
>
> Thanks,
> Akash
>