I have implmented data affinity using KeyAssociation, all well and good. I understand Key objects should be immuatable however there is an edge case for my usecase - to update the attribute used for KeyAssociation. I guess I can do this by
1. removing the existing key and insert new key with updated attribute but then this is not transactional right..
2. Use an entyprocessor, remove the key from the backingmap and insert new key in to backingmap but the issue is new key might not belong to that partition and hence data-affinity is broken
Say I have Order object and LineItem object.
Edge case is - I have to update the orderId of a LineItem, this normally wont happen but if by mistake LineItem is associated to wrong Order, then it needs to be re-associated with correct order.
So would appreciate ideas on how to update the orderId of a LineItem transactionally and without breaking the data-affinity.. Really appreciate your help,
PS: I will never do cache.get(key).
Given that you are effectively changing the key, i.e. removing one entry and inserting another, I don't think there is a way in Coherence to do this transactionally (I know there is a transactional cache but we don't want to go there unless you are not doing anything much with the cache). When you think about it, the old entry and new entry might be located on different JVMs on different physical boxes and there is no link between them. How ever you do the update there will be a window of time where you might see the line item in both the old and new orders or in neither order, before it is finally correctly in the new order only. It depends how important it is that this window exists and whether any of your application code may break because of it, this of course depends on how your code accesses the line items.
Thanks for getting back.
Currently have 3 distributed caches on same service with data affinity. Its possible that I need update key's in all 3 caches. So making all 3 caches as transactional cache might not fly as these are the 3 main caches in my cluster.
I guess.. I have to live with the fact that there is window when I might see the line item in both old and new orders or in neither orders. Whats efficient/optimal way to update orderId in LineItem, so that window is as small as possible.