2 Replies Latest reply on Jun 4, 2018 9:54 PM by pferraro

    How to configure and use pessimistic lock in Wildfly10/EAP7 cluster?

    pahuang

      Hi guys,

       

      I am trying to configure infinispan cache to use it as a cluster lock. Here is my config:

      <cache-container name="mt-cluster-cache">

                      <transport lock-timeout="60000"/>

                      <distributed-cache name="doc-lock" jndi-name="infinispan/mt-cluster-cache/doc-lock" mode="SYNC" owners="2">

                          <transaction locking="PESSIMISTIC" mode="FULL_XA"/>

                      </distributed-cache>

                  </cache-container>

       

      I am using CDI so here is how I produce the cache:


      @Resource(lookup = "java:jboss/infinispan/container/mt-cluster-cache")

      private CacheContainer mtClusterCache;

       

      @Produces
      @ClusteredCache(DOC_PROCESS_CACHE)

      public Cache<DocumentProcessKey, Boolean> docProcessCache() {

         return mtClusterCache.getCache(DOC_PROCESS_CACHE);

      }

       

      @Produces
      @ClusteredCache(DOC_PROCESS_CACHE)

      public TransactionManager dockProcessCacheTransactionManager(

         @ClusteredCache(DOC_PROCESS_CACHE)

        Cache<DocumentProcessKey, Boolean> cache) {

         return cache.getAdvancedCache().getTransactionManager();

      }

       

      However when I try to use it the transaction manager is null.

      transactionManager.begin();

      // transaction.begin();
      docProcessCache.getAdvancedCache().lock(key);

       

      If I inject UserTransaction from the Wildfly/EAP container and use that instead, it will complain locking requires transaction etc. What did I do wrong here? Thanks.

        • 1. Re: How to configure and use pessimistic lock in Wildfly10/EAP7 cluster?
          galder.zamarreno

          Several potential causes:

          * the cache name is wrong (DOC_PROCESS_CACHE)?

          * Errors/warnings in log (Enable TRACE to see what's up)? Maybe transaction manager is not being located?

          * Configuration is being overriden/ignored - log or stepping through the code

          * Bug? Attach a reproducable environment, or try with latest Wildfly (maybe it's been fixed)?

          • 2. Re: How to configure and use pessimistic lock in Wildfly10/EAP7 cluster?
            pferraro

            In WF10/EAP7, cache configurations are installed on-demand, thus, the above code is not sufficient to ensure that your "doc-lock" cache configuration is installed into the mt-cluster-cache container.

             

            To properly inject a configured cache into your application, add the following to your deployment descriptor:

             

            <resource-ref>
              <res-ref-name>infinispan/doc-lock</res-ref-name>
              <lookup-name>java:jboss/infinispan/cache/mt-cluster-cache/doc-lock</lookup-name>
            </resource-ref>
            

             

            Now, inject the cache itself into your class:

             

            @Resource(name="infinispan/doc-lock")
            private Cache<DocumentProcessKey, Boolean> cache;