5 Replies Latest reply on Jan 15, 2014 5:01 AM by pruivo

    Infinispan 6 - Is Map/Remove consistent?

    eskape

      Hi everyone,

       

      Short question: Does calling Cache.remove() from either map() or reduce() method affect overall cache consistency?

      The reason I'm asking is that it looks startlingly similar to a big bad no-no like this:

      List<String> values = getValues();
      for (String s : values) {
          //...
         values.delete(0);
      }
      

      ... which actually results in an Exception being thrown.

       

      Long question: I'm adding a chat function to existing application so users can talk to each other. Most of it is quite straightforward, however, there's a bit of a problem when user is logged in from multiple devices or offline: I have to maintain a queue of "unread" messages and then "discard" them as soon as they're acknowledged.

      Since every message is server-timestamped, map() function gets the latest timestamp as an input parameter, scans cache data, identifies all "read" messages (i.e. with older timestamps) and removes them from the "offline" storage.

      As it stands, I see a few options:

      - Remove items as soon as they're discovered in map() method;

      - Remove items in reduce() function;

      - Return a list of objects from map/reduce function and then remove them all in one batch.

       

      First option is the most straightforward, however, I'm still worried about consistency. Any suggestions?

       

      Many thanks.

        • 1. Re: Infinispan 6 - Is Map/Remove consistent?
          pruivo

          Hi Egor,

           

          All your options should work fine. We have never checked for consistency during the map/reduce phase, but it should keep the cache consistency.

           

          However, IMO, the last option is the most related to the map/reduce world.

           

          Cheers,

          Pedro

          • 2. Re: Infinispan 6 - Is Map/Remove consistent?
            eskape

            Hi Pedro,

             

            Thanks for swift reply.

             

            I do understand that from theory standpoint the last option is the most "correct" - however, in I also have performance considerations in mind.

            My understanding of the process, given distributed cache setup, is:

            1) Map/Reduce operation is executed on each node of the cluster;

            2) Resulting list is collected on a "master" node (i.e. the one that requested the operation);

            3) remove() method is called for each object in the list, and this again gets executed on each node.

             

            If my understanding of the way Infinispan works is adequate, I could save on unnecessary reduce() operation, as well as on collection and re-execution phases if I call evict() method rather than remove() during map() phase because the execution is already distributed.

             

            Please correct me if I'm wrong.

             

            Thanks

            Egor.

            • 3. Re: Infinispan 6 - Is Map/Remove consistent?
              pruivo

              Hi Egor,

              Egor Kolesnikov wrote:

               

               

              I do understand that from theory standpoint the last option is the most "correct" - however, in I also have performance considerations in mind.

              My understanding of the process, given distributed cache setup, is:

              1) Map/Reduce operation is executed on each node of the cluster;

              2) Resulting list is collected on a "master" node (i.e. the one that requested the operation);

              3) remove() method is called for each object in the list, and this again gets executed on each node.

               

              Yes that is correct.

              Egor Kolesnikov wrote:

               

               

              If my understanding of the way Infinispan works is adequate, I could save on unnecessary reduce() operation, as well as on collection and re-execution phases if I call evict() method rather than remove() during map() phase because the execution is already distributed.

               

              Please correct me if I'm wrong.

               

              That works If you have configured numOwners = 1. Otherwise, you will have to use remove().  The map() phase happens in the primary owner of the key and the evict() only removes from local node. So, with evict() and numOwners != 1, the backup owners would never remove the key.

               

              One thing that you may consider is the evict() does not remove the key from CacheLoader/Store (if you have any configured).

               

              Cheers,

              Pedro

              • 4. Re: Infinispan 6 - Is Map/Remove consistent?
                eskape

                Hi Pedro

                 

                That's a bit unexpected - I was under impression that map() will iterate over each entry in the local cache whether it originated on the node or not. It appears that's not the case.

                 

                Thanks for the heads-up, I guess I just go for option 3 then.

                 

                Cheers

                Egor

                • 5. Re: Infinispan 6 - Is Map/Remove consistent?
                  pruivo

                  Hi Egor,

                   

                  Why is it unexpected?

                   

                  If a key K is replicated in N nodes (i.e. numOwners=N), only one node will invoke map() with K, otherwise it would map() N times (that is not desired).

                   

                  Cheers,

                  Pedro