3 Replies Latest reply on Feb 11, 2015 8:32 AM by Vladimir Blagojevic

    Infispan Automatic Task Failover

    Bijesh Roy Newbie

      Hi,

      I was using Distributed Task executor over an Infispan cluster. My use case was map population over 2nodes and check automatic task failover. however during testing it is noticed that if any of the node is going down task is transferred to the other node but some of keys are missed out and exeeption thrown so after future.get() rest of the code is not working. Can you please help me getting a sample code shich shows Success Ful implementation of Automatic Task failover without loosing any data?

       

      Thanks in Advance!!

        • 1. Re: Infispan Automatic Task Failover
          Vladimir Blagojevic Master

          Hi Bijesh,

           

          Automatic task failover does not provide any consistency guarantees regarding keys iterated. If you have some code samples to share I would be glad to help you further.

           

          Regards,

          Vladimir

          • 2. Re: Infispan Automatic Task Failover
            Bijesh Roy Newbie

            Hi Vladimir,

            Here is my callable statement:

            public class DistributedCacheTest<V, K, T> implements DistributedCallable<K, V, T>,Serializable{
            private static final long serialVersionUID = 8331682008912636780L;
              //private final String cacheName;
              private transient Cache cache;
              private final String key;

              DistributedCacheTest(Cache cache,String key){
               this.cache=cache;
               this.key=key;
              }
             
            @Override
            public void setEnvironment(Cache<K, V> arg0, Set<K> arg1) {
              // TODO Auto-generated method stub
              this.cache=arg0;
            }

            @SuppressWarnings("unchecked")
            @Override
            public T call() throws Exception {
              cache.put(key, UUID.randomUUID());
              System.out.println("Printing from Distributed cache Key="+key);
              //Thread.currentThread().sleep(5000);
              return null;
            }

            }

             

            And the Executor node and I have another node which is just calling the cache manager:

            public class TestDistributedCache {

            public static void main(String args[]) throws IOException, InterruptedException{
              EmbeddedCacheManager cacheManager=null;
              try {
               cacheManager = createCacheManager();
              } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
              }
              Cache cache=cacheManager.getCache("dist");
              //for (int i=0;i<20;i++){
               // cache.put(String.valueOf(i),UUID.randomUUID().toString());
               //}
              DistributedExecutorService des = new DefaultExecutorService(cache);

              List<Future<String>> results = new ArrayList<Future<String>>();
              try{
               for(int i=0;i<=20; i++){
               
                results.add((Future<String>) des.submit(new DistributedCacheTest(cache,String.valueOf(i))));
                Thread.currentThread().sleep(2000);
                //results.add((Future<String>) des.submit(new EchoTask(cache,String.valueOf(i))));
               }
               for (Future<String> f : results) {
                String echoResult = f.get();
                System.out.println("Response received for DistributedCacheTest:"+echoResult);
               }
              }catch(ExecutionException e){
               System.out.println("Execution Exception Occured="+e.getMessage());
              }
             
              System.out.println("After task execution cache size="+cacheManager.getCache("dist").size());

            }

            private static EmbeddedCacheManager createCacheManager() throws IOException {
              System.out.println("Starting a cache manager with an XML configuration");
              //System.setProperty("nodeName", nodeName);
              return new DefaultCacheManager("infinispan.xml");

            }

            }

             

            However after task failure I can see that keys that the down node puts into cache are missing even in some cases. Is it a normal behavior or something is wrong with my code. Also if possible can you please send me some sample code which handles the task failover properly?

            Thanks in advance!!

            • 3. Re: Infispan Automatic Task Failover
              Vladimir Blagojevic Master

              Hey Bijesh,

               

              I would suggest that you read a bit more of Infinispan documentation. Failover is not done by default and you would have to set it up programmatically yourself.

               

              Regards,

              Vladimir