5 Replies Latest reply on May 27, 2011 10:19 AM by Galder Zamarreño

    Problem creating Named Cache programatically

    patilka Newbie

      Hi,

       

      I am trying some HA scenarios. I Have a 2 node embedded cache cluster setup(Node1 and Node2) in replication Mode.

       

      1.I have added a Named cache "RUNTIMECACHE" programatically in Node1. and created same "RUNTIMECACHE" in Node2 as well.

      2.I added some 10 entries in Node1 in "RUNTIMECACHE". and I am able to read all 10 entries in Node2 which are added in Node1.

      3. I restarted the Node1. I tried to read the entries which are present in Node2 memory. But I am not able to read the entries .

      4.I also tried restarting the Node1 with changing the configuration file but still i faced same problem.

      5.After restarting the Node1 i added some more entries in "RUNTIMECACHE" and which got replicated in Node2 and able to read new entries added in Node1.

       

      I am not getting why it is not replicating old data which is present in Node2.

       

       

      regards,

      Kavita Patil

        • 1. Problem creating Named Cache programatically
          Richard Yang Apprentice

          I am having similar issue. I am using infinispan that comes with jboss AS6Final. It is 4.2.0Final.

          I have two nodes to form a cluster. The CacheContainer calls getCache("nonexistCache"); this would cause the cachecontainer to create the cache called "nonexistCache". I then add cache entries to both nodes (through a simple UI). However, the entried added from node1 shows up in node 2, but entries added through node 2 did not show up in node1. I even restart node1, but it does not see entries added from node 2.

          If I preconfigure the named cache such as getCache("existingCache"), then entries show up in both nodes no matter they are entered through node1 or 2.

           

          My infinispan config:

           

          <infinispan-config name="epen_application" jndi-name="java:CacheManager/my">

                  <infinispan xmlns="urn:infinispan:config:4.2">

                      <global>

                          <transport clusterName="${jboss.partition.name:DefaultPartition}-my"

                              distributedSyncTimeout="17500">

                              <properties>

                                  <property name="stack" value="${jboss.default.jgroups.stack:udp}" />

                              </properties>

                          </transport>

                          <globalJmxStatistics enabled="true" />

                          <shutdown hookBehavior="DONT_REGISTER" />

                      </global>

                      <default>

                          <jmxStatistics enabled="true" />

                          <clustering mode="distribution">

                              <l1 enabled="true" lifespan="60000" />

                              <hash numOwners="1" rehashRpcTimeout="120000" />

                              <sync />

                          </clustering>

                      </default>

                      <namedCache name="existingCache">

                          <locking concurrencyLevel="5000" />

                          <clustering mode="distributed">

                              <sync />

                          </clustering>

                      </namedCache>

                      <namedCache name="Response">

                          <locking concurrencyLevel="5000" />

                          <clustering mode="distributed">

                              <sync />

                          </clustering>

                      </namedCache>

                  </infinispan>

              </infinispan-config>

          • 2. Problem creating Named Cache programatically
            Vladimir Blagojevic Master

            Kavita,

             

            What does your programmatic configuration look like?

             

            Regards,

            Vladimir

            • 3. Problem creating Named Cache programatically
              Richard Yang Apprentice

              Vladimir:

              This is my default distributed cache looks like:

              <global>

                              <transport clusterName="${jboss.partition.name:DefaultPartition}-epen"

                                  distributedSyncTimeout="17500">

                                  <properties>

                                      <property name="stack" value="${jboss.default.jgroups.stack:udp}" />

                                  </properties>

                              </transport>

                              <globalJmxStatistics enabled="true" />

                              <shutdown hookBehavior="DONT_REGISTER" />

                          </global>

                          <default>

                              <jmxStatistics enabled="true" />

                              <invocationBatching enabled="true" />

                              <locking isolationLevel="READ_COMMITTED"

                                  lockAcquisitionTimeout="20000" writeSkewCheck="false"

                                  concurrencyLevel="5000" useLockStriping="false" />

                              <transaction

                                  transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"

                                  syncRollbackPhase="false" syncCommitPhase="false" useEagerLocking="true"

                                  eagerLockSingleNode="true" />

                              <clustering mode="distribution">

                                  <l1 enabled="false" lifespan="60000" />

                                  <hash numOwners="1" rehashRpcTimeout="120000" />

                                  <sync />

                              </clustering>

                          </default>

               

              I create the cache programmatically like this:

              public Cache<?, ?> findCacheByName(String cacheName) {

                      Cache<?, ?> cache = null;

                      if (!StringUtils.isEmpty(cacheName) && !cacheExists(cacheName)) {

                          Configuration c = cacheManager.getDefaultConfiguration().clone();

                          // c.setCacheMode(CacheMode.DIST_SYNC);

                          // c.setOtherAttributeToOverrideDefault

                          cacheManager.defineConfiguration(cacheName, c);

                          cache = cacheManager.getCache(cacheName);

               

                      } else {

                          cache = cacheManager.getCache(cacheName);

                      }

               

                      return cache;

                  }

               

              The problme is that the cache that is created in node1 is not visible to node 2 in a distributed mode.

               

              I am using jboss 6 and infinispan 4.2.

               

              Please help.

               

              Thanks.

              Richard

              • 4. Problem creating Named Cache programatically
                patilka Newbie

                Hi Vladimir,

                 

                Sorry for late reply.

                 

                My programatic configuration looks like below.

                 

                Configuration config=manager.getDefaultConfiguration().clone();

                                    config.setCacheMode(CacheMode.REPL_SYNC);

                                    config.setExpirationLifespan(500000);

                                    config.setFetchInMemoryState(true);

                                    config.setAlwaysProvideInMemoryState(true);

                                    config.setStateRetrievalTimeout(20000);

                                    config.setSyncReplTimeout(20000);

                                    String newCacheName = "RUNTIMECACHE";

                 

                 

                                    manager.defineConfiguration(newCacheName, config);

                                    Cache<String, String> cache = manager.getCache(newCacheName);

                 

                Regards,

                Kavita

                • 5. Re: Problem creating Named Cache programatically
                  Galder Zamarreño Master

                  Not sure what this programmatic configuration is used for, but for your question on "nonexistCache", if the name does not match any of the named caches, it creates a cache that's a clone of the default one, and the default one has no <clustering> element configured, hence why data is not replicated/distributed.