1 Reply Latest reply on Jul 31, 2017 3:05 AM by Bela Ban

    Infinispan Cluster on Tomcat

    Greg Parker Newbie

      I setup two tomcat instances.  I have an initialization servlet on each that sets up a distributed cache like this:

       

      GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
      global.transport().clusterName("testCluster");
      cacheManager = new DefaultCacheManager(global.build());
      ConfigurationBuilder config = new ConfigurationBuilder();
      config.expiration().lifespan(60000, TimeUnit.SECONDS).clustering().cacheMode(CacheMode.DIST_SYNC);
      cacheManager.defineConfiguration("test", config.build());
      

       

      The first server, server A, has a page that puts a message in the cache like this:

       

      Cache<String, String> cache = CacheInitializationServlet.cacheManager.getCache("test");
      String message = cache.get("message");
      
      if (message == null) {
          message = "";
      }
      
      message += "*";
      cache.put("message", message);
      message = cache.get("message");
      System.out.println("Server A -> cache has : " + message);
      

       

      Each time I hit the page it adds an asterisk to the message in the cache.  The second server, server B, has a page the just gets the message from the cache like this:

       

      Cache<String, String> cache = CacheInitializationServlet.cacheManager.getCache("test");
      String message = cache.get("message");
      System.out.println("Server B -> cache has : " + message);
      

       

      When I hit the page on server A, I see:

      Server A -> cache has : *

       

      When I hit server B, I get:

      Server B -> cache has : null

       

      The console on server A has the following logs entries at startup:

      28-Jul-2017 16:27:21.460 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.start ISPN000078: Starting JGroups channel testCluster

      28-Jul-2017 16:27:21.461 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!

      28-Jul-2017 16:27:26.702 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.receiveClusterView ISPN000094: Received new cluster view for channel testCluster: [localhost-32508|0] (1) [localhost-32508]

      28-Jul-2017 16:27:26.714 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.startJGroupsChannelIfNeeded ISPN000079: Channel testCluster local address is localhost-32508, physical addresses are [fe80:0:0:0:ac5c:7cd7:90b7:7667%10:51444]

      28-Jul-2017 16:27:26.720 INFO [localhost-startStop-1] org.infinispan.factories.GlobalComponentRegistry.start ISPN000128: Infinispan version: Infinispan 'Bastille' 9.1.0.Final

      Done initializing cache

       

      The console on server B has the following logs entries at startup:

      28-Jul-2017 16:27:23.713 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.start ISPN000078: Starting JGroups channel testCluster

      28-Jul-2017 16:27:23.714 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.buildChannel ISPN000088: Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!

      28-Jul-2017 16:27:28.885 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.receiveClusterView ISPN000094: Received new cluster view for channel testCluster: [localhost-16476|0] (1) [localhost-16476]

      28-Jul-2017 16:27:28.895 INFO [localhost-startStop-1] org.infinispan.remoting.transport.jgroups.JGroupsTransport.startJGroupsChannelIfNeeded ISPN000079: Channel testCluster local address is localhost-16476, physical addresses are [fe80:0:0:0:ac5c:7cd7:90b7:7667%10:51445]

      28-Jul-2017 16:27:28.900 INFO [localhost-startStop-1] org.infinispan.factories.GlobalComponentRegistry.start ISPN000128: Infinispan version: Infinispan 'Bastille' 9.1.0.Final

       

      The same type of test run using a standalone Java application works when run from the command line.  So something is not working correctly on Tomcat.  Hoping someone can show me what is wrong.

        • 1. Re: Infinispan Cluster on Tomcat
          Bela Ban Master

          The cluster didn't form: Received new cluster view for channel testCluster: [localhost-16476|0] (1) [localhost-16476].

           

          Apparently the correct configuration was not found and JGroups fell back to the default (default-jgroups-tcp.xml or default-jgroups-udp.xml) configuration which uses IP multicasting for discovery (MPING or PING).

           

          When using default-jgroups-tcp.xml, you need to make sure bind_addr points to the correct address, e.g. by setting it in the XML config or using system prop -Djgroups.tcp.address=X where X should be a routable IP address. Note that you can use "global" or "site_local" (see [1]) to pick a global or site local address.

           

          Also note that you're using IPv6; if you want to disable it use -Djava.net.preferIPv4Stack=true.

           

          [1] Reliable group communication with JGroups