2 Replies Latest reply on Aug 25, 2010 12:08 PM by Jeff Nadler

    Cache Warming - How To Run On One Node Only?

    Jeff Nadler Newbie

      I'm running a cache warming process as a part of system initialization.   It's run by Spring not that it should matter.   Works fine with a single server.


      Once a cluster is established, this cache warming process should run on one server only (first one wins?) and the other servers need to block until the cache warming job is done. 


      Does infinispan have anything that might help here?  I need a cluster shared lock, I'm thinking of having a DB table 'init_lock' and the first process to get there adds a record with PK of 1, if this commits it starts the cache warm, if this fails (row already exists) then it goes into a sleep loop checking to see if that record still exists every second.


      I don't love it.  Better ideas, anyone?

        • 1. Re: Cache Warming - How To Run On One Node Only?
          Mircea Markus Master

          I would rather run the warmup on the last node that joins the cluster, so that when the warmup is run the cluster is formed for sure.

          Cluster wide locking can be achieved through eager locking. Not sure you need that for your scenarion though.

          I think the code would look something like this:


          On passive nodes:


          while (!Boolean.TRUE.equals(cache.get("isWarmupFinished") ) {
          //when this point is reached the node is warmed up



          On the node that does the warmup:


          Transport t = cache.getAdvancedCache().getRpcManager().getTransport();
          //this is the condition for determining weather I am the last node in the cluster and I should run warmup
          if (t.getMembers().size() == CLUSTER_SIZE && t.getMembers().get(t.getMembers().size()-1).equals(t.getLocalAddress)) {
           cache.put("isWarmupFinished", Boolean.TRUE);




          • 2. Re: Cache Warming - How To Run On One Node Only?
            Jeff Nadler Newbie

            Thank you Mircea.   I was hoping that something like this was possible.