Database transaction updating more than 1 table from CacheStore

classic Classic list List threaded Threaded
7 messages Options
bintisepaha bintisepaha
Reply | Threaded
Open this post in threaded view
|

Database transaction updating more than 1 table from CacheStore

This post has NOT been accepted by the mailing list yet.
Hi,

We have a use case where multiple database tables/caches need to updated within a transaction, on the cluster side I can achieve this using IgniteTransactions. But I want to do the same while its going to the DB Store using write-behind. Seems like CacheStoreSession is something I should be using, but I could not find examples that wrote to 2 tables together in a transaction. Does ignite have some way to chain this when writing to the database or does this have to be a custom cacheStore implementation?

table A -> cache A
table B -> cache B

But when A is updated, B is always updated (ignite transaction). How can write-behind achieve this?

Thanks,
Binti Sepaha
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Database transaction updating more than 1 table from CacheStore

Hi Binti,

Can you please properly subscribe to the mailing list so that the community can receive email notifications? Here is the instruction: http://apache-ignite-users.70518.x6.nabble.com/mailing_list/MailingListOptions.jtp?forum=1

bintisepaha wrote
We have a use case where multiple database tables/caches need to updated within a transaction, on the cluster side I can achieve this using IgniteTransactions. But I want to do the same while its going to the DB Store using write-behind. Seems like CacheStoreSession is something I should be using, but I could not find examples that wrote to 2 tables together in a transaction. Does ignite have some way to chain this when writing to the database or does this have to be a custom cacheStore implementation?

table A -> cache A
table B -> cache B

But when A is updated, B is always updated (ignite transaction). How can write-behind achieve this?
This is possible only with write-through with the help of cache store session listeners. See store example [1] on how it is used.

With write-behind database is updated asynchronously, so the DB updates are independent and can't be enlisted in a single DB transaction.

[1] https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java
bintisepaha bintisepaha
Reply | Threaded
Open this post in threaded view
|

RE: Database transaction updating more than 1 table from CacheStore

This post has NOT been accepted by the mailing list yet.

Thanks a lot, I just did.

 

From: vkulichenko [via Apache Ignite Users] [mailto:ml-node+[hidden email]]
Sent: Thursday, April 14, 2016 4:45 PM
To: Binti Sepaha
Subject: Re: Database transaction updating more than 1 table from CacheStore

 

Hi Binti,

Can you please properly subscribe to the mailing list so that the community can receive email notifications? Here is the instruction: http://apache-ignite-users.70518.x6.nabble.com/mailing_list/MailingListOptions.jtp?forum=1

bintisepaha wrote

We have a use case where multiple database tables/caches need to updated within a transaction, on the cluster side I can achieve this using IgniteTransactions. But I want to do the same while its going to the DB Store using write-behind. Seems like CacheStoreSession is something I should be using, but I could not find examples that wrote to 2 tables together in a transaction. Does ignite have some way to chain this when writing to the database or does this have to be a custom cacheStore implementation?

table A -> cache A
table B -> cache B

But when A is updated, B is always updated (ignite transaction). How can write-behind achieve this?

This is possible only with write-through with the help of cache store session listeners. See store example [1] on how it is used.

With write-behind database is updated asynchronously, so the DB updates are independent and can't be enlisted in a single DB transaction.

[1] https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/store/jdbc/CacheJdbcStoreExample.java


To unsubscribe from Database transaction updating more than 1 table from CacheStore, click here.
NAML

_________________________________________________________

This communication is intended only for the addressee(s) and may contain confidential information. We do not waive any confidentiality by misdelivery. If you receive this communication in error, any use, dissemination, printing or copying is strictly prohibited; please destroy all electronic and paper copies and notify the sender immediately.

bintisepaha bintisepaha
Reply | Threaded
Open this post in threaded view
|

Re: Database transaction updating more than 1 table from CacheStore

In reply to this post by bintisepaha
Val, is there an example of how to use Cache store sessions listeners?
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Database transaction updating more than 1 table from CacheStore

The example I provided [1] has this, see line 90. Out of the box Ignite provides JDBC-based CacheJdbcStoreSessionListener, Spring-based CacheSpringStoreSessionListener and Hibernate-based CacheHibernateStoreSessionListener. These three fit majority of cases, but you're always free to implement your own.

There is a lack of documentation on this matter and I will try to add it soon. In the meantime, feel free to ask any questions.

-Val
bintisepaha bintisepaha
Reply | Threaded
Open this post in threaded view
|

Re: Database transaction updating more than 1 table from CacheStore

We do not want to use write-through, because database slowness is the reason why we are using ignite grid. Write-behind is our choice. But since we want a few tables to be updated in one DB transaction, it looks like the only way to achieve this is our own CacheStore implementation on the main cache and use that to get rows from other caches (they are all linked to a key) and then update in a single DB transaction. the other caches don't have to implement write-through.

Is there any better way to achieve this? Can CacheJdbcStoreSessionListener or a similar implementation achieve what we are trying to do? Not fully understanding what CacheJdbcStoreSessionListener does.

Thanks,
Binti

vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: Database transaction updating more than 1 table from CacheStore

Binti,

Session listener is just a callback that is called before and after cache transaction. In case of write-through you can use it to start and commit/rollback DB transaction along with cache transaction. With write-behind it doesn't help much because in this case DB is updated from primary nodes and generally there are several of them in one transaction, which makes maintaining a single DB transaction impossible. The only way to fully guarantee transactional consistency is using write-through.

-Val