2 Replies Latest reply on Feb 26, 2018 5:17 AM by racoonforever

    Wildfly 11 - Can't make replicated cache work

    racoonforever

      Hello,

       

      I've been trying for 2 days to make replicated cache to work with Wildfly 11. I've read a lot on this forum and tried a lot of things without success.

      I'm trying to have a replicated cache for now on localhost. I have of course two Wildfly launched in HA mode.

      It is a JEE application.

       

      Command for 1st node  : standalone.bat -c standalone-ha.xml -Djboss.node.name=node1 -Djboss.socket.binding.port-offset=100

      Command for 2nd node : standalone.bat -c standalone-ha.xml -Djboss.node.name=node2 -Djboss.socket.binding.port-offset=200

       

      My standalone-ha.xml cache-container definition (same on both wildfly) :

       

      I used the initial standalone and just added mine

              <subsystem xmlns="urn:jboss:domain:infinispan:4.0">
                  <cache-container name="myCache" default-cache="cachedb">
                      <transport lock-timeout="60000"/>
                      <replicated-cache name="cachedb" mode="ASYNC">
                          <transaction mode="BATCH"/>
                      </replicated-cache>
                  </cache-container>
      <cache-container name="server" aliases="singleton cluster" default-cache="default" module="org.wildfly.clustering.server">
                      <transport lock-timeout="60000"/>
                      <replicated-cache name="default">
                          <transaction mode="BATCH"/>
                      </replicated-cache>
                  </cache-container>
                  <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan">
                      <transport lock-timeout="60000"/>
                      <distributed-cache name="dist">
                          <locking isolation="REPEATABLE_READ"/>
                          <transaction mode="BATCH"/>
                          <file-store/>
                      </distributed-cache>
                  </cache-container>
                  <cache-container name="ejb" aliases="sfsb" default-cache="dist" module="org.wildfly.clustering.ejb.infinispan">
                      <transport lock-timeout="60000"/>
                      <distributed-cache name="dist">
                          <locking isolation="REPEATABLE_READ"/>
                          <transaction mode="BATCH"/>
                          <file-store/>
                      </distributed-cache>
                  </cache-container>
                  <cache-container name="hibernate" default-cache="local-query" module="org.hibernate.infinispan">
                      <transport lock-timeout="60000"/>
                      <local-cache name="local-query">
                          <eviction strategy="LRU" max-entries="10000"/>
                          <expiration max-idle="100000"/>
                      </local-cache>
                      <invalidation-cache name="entity">
                          <transaction mode="NON_XA"/>
                          <eviction strategy="LRU" max-entries="10000"/>
                          <expiration max-idle="100000"/>
                      </invalidation-cache>
                      <replicated-cache name="timestamps" mode="ASYNC"/>
                  </cache-container>
              </subsystem>
      

       

      I already tried to change ASYNC to SYNC, to remove the transaction mode.

       

      Then socket-binding-group :

       

          <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
              <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
              <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
              <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
              <socket-binding name="http" port="${jboss.http.port:8080}"/>
              <socket-binding name="https" port="${jboss.https.port:8443}"/>
              <socket-binding name="jgroups-mping" interface="private" port="0" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45700"/>
              <socket-binding name="jgroups-tcp" interface="private" port="7600"/>
              <socket-binding name="jgroups-udp" interface="private" port="55200" multicast-address="${jboss.default.multicast.address:230.0.0.4}" multicast-port="45688"/>
              <socket-binding name="modcluster" port="0" multicast-address="${jboss.modcluster.multicast.address:224.0.1.105}" multicast-port="23364"/>
              <socket-binding name="txn-recovery-environment" port="4712"/>
              <socket-binding name="txn-status-manager" port="4713"/>
              <outbound-socket-binding name="mail-smtp">
                  <remote-destination host="localhost" port="25"/>
              </outbound-socket-binding>
          </socket-binding-group>
      

       

      And jgroups :

       

      <subsystem xmlns="urn:jboss:domain:jgroups:5.0">
                  <channels default="ee">
                      <channel name="ee" stack="udp" cluster="ejb"/>
                  </channels>
                  <stacks>
                      <stack name="udp">
                          <transport type="UDP" socket-binding="jgroups-udp"/>
                          <protocol type="PING"/>
                          <protocol type="MERGE3"/>
                          <protocol type="FD_SOCK"/>
                          <protocol type="FD_ALL"/>
                          <protocol type="VERIFY_SUSPECT"/>
                          <protocol type="pbcast.NAKACK2"/>
                          <protocol type="UNICAST3"/>
                          <protocol type="pbcast.STABLE"/>
                          <protocol type="pbcast.GMS"/>
                          <protocol type="UFC"/>
                          <protocol type="MFC"/>
                          <protocol type="FRAG2"/>
                      </stack>
                      <stack name="tcp">
                          <transport type="TCP" socket-binding="jgroups-tcp"/>
                          <socket-protocol type="MPING" socket-binding="jgroups-mping"/>
                          <protocol type="MERGE3"/>
                          <protocol type="FD_SOCK"/>
                          <protocol type="FD_ALL"/>
                          <protocol type="VERIFY_SUSPECT"/>
                          <protocol type="pbcast.NAKACK2"/>
                          <protocol type="UNICAST3"/>
                          <protocol type="pbcast.STABLE"/>
                          <protocol type="pbcast.GMS"/>
                          <protocol type="MFC"/>
                          <protocol type="FRAG2"/>
                      </stack>
                  </stacks>
              </subsystem>
      

       

      In my JEE application I added the /src/main/resources/MANIFEST.MF with :

       

      Manifest-Version: 1.0
      Dependencies: org.infinispan export
      

       

      I have the <distributable /> tag in web.xml.

       

      And I try to lookup for my cache like that (we are in a Singleton) :

       

      @Resource(lookup = "java:jboss/infinispan/container/myCache")
      CacheContainer cc;
      
      /**
      * Set the last refresh date
      * @param date the date to set
      */
      public void setLastRefresh(final Date date) {
           this.lastRefresh = date == null ? 0 : date.getTime();
           if (this.cc != null && this.cc.getCache() != null) {
                this.cc.getCache().put("lastrefresh", this.lastRefresh);
                LOGGER.info("instantiating lastrefresh to : " + this.lastRefresh);
           } else {
                LOGGER.info("Cache probably null");
           }
      }
      
      /**
      * @return the last refresh date
      */
      public Date getLastRefreshDateForWS() {
           if (this.cc.getCache().get("lastrefresh") != null) {
                LOGGER.info("getting lastrefresh : " + this.cc.getCache().get("lastrefresh"));
           } else {
                LOGGER.info("empty lastrefresh in cache");
           }
           return new Date(this.lastRefresh);
      }
      

       

      And server logs for both server in attached files.

       

      There are no error in the logs, and they seem to detect each other. I don't understand ...

       

      Thanks for you help !

       

      Arthur

        • 1. Re: Wildfly 11 - Can't make replicated cache work
          pferraro

          Injecting a cache container into your application only establishes a dependency on the cache container and its global configuration, not any particular cache or its configuration.  Unless the requisite cache configuration is installed, Infinispan will use assume the cache uses a basic local configuration.  To ensure that a given cache configuration is installed, you can do one of two things:

           

          1. Add a reference to the requisite cache configuration to your deployment descriptor or via @Resource
          2. Inject the cache directly, instead of creating it yourself.

           

          I always recommend option #2 whenever possible, as that way the lifecycle of the cache is managed by the server, rather than having to manage it yourself.

           

          e.g.

          @Resource(lookup = "java:jboss/infinispan/cache/myCache/default")
          private Cache<string, date=""> cache;
          • 2. Re: Wildfly 11 - Can't make replicated cache work
            racoonforever

            Thank you a lot for your answer Paul !

             

            I had a misunderstanding between Caches and CacheContainers.

             

            Have a nice day,

             

            Arthur