This discussion is archived
2 Replies Latest reply: Aug 20, 2013 7:39 AM by 82420128-c6b8-49b4-9804-510cbc337b09 RSS

updating key-association in  Key  object

82420128-c6b8-49b4-9804-510cbc337b09 Newbie
Currently Being Moderated

Guys,

 

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

 

Usecase:

Say I have Order object and LineItem object.

public class LineItemId implements KeyAssociation

   {

   // {...}

   public Object getAssociatedKey()

       {

       return getOrderId();

       }

   // {...}

   }

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).

 

Thanks

D

  • 1. Re: updating key-association in  Key  object
    Jonathan.Knight Expert
    Currently Being Moderated

    Hi,

     

    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.

     

    JK

  • 2. Re: updating key-association in  Key  object
    82420128-c6b8-49b4-9804-510cbc337b09 Newbie
    Currently Being Moderated

    Hi JK,

     

    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.

     

     

    Thanks

    D

     


Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points