5 Replies Latest reply on Jun 23, 2016 1:31 PM by Tendai Munetsi

    WildFly 10 distributed cache does not sync

    Tendai Munetsi Newbie

      Hi,

      I recently upgraded to WildFly 10.0.0.Final from 9.0.2 and my manually configured distributed caches are no longer syncing. I am running in domain mode with two backend servers (ha profile, ha sockets). For some reason Infinispan thinks the cache is local (i.e newly inserted keys are not seen on the other nodes). What is interesting is that he "web" cache container appears to be syncing across the nodes as expected. The manually configured container is a copy of the "web" cache container with the name attribute changed (see below), so one would expect it to behave the same.

       

                      <cache-container name="FAAR" default-cache="dist">

                          <transport lock-timeout="60000"/>

                          <distributed-cache name="dist" mode="ASYNC" owners="2" l1-lifespan="0">

                              <locking isolation="REPEATABLE_READ"/>

                              <transaction mode="BATCH"/>

                              <file-store/>

                          </distributed-cache>

                      </cache-container>

       

      From my research into the issue, it appears that the correct Infinispan interceptors are not being applied to the manually configured distributed cache. Below is the interceptor list for the "web" container that syncs versus the cache container which does not sync.

       

      web cache container:

      2016-06-16 10:23:02,058 DEBUG [org.infinispan.interceptors.InterceptorChain] (ServerService Thread Pool -- 62) Interceptor chain size: 12

      2016-06-16 10:23:02,058 DEBUG [org.infinispan.interceptors.InterceptorChain] (ServerService Thread Pool -- 62) Interceptor chain is:

                      >> org.infinispan.interceptors.distribution.DistributionBulkInterceptor

                      >> org.infinispan.interceptors.InvocationContextInterceptor

                      >> org.infinispan.statetransfer.StateTransferInterceptor

                      >> org.infinispan.statetransfer.TransactionSynchronizerInterceptor

                      >> org.infinispan.interceptors.TxInterceptor

                      >> org.infinispan.interceptors.locking.PessimisticLockingInterceptor

                      >> org.infinispan.interceptors.NotificationInterceptor

                      >> org.infinispan.interceptors.GroupingInterceptor

                      >> org.infinispan.interceptors.EntryWrappingInterceptor

                      >> org.infinispan.interceptors.ClusteredActivationInterceptor

                      >> org.infinispan.interceptors.distribution.TxDistributionInterceptor

                      >> org.infinispan.interceptors.CallInterceptor

      2016-06-16 10:23:02,066 DEBUG [org.infinispan.jmx.JmxUtil] (ServerService Thread Pool -- 62) Object name jboss.infinispan:type=Cache,name="test-sessions-cache.war(dist_async)",manager="web",component=Cache already registered

       

      FAAR cache container:

      2016-06-16 10:23:19,349 DEBUG [org.infinispan.interceptors.InterceptorChain] (default task-3) Interceptor chain size: 5

      2016-06-16 10:23:19,349 DEBUG [org.infinispan.interceptors.InterceptorChain] (default task-3) Interceptor chain is:

                      >> org.infinispan.interceptors.InvocationContextInterceptor

                      >> org.infinispan.interceptors.CacheMgmtInterceptor

                      >> org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor

                      >> org.infinispan.interceptors.EntryWrappingInterceptor

                      >> org.infinispan.interceptors.CallInterceptor

      2016-06-16 10:23:19,351 DEBUG [org.infinispan.jmx.JmxUtil] (default task-3) Object name jboss.infinispan:type=Cache,name="dist(local)",manager="FAAR",component=Cache already registered

       

      You can also see from the line above that Infinispan considers the cache to be local. This behavior does not occur in WildFly 9.0.2 using the same configuration, all of the distributed caches sync without issue.

       

      Please advise.

        • 1. Re: WildFly 10 distributed cache does not sync
          Paul Ferraro Master

          How are you starting your cache?  Please paste any relevant code.

          • 2. Re: WildFly 10 distributed cache does not sync
            Tendai Munetsi Newbie

            Hi Paul,

            Below is the code to a bean class that inserts then retrieves an object from the distributed cache. When the code below is run on the first node, the object is inserted, then retrieved from the cache. When the code is run on a second node, one would expect it to find the object (which happens on WildFly 9.0.2) and not insert another object into the cache with the same key (which is happening on WildFly 10.0.0).

             

            import java.io.Serializable;

            import java.util.logging.Logger;

             

            import javax.annotation.PostConstruct;

            import javax.annotation.Resource;

            import javax.faces.bean.ManagedBean;

            import javax.faces.bean.RequestScoped;

             

            import org.infinispan.manager.CacheContainer;

             

            import com.avlogic.model.AviationAccident;

             

            @ManagedBean(name = "requestBean")

            @RequestScoped

            public class RequestBean implements Serializable {

                 private static final long serialVersionUID = 1L;

                 private static Logger logger = Logger.getLogger(RequestBean.class.getName());

             

                 @Resource(lookup="java:jboss/infinispan/container/FAAR")

                 private CacheContainer container;


                 private org.infinispan.Cache<String, AviationAccident> cache;

             

                 @PostConstruct

                 private void initCache() {

                      cache = container.getCache();

                 }


                 public String save() {

                      logger.info("Clicked the save for request bean");

                      AviationAccident cacheObj = cache.get("1");

                      if (!cache.containsKey((Object)"1")) {

                           AviationAccident accident = new AviationAccident();

                           accident.setEventId("1111111");

                           accident.setAccidentNumber("FA123456");

                           accident.setEventDate("11/04/2015");

                           cache.put("1", accident);

                           logger.info("Inserted cache object: " + accident);

                           if (cache.get("1") != null) {

                                logger.info("Retrieved cache object: " + accident);

                           } else {

                                logger.info("Cannot retrieve inserted cache object: " + accident);

                           }

                      } else {

                           AviationAccident accident = (AviationAccident)cacheObj;

                           logger.info("Found cache object: " + accident);

                      }

                      return "request.xhtml";

                 }

             

            }

            • 3. Re: WildFly 10 distributed cache does not sync
              Siyavash Habashi Newbie

              Had the same issue.

               

              Tried successfully to inject the Cache directly instead to get the Cache from the cacheContainer programmatically.

               

              @Resource(lookup = "java:jboss/infinispan/cache/myCacheContainer/myCacheName")

              void setCache(Cache<String, MyData> cache) {

                this.cache = cache;
              }

               

              See also following thread: WildFly10: What is the right way to get preconfigured Infinispan cache instance?

              • 4. Re: WildFly 10 distributed cache does not sync
                Paul Ferraro Master

                Cache configurations are intended to auto-define once their dependencies are satisfied.  WF 10.0.0.Final contained a bug preventing this from happening properly.

                See:

                [WFLY-6674] Infinispan subsystem cache configuration is lost when cache is created - JBoss Issue Tracker

                WFLY-6674 Auto-install cache configurations when cache manager starts · wildfly/wildfly@7422623 · GitHub

                 

                The issue is fixed in WF master, and will be included in 10.1.0.Final.

                 

                In general, you can inject the default cache of a given cache container by the following jndi name:

                <resource-ref>
                     <res-ref-name>mycache</res-ref-name>
                     <lookup-name>java:jboss/infinispan/cache/FAAR/default</lookup-name>
                </resource-ref>
                
                
                @Resource(name = "mycache")
                private Cache<?, ?> cache;
                
                
                • 5. Re: WildFly 10 distributed cache does not sync
                  Tendai Munetsi Newbie

                  Thanks! The last two posts corrected the problem.