Reading dirty / updated entries, simple replication, misuse or shall I use different configuration?
javapapo Aug 9, 2014 5:07 AMHello, I am using infinispan in library mode, with the setting REPLICATED _ SYNC (non transactional) . It works like a charm. I have some simple questions regarding replicated sync mode and pass by reference feature of Infinispan
Question1:
I have inherited a code base, that was not cluster aware, this code base was using a cache data holder object, to group all the cached data that it needed, between calls. So when I migrated to Infinispan i created a new Cache that would hold String as a Key and value this bag or properties.
Cache<String,SessionDataHolder>
Eventually different calls on nodes using the same Key (session Id), want to get a reference on a SessionDataHolder instance and change a property.
In the above mode, if i do a get() from the Cache get a reference on Node 1.
NODE1
SessionDataHolder cached = myCache.get(sessionId); cached.setName("aNewName"); cached.setVATID("aBew Vat ID") myCache.replace(sessionId,cached);
QUESTION: Since currently I am not implementing a DeltaAware interface as I have red in a related post, my way on updating this property and make the cache distributes the change is to get reference of the object, set a new value for a certain property and then call the replace() method to notify the cache that the overall entry was updated and distribute changes? Is there a different in this case for put and replace?
Question2:
In non transaction, replicated sync mode, if at the same moment 2 Nodes hold on a 'updated' cache element, but their calls take different amount of time, when each of them completes it needs to update a property in the Cache, the chages are going to be put on top of the previous cache commits? Example
Node 1: Time 12:00
SessionDataHolder cached = myCache.get(sessionId);
Node 2 Time 12:00
SessionDataHolder cached = myCache.get(sessionId);
Node 1: Time 12:05
cached.setName("aNewName"); myCache.replace(sessionId,cached)
Node 2 : Time 12:10
cached.setName("ANode2Name"); myCache.replace(sessionId,cached)
At 12:05, Node1 is going to issue to the cluster a replace on the object with the specific ID and the entry will be replaced, BUT Node2 will be holding a reference from the local cache since it did a get at 12:00 and it might take some time until it is on the state to update the cache. When it is ready it is going to replace a older version of the cache value with it's change, overwritting the overall changes on Node1. Is my understanding correct?
Is there any way on the above mode, to make my code always check for changes on remote cache? it is should be implemented using JTA transactions?
Many thanks for your help or tips?