8 Replies Latest reply on Nov 11, 2012 8:36 AM by aolean

    TreeCache problem - JDBC - JdbcStringBasedCacheStore

    eialbur

      I wrote what I thought was a minimal program just to get experience with TreeCache.  Any help would be welcome.

      Contrary to appearances, I am an experienced Java programmer ... I just can't seem to get my feet under me with Infinicache.

      I appreciate any help you can provide.

       

      Config File:

      <infinispan>

                <namedCache name="category">

                          <loaders passivation="false" shared="false" preload="true">

                                    <loader

                                              class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore"

                                              fetchPersistentState="true" purgeOnStartup="false">

                                              <properties>

                                                        <property name="databaseType" value="MYSQL" />

                                                        <property name="connectionFactoryClass"

                                                                  value="org.infinispan.loaders.jdbc.connectionfactory.SimpleConnectionFactory" />

                                                        <property name="connectionUrl" value="jdbc:mysql://localhost:3306/Hookup" />

                                                        <property name="userName" value="root" />

                                                        <property name="password" value="passw0rd" />

                                                        <property name="driverClass" value="com.mysql.jdbc.Driver" />

       

                                                        <property name="stringsTableNamePrefix" value="cache" />

                                                        <property name="dropTableOnExit" value="false" />

                                                        <property name="createTableOnStart" value="false" />

       

                                                        <property name="timestampColumnName" value="timestamp" />

                                                        <property name="timestampColumnType" value="INT8" />

                                                        <property name="idColumnName" value="category" />

                                                        <property name="idColumnType" value="VARCHAR(255)" />

                                                        <property name="dataColumnName" value="id" />

                                                        <property name="dataColumnType" value="INTEGER" />

                                              </properties>

                                    </loader>

                          </loaders>

       

                          <transaction transactionMode="TRANSACTIONAL" />

                          <invocationBatching enabled="true" />

       

                </namedCache>

      </infinispan>

       

       

      Java File (snippet):

          public static void main(String[] args) throws IOException {

              DefaultCacheManager dcm = new DefaultCacheManager("InfiniConfig.xml");

              Cache<String, Object> c = dcm.getCache("category");

              TreeCache<String, Object> treeCache = new TreeCacheFactory().createTreeCache(c);

       

      Error on createTreeCache:

      Exception in thread "main" org.infinispan.CacheException: Unable to end batch

                at org.infinispan.batch.BatchContainer.endBatch(BatchContainer.java:107)

                at org.infinispan.batch.AutoBatchSupport.endAtomic(AutoBatchSupport.java:49)

                at org.infinispan.tree.TreeStructureSupport.exists(TreeStructureSupport.java:56)

                at org.infinispan.tree.TreeStructureSupport.exists(TreeStructureSupport.java:46)

                at org.infinispan.tree.TreeCacheImpl.createRoot(TreeCacheImpl.java:442)

                at org.infinispan.tree.TreeCacheImpl.<init>(TreeCacheImpl.java:54)

                at org.infinispan.tree.TreeCacheImpl.<init>(TreeCacheImpl.java:46)

                at org.infinispan.tree.TreeCacheFactory.createTreeCache(TreeCacheFactory.java:58)

                at com.albury.infinitest.InfiniTest.main(InfiniTest.java:34)

      Caused by: javax.transaction.RollbackException: Transaction status is Status.STATUS_MARKED_ROLLBACK

                at org.infinispan.transaction.tm.DummyBaseTransactionManager.commit(DummyBaseTransactionManager.java:100)

                at org.infinispan.batch.BatchContainer.resolveTransaction(BatchContainer.java:123)

                at org.infinispan.batch.BatchContainer.endBatch(BatchContainer.java:105)

                ... 8 more

        • 1. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
          tfromm

          On a first view I'd say there is a problem with the loader. Maybe: <property name="createTableOnStart" value="false" /> should be true.

          And  <property name="dataColumnType" value="INTEGER" /> looks suspicious to me, since this is the field where the cache objects are serialized into.

           

          Btw object serialization just as hint: Look at https://docs.jboss.org/author/display/ISPN/Plugging+Infinispan+With+User+Defined+Externalizers

          In general I'd try to avoid the use using default serialization of objects, because you'll get in problems, when refactoring classes...

          • 2. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
            eialbur

            I changed the data column type to varbinary(100) and allowed Infinispan to create the table.... same error.

            • 3. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
              tfromm

              Turn trace log level on.

              And simply use "BINARY" als data column type.

              • 4. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
                eialbur

                MySql objected to just BINARY ... it wanted a length .... and I was loath to make it a fixed length (and wasn't sure what fixed length to make it)

                 

                INFO  TransactionManagerFactory - ISPN000161: Using a batchMode transaction manager

                ERROR InvocationContextInterceptor - ISPN000136: Execution error

                org.infinispan.loaders.keymappers.UnsupportedKeyTypeException: Unsupported key type: 'org.infinispan.tree.NodeKey' on key: NodeKey{contents=DATA, fqn=/}

                 

                Based on the trace, and on other postings, I added the following to my config:

                <property name="key2StringMapperClass" value="org.infinispan.loaders.keymappers.DefaultTwoWayKey2StringMapper" />

                That didn't fix anything

                 

                I guess it is trying to turn a NodeKey into a string and is failing.  I didn't really expect the DefaultTwoWayKey2StringMapper to work as NodeKey is not a simple type.  However, I don't see a key mapper provided for Trees.

                • 5. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
                  eialbur

                  I decided to screw the tree cache and just get jdbc working for regular cache.  I changed my source as follows:

                   

                          DefaultCacheManager dcm = new DefaultCacheManager("InfiniConfig.xml");

                          Cache<String, Object> c = dcm.getCache("categoryX");

                   

                          CategoryNode catNode = new CategoryNode();  // my value object

                          catNode.setId(100L);

                          catNode.setName("some name");

                          c.put(catNode.getName(), catNode);

                   

                  I get the following error:

                  INFO  TransactionManagerFactory - ISPN000161: Using a batchMode transaction manager

                  ERROR InvocationContextInterceptor - ISPN000136: Execution error

                  java.lang.NullPointerException

                            at org.infinispan.loaders.jdbc.connectionfactory.SimpleConnectionFactory.releaseConnection(SimpleConnectionFactory.java:79)

                  • 6. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
                    eialbur

                    Just to make sure it was able to access the DB I set the config to create the table and then dropped the table from the db before I ran.  The table is, in fact, created, so I am connecting to the database.

                     

                    The trace indicated my data column was too narrow - A null pointer exception is a rather obscure error for this condition.  Anyways, I expanded it and I seem now to be able to do straight Infinispan to the database.

                     

                    I will play with it like this for a while ... thank you for you assistance.

                    • 7. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
                      mircea.markus

                      The NPW looks like a bug to me.

                      What version of ISPN are you using?

                      Mind raising a JIRA[1] for this with some description and (ideally) an unit test?

                      [1] https://issues.jboss.org/browse/ISPN

                      • 8. Re: TreeCache problem - JDBC - JdbcStringBasedCacheStore
                        aolean

                        Hi all,

                         

                        I confirm to have the same problem in 5.2 (just re-downloaded the entire infinispan yesterday to confirm to have the latest version, I cleaned the path).

                         

                        I'm using the simple following code, there's not even a need to try to insert/fetch any value from the cache :

                         

                        Cache<String, Object> cache = new DefaultCacheManager("cache.xml").getCache("Ion");

                        TreeCacheFactory treeCacheFactory = new TreeCacheFactory();

                        //TreeCache<String, Object> treeCache = treeCacheFactory.createTreeCache(cache);

                         

                        The previous code is working, but when I uncomment the third line (creation of the treeCache), the error is popping :

                        Unsupported key type: 'org.infinispan.tree.NodeKey' on key: NodeKey{contents=DATA, fqn=/}

                         

                        If, keeping the 3 lines uncommented, I comment out the jdbc cache store in the infinispan config file, then the error disappears.

                         

                        Would you have any idea where this issue is coming from ?

                         

                        Thanks for your assistance.