10 Replies Latest reply on Jun 23, 2011 11:21 AM by Manik Surtani

    Problem: create cache programmatically in jboss AS 6

    Richard Yang Apprentice

      Jboss AS 6 Final'a all profile comes with infinispan 4.2.0.FINAL. We are using it with no problem with predefined named cache. However, when I use the following code to look for a cache name which does not exist, the created cache name is always _defaultCache.

       

      Let's say the passed in newcache name is called "newCacheName"

       

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

              Cache<?, ?> cache = null;

              if (!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 cacheManager is lookedup through jndi:

      EmbeddedCacheManager ecm = (EmbeddedCacheManager) jndi

      .jndiLookup("MyCacheManager);

       

      But intestingly, the newly createdly cache ("_defaultCache")'s cache manager now becomes MyCacheManager/newCacheName)

       

       

      Here is my infinispan xml (Note this is part of the infinispan config that is part of the jboss cluster deployer)

       

      <infinispan-config name="epen_application" jndi-name="java:MyCacheManager">

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

                  <global>

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

                          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>

       

              </infinispan>

          </infinispan-config>

       

      Can anybody tell me why it always creates _defaultCache instead of the cache name that I want?

       

      Is this a defect in 4.2.0.Fianl?

        • 1. Re: Problem: create cache programmatically in jboss AS 6
          Paul Ferraro Master

          It looks like you've discovered AS6's workaround for ISPN-658.

          Because of ISPN-658, you cannot safely use multiple DIST-mode caches in the same cache manager.

          The AS implements a workaround for this, such that you *appear* to be able create multiple caches, but really under the covers a separate cache manager is created for every DIST cache.  The cache manager is named using the name of the requested cache name.  The actual cache name will always be "__defaultCache".  This *should* be mostly transparant from an API perspective.

          So, to answer your question - no, this is not a defect - but rather an intentional workaround.

          • 2. Re: Problem: create cache programmatically in jboss AS 6
            Richard Yang Apprentice

            Paul:

             

            Thanks for your reply. For now since ISPN-658 is yet to be resolved, I am using pre-conifgured cache.

             

            However, I have been struggling to find any documentation on how to upgrade jboss AS 6 Final's infinispan to version 5. I have been posting everywhere but got no answer. I tried to upgrade the infinispan modules but got NodeKey class not found exception in a distributed cluster (singlge node is OK). It seems that some old jboss classes in the jboss lib or common lib are still loaded first and ignored some of the upgraded jars.

             

            I know you are the expert on the jboss-ISPN integration. Could you shed some light on this? I heard that jboss AS 6 won't have any new release anymore (will be in AS 7). And jboss EAP 6 will have EDG 6 (which is based on ISPN 5). But we really need ISPN's query functionality, therefore needs to be able to use infinispan 5 in jbossAS 6.

             

            Could you provides some info on this?

             

            Thanks.

             

            Richard

            • 3. Re: Problem: create cache programmatically in jboss AS 6
              Paul Ferraro Master

              In summary, ISPN-658 won't be addressed.  In AS7, I've reimplemented the cache mapping of sessions to address this problem.

              In AS6, each web application created a separate cache instance (named using the host + context path) within the same cache container, and stored sessions using the session id as the cache key.

              In AS7, I've changed this mapping such that sessions for all caches are stored in the same cache instance, and store sessions in a compound key consisting of the host, context path, and session id.

               

              To upgrade AS6 to Infinispan 5 is going to require you to get your hands dirty (i.e. you'll need to download sources, make minor code changes, and rebuild).  The key module to change is jboss-ha-server-ispn.  This module contains the core infinispan integration code (e.g. CacheContainerRegistry, CacheContainerFactory, etc.).  The svn url is:

              http://anonsvn.jboss.org/repos/jbossas/projects/cluster/ha-server-ispn/trunk/

               

              At a minimum, you'll need to make the following changes:

              * Update pom.xml to use the latest infinispan 5.0 release

              * Edit the src/main/resources/META-INF/infinispan-configs.xsd and update the schema namespace of the included infinispan schema.

              * Make any necessary api-related code changes (there shouldn't be too many)

              * mvn clean install

              * You should then be able to copy the generated jar from your local maven repo into the jboss distribution, and make the necessary namespace changes to infinispan-configs.xml.

               

              BTW - there will likely be an AS 6.1 release sometime soon, though it will continue to use infinispan 4.2.x.

              • 4. Re: Problem: create cache programmatically in jboss AS 6
                Richard Yang Apprentice

                Paul:

                 

                I have followed your instruction and got latest ha-server-ispn code and changed the pom to use <version.infinispan>5.0.0.CR6</version.infinispan>

                However, I got a lot of compiler errors in many classes, mainly around Jaxb classes.

                I wonder if you could make a branch in ha-server-ispn for infinispan 5.0.0.CR6 (latest) and share it with us.

                I am sure there are lots of people who want to upgrade jboss AS 6's infinispan module and your work would greatly benefit the jboss and infinispan communities.

                 

                Thanks in advance.

                 

                Richard

                • 5. Re: Problem: create cache programmatically in jboss AS 6
                  Richard Yang Apprentice

                  Paul:

                  I managed to get rid of all the compiler error and created a new ha-server-ispn jar. However, when I started the jboss in a cluster with distributed cache, I got the same error I had before:

                  16:19:48,094 ERROR [org.infinispan.remoting.transport.jgroups.JGroupsTransport] ISPN00095: Caught while responding to state transfer request: org.infinispan.statetransfer.StateTransferException: java.io.NotSerializableException: org.infinispan.tree.NodeKey

                      at org.infinispan.statetransfer.StateTransferManagerImpl.generateInMemoryState(StateTransferManagerImpl.java:326) [:5.0.0.CR6]

                      at org.infinispan.statetransfer.StateTransferManagerImpl.generateState(StateTransferManagerImpl.java:151) [:5.0.0.CR6]

                      at org.infinispan.remoting.InboundInvocationHandlerImpl.generateState(InboundInvocationHandlerImpl.java:248) [:5.0.0.CR6]

                      at org.infinispan.remoting.transport.jgroups.JGroupsTransport.getState(JGroupsTransport.java:587) [:5.0.0.CR6]

                      at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.handleUpEvent(MessageDispatcher.java:690) [:2.12.0.Final]

                      at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.up(MessageDispatcher.java:771) [:2.12.0.Final]

                      at org.jgroups.blocks.mux.MuxUpHandler.up(MuxUpHandler.java:135) [:2.12.0.Final]

                      at org.jgroups.JChannel.up(JChannel.java:1484) [:2.12.0.Final]

                      at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:1074) [:2.12.0.Final]

                      at org.jgroups.protocols.pbcast.FLUSH.up(FLUSH.java:477) [:2.12.0.Final]

                      at org.jgroups.protocols.pbcast.STREAMING_STATE_TRANSFER$StateProviderHandler.process(STREAMING_STATE_TRANSFER.java:651) [:2.12.0.Final]

                      at org.jgroups.protocols.pbcast.STREAMING_STATE_TRANSFER$StateProviderThreadSpawner$1.run(STREAMING_STATE_TRANSFER.java:580) [:2.12.0.Final]

                      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_24]

                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_24]

                      at java.lang.Thread.run(Unknown Source) [:1.6.0_24]

                  Caused by: java.io.NotSerializableException: org.infinispan.tree.NodeKey

                      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:885) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:119) [:1.3.0.CR9]

                      at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.writeObject(ImmortalCacheEntry.java:126) [:5.0.0.CR6]

                      at org.infinispan.container.entries.ImmortalCacheEntry$Externalizer.writeObject(ImmortalCacheEntry.java:123) [:5.0.0.CR6]

                      at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.writeObject(ExternalizerTable.java:362) [:5.0.0.CR6]

                      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:145) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:119) [:1.3.0.CR9]

                      at org.infinispan.marshall.MarshallUtil.marshallCollection(MarshallUtil.java:49) [:5.0.0.CR6]

                      at org.infinispan.marshall.exts.SetExternalizer.writeObject(SetExternalizer.java:62) [:5.0.0.CR6]

                      at org.infinispan.marshall.exts.SetExternalizer.writeObject(SetExternalizer.java:47) [:5.0.0.CR6]

                      at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.writeObject(ExternalizerTable.java:362) [:5.0.0.CR6]

                      at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:145) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62) [:1.3.0.CR9]

                      at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:119) [:1.3.0.CR9]

                      at org.infinispan.marshall.jboss.GenericJBossMarshaller.objectToObjectStream(GenericJBossMarshaller.java:119) [:5.0.0.CR6]

                      at org.infinispan.marshall.VersionAwareMarshaller.objectToObjectStream(VersionAwareMarshaller.java:157) [:5.0.0.CR6]

                      at org.infinispan.statetransfer.StateTransferManagerImpl.generateInMemoryState(StateTransferManagerImpl.java:324) [:5.0.0.CR6]

                      ... 14 more

                  Caused by: an exception which occurred:

                      in object org.infinispan.tree.NodeKey@ff816b1c

                      in object org.infinispan.container.entries.ImmortalCacheEntry@2449f33f

                      in object java.util.HashSet@5db645f9

                   

                  This really puzzled me and also infinispan developers. I guess this has something to do with the infinispan-tree.jar that comes with jboss as 6.

                  If my cluster has only one node, this error did not occur. But as soon as I have more than one nodes in the cluster, this error occurred.

                   

                  So I am back to the original problem that I posted about three months ago. Could you help me figure out why this NodeKey problem occurred?

                   

                  I am not using tree cache, why there is a treeNode?

                   

                  Thanks.

                  • 6. Re: Problem: create cache programmatically in jboss AS 6
                    Paul Ferraro Master

                    infinispan-tree is used by HA-JNDI.  You will also need to download the following source:

                    http://anonsvn.jboss.org/repos/jbossas/projects/cluster/ha-server-cache-ispn/trunk/

                    rebuild against infinispan 5.0, and update the AS with the generated jar.

                    That should fix the above error.

                    • 7. Re: Problem: create cache programmatically in jboss AS 6
                      Richard Yang Apprentice

                      I made a new jar for ha-server-cache-ispn. Now I got error even in single node:

                       

                      Deployment "HAJNDI" is in error due to the following reason(s): org.infinispan.marshall.NotSerializableException: Object of type class org.infinispan.tree.NodeKey expected to be marshallable

                       

                          at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:1228) [:2.2.0.GA]

                          at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:905) [:2.2.0.GA]

                          at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.checkComplete(MainDeployerPlugin.java:87) [:6.0.0.Final]

                          at org.jboss.profileservice.deployment.ProfileDeployerPluginRegistry.checkAllComplete(ProfileDeployerPluginRegistry.java:107) [:0.2.2]

                          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:135) [:6.0.0.Final]

                          at org.jboss.system.server.profileservice.bootstrap.BasicProfileServiceBootstrap.start(BasicProfileServiceBootstrap.java:56) [:6.0.0.Final]

                          at org.jboss.bootstrap.impl.base.server.AbstractServer.startBootstraps(AbstractServer.java:827) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                          at org.jboss.bootstrap.impl.base.server.AbstractServer$StartServerTask.run(AbstractServer.java:417) [jboss-bootstrap-impl-base.jar:2.1.0-alpha-5]

                          at java.lang.Thread.run(Unknown Source) [:1.6.0_24]

                       

                      I also got Deployment "jboss:service=ClientUserTransaction" is in error due to the following reason(s): javax.naming.NameAlreadyBoundException: UserTransaction

                       

                      Here is the modified infinispan-configs.xml:

                      <?xml version="1.0" encoding="UTF-8"?>

                      <!-- Refer to Infinispan configuration documentation http://docs.jboss.org/infinispan/5.0/apidocs/config.html

                          for a description of the possible settings. -->

                       

                      <infinispan-configs default="epen_application"

                          xmlns="urn:jboss:infinispan-configs:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

                       

                         

                         

                          <!-- application cache-->

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

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

                                  <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" />

                                      <deadlockDetection enabled="true" spinDuration="1000" />

                                      <invocationBatching enabled="true" />

                                      <storeAsBinary enabled="true"/>

                                      <eviction maxEntries="2000" />

                                      <expiration lifespan="600000" />

                       

                                      <locking isolationLevel="READ_COMMITTED"

                                          lockAcquisitionTimeout="2000" writeSkewCheck="false"

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

                                      <transaction syncRollbackPhase="false" syncCommitPhase="false"

                                          useEagerLocking="true" eagerLockSingleNode="true" />

                                      <clustering mode="distribution">

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

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

                                          <async />

                                      </clustering>

                       

                                  </default>

                                  <namedCache name="response_record">

                                      <jmxStatistics enabled="true" />

                                      <deadlockDetection enabled="true" spinDuration="1000" />

                                      <invocationBatching enabled="true" />

                                      <storeAsBinary enabled="true"/>

                                      <eviction maxEntries="20000" />

                                      <expiration lifespan="300000" />

                       

                                      <locking isolationLevel="READ_COMMITTED"

                                          lockAcquisitionTimeout="2000" writeSkewCheck="false"

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

                                      <transaction syncRollbackPhase="false" syncCommitPhase="false"

                                          useEagerLocking="true" eagerLockSingleNode="true" />

                                      <clustering mode="distribution">

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

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

                                          <sync />

                                      </clustering>

                                  </namedCache>

                       

                       

                       

                              </infinispan>

                          </infinispan-config>

                       

                       

                       

                      </infinispan-configs>

                      • 9. Re: Problem: create cache programmatically in jboss AS 6
                        Paul Ferraro Master

                        My mistake, you'll need to recompile ha-server-cache-ispn against the new version of ha-server-ispn that you built.

                        • 10. Re: Problem: create cache programmatically in jboss AS 6
                          Manik Surtani Master

                          Interesting thread.  Would be much appreciated if this is summarised into an FAQ or a wiki page linked from http://community.jboss.org/wiki/Infinispan once a final solution/set of steps has been teased out.  :-)