You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Artёm Basov <ba...@gmail.com> on 2017/07/05 12:54:37 UTC

Keep two caches "consistent"

Hi guys!

I have 2 caches, let's say 
*Cache<String, Person> presonCache* which *Read-through*
and *Cache<String, Organization> organizationCache*
we assume that each key guaraneed to be uniqe for unique entity.
Classes are:
Person {
    String name; // get/set
    .. other fields...
}
Organization {
    String name; // get/set
    Set<String> employees // consists of personCache's keys. Represents
one-to-many relation.
}

what i need to do is to make sure that if Organization o1 present in the
*organizationCache*, then all its employees need to be presend in the
*personCache* if they present in the underlying storage.
If some of them were not present(CacheStorage wasn't able to load them),
they should be removed from Organization.employees set.

There are 2 options i'm aware of:
 1) Wrap both caches into Service and handle consistency via
IgniteTransactions and custom logic.
There is no guarantees if someone will *ignite.cache(CACHE_NAME).put(k,v);*
 2) ContinuousQuery.setLocalListener(...)
Seemse to be just what is needed, but we have to do it synchronously and
person might be in many organizations, thus there is porential for deadlock
(we could sort keys though).

What's your solution of such case would be?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Keep-two-caches-consistent-tp14322.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Keep two caches "consistent"

Posted by Артём Басов <ba...@gmail.com>.
Thank you for clarifying that for me.

Have a nice day!

С Уважением,
Басов Артём

2017-07-06 0:52 GMT+03:00 vkulichenko <va...@gmail.com>:

> Hi Artem,
>
> I think the only way to do this synchronously and consistently is to
> manually load all required objects from database and put them all within a
> single transaction.
>
> You can't do synchronous updates in continuous query listener as it can
> cause a deadlock.
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Keep-two-caches-consistent-tp14322p14356.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Keep two caches "consistent"

Posted by vkulichenko <va...@gmail.com>.
Hi Artem,

I think the only way to do this synchronously and consistently is to
manually load all required objects from database and put them all within a
single transaction.

You can't do synchronous updates in continuous query listener as it can
cause a deadlock.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Keep-two-caches-consistent-tp14322p14356.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.