13 Replies Latest reply on Aug 30, 2006 10:24 AM by Ben Wang

    Problems about updating an ArrayList in replicated TreeCache

    Huaigu Wu Newbie

      Hi, everybody:

      I met a problem when updating an arraylist. I put a Pojo object "Lobby" in a replicated TreeCache. The "Lobby" object has an Arraylist which contains objects "Player". The TreeCache is replicated on two nodes. At each node, a couple of transactions update the ArrayList. When two transactions on two nodes are updating the Arraylist at the same time, a write conflict will happen and then both abort. Then, each transaction wil retry later. At the time of retry , I met exceptions on each node. On one node , the exception is
      [java] java.lang.RuntimeException: java.lang.IllegalStateException: AOPInstance.incrementRefCount(): source fqn: /lobby/0/players/17 is already present.

      On another node, the exception is:
      [java] java.lang.RuntimeException: java.lang.RuntimeException: InternalDelegate.incrementRefCount(): null aopInstance.

      Then, I cannot continue the execution. I tried to change to use HashMap to replace ArrayList, but the the same problem still exist.

      Anybody here kowns what is the reason?

      Thank you very much.

        • 1. Re: Problems about updating an ArrayList in replicated TreeC
          Ben Wang Master

          Which version of JBossCache you are using? Do you have a junit test that I can try really quick. It'd be much easier to troubleshoot.

          Thanks,

          -Ben

          • 2. Re: Problems about updating an ArrayList in replicated TreeC
            Huaigu Wu Newbie

            I tried JBossCache 1.3.0.SP2 and 1.4.0.BETA. Both have the similar problem. The difference is that in 1.3.0, one node will say "/lobby/players/17" is already present. but in 1.4.0, both nodes say
            " [java] java.lang.RuntimeException: java.lang.RuntimeException: InternalDelegate.incrementRefCount(): null aopInstance for fqn: /lobby/0/players/17"

            Sorry, I don't know how to use junit.

            • 3. Re: Problems about updating an ArrayList in replicated TreeC
              Ben Wang Master

              Ok, I was able to re-recreate your problem using a junit test case. Here is the Jira:
              http://jira.jboss.com/jira/browse/JBCACHE-639

              I should fix it within the next day or so. So stay tuned.

              Thanks,

              -Ben

              • 4. Re: Problems about updating an ArrayList in replicated TreeC
                Ben Wang Master

                One temporary workaround is when you do the re-try, you can clone the failed pojo to a new one first.

                For example, if you know that:

                tx.begin();
                lobby.add(player);
                tx.commit();

                failed, then do
                Playler player_new = player.clone() // or whatever to construct a new player

                then
                tx.begin();
                lobby.add(player_new);
                tx.commit();

                It should work. The problem here is that the rollback is not completely clean in this case. It still has added an interceptor to the player pojo. By creating a new one then will bypass this problem.

                • 6. Re: Problems about updating an ArrayList in replicated TreeC
                  Marcel Dullaart Newbie

                  Hi,

                  How can I circumvent this problem when using the PojoCache?

                  I am running into a similar problem, as mentioned earlier, when setting a field of a class added to the cache.

                  I am using JBossCache 1.4.0.GA.

                  Regards,
                  Marcel Dullaart

                  • 7. Re: Problems about updating an ArrayList in replicated TreeC
                    Ben Wang Master

                    Marcel,

                    Is this the same problem or a similar problem. Please be specific about your usage and error log (or stack trace).

                    Thanks,

                    -Ben

                    • 8. Re: Problems about updating an ArrayList in replicated TreeC
                      Marcel Dullaart Newbie

                      I think it is a similar problem, so not exactly the same.
                      I have a couple of pojo's inserted in Lists, these lists are added to the cache.
                      One of these pojo's have a state implemented using the GoF state pattern, hence as pojo's theirselves.
                      Now when I change the state into a different state using

                      state = bindingFileState;

                      I get the following stack:
                      java.lang.RuntimeException: PojoCache.putObject(): fqn: /product/java/jboss/AMF/BindingManager/BindingFiles/0/state
                       at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:478)
                       at org.jboss.cache.aop.CacheInterceptor.invoke(CacheInterceptor.java:115)
                       at org.jboss.aop.joinpoint.FieldWriteInvocation.invokeNext(FieldWriteInvocation.java:51)
                       at org.epo.product.jboss.nodeagent.bindingmanager.BindingFile.state_w_$aop(BindingFile.java)
                       at org.epo.product.jboss.nodeagent.bindingmanager.BindingFile.setState(BindingFile.java:42)
                       at org.epo.product.jboss.nodeagent.bindingmanager.ApplicationPackage.releaseBindingfile(ApplicationPackage.java:143)
                       at org.epo.product.jboss.nodeagent.bindingmanager.BindingManager.releaseBindingFile(BindingManager.java:296)
                       at org.epo.product.jboss.nodeagent.bindingmanager.BindingManagerTest.testReleaseBindingFile(BindingManagerTest.java:239)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at junit.framework.TestCase.runTest(TestCase.java:154)
                       at junit.framework.TestCase.runBare(TestCase.java:127)
                       at junit.framework.TestResult$1.protect(TestResult.java:106)
                       at junit.framework.TestResult.runProtected(TestResult.java:124)
                       at junit.framework.TestResult.run(TestResult.java:109)
                       at junit.framework.TestCase.run(TestCase.java:118)
                       at junit.framework.TestSuite.runTest(TestSuite.java:208)
                       at junit.framework.TestSuite.run(TestSuite.java:203)
                       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
                       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
                       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
                      Caused by: java.lang.IllegalStateException: AOPInstance.incrementRefCount(): source fqn: /product/java/jboss/AMF/BindingManager/BindingFiles/0/state/appPackage is already present.
                       at org.jboss.cache.aop.AOPInstance.incrementRefCount(AOPInstance.java:92)
                       at org.jboss.cache.aop.InternalDelegate.incrementRefCount(InternalDelegate.java:98)
                       at org.jboss.cache.aop.ObjectGraphHandler.incrementRefCount(ObjectGraphHandler.java:212)
                       at org.jboss.cache.aop.ObjectGraphHandler.setupRefCounting(ObjectGraphHandler.java:192)
                       at org.jboss.cache.aop.ObjectGraphHandler.objectGraphPut(ObjectGraphHandler.java:88)
                       at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:197)
                       at org.jboss.cache.aop.TreeCacheAopDelegate._regularPutObject(TreeCacheAopDelegate.java:462)
                       at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:202)
                       at org.jboss.cache.aop.PojoCache._putObject(PojoCache.java:731)
                       at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:462)
                       ... 22 more
                      
                      


                      I have changed my code to
                      if (!state.equals(bindingFileState)) {
                       state = bindingFileState;
                      } else {
                       System.out.println("It's equal");
                      }
                      
                      Which circumvents the problem, but I expected that an assignment, whether or not with the same object would not case this stack trace.

                      Kind regards,
                      Marcel Dullaart

                      • 9. Re: Problems about updating an ArrayList in replicated TreeC
                        Ben Wang Master

                        Marcel,

                        Thanks for the detailed info. When we do putObject, internally we do check for the exisiting object. If it is, we return right away. So this is not just assignment of the same object, I'd imagine.

                        Will it be possible that you can put together a simple test? That'd help greatly.

                        Thanks,

                        -Ben

                        • 10. Re: Problems about updating an ArrayList in replicated TreeC
                          Marcel Dullaart Newbie

                          Hi Ben,

                          Simplifying the code to make a test case took some time, but I have it ready now, where can I send it to?

                          • 12. Re: Problems about updating an ArrayList in replicated TreeC
                            Jörn Eyrich Newbie

                            We see the same exception. Trying to reproduce it, I found I can only provoke it by having a circular reference. I have created a small test case (and created JBCACHE-757 (http://jira.jboss.com/jira/browse/JBCACHE-757) for it):

                            import org.jboss.cache.aop.PojoCache;
                            import org.jboss.cache.aop.annotation.PojoCacheable;
                            
                            @PojoCacheable
                            public class Main {
                             public Main reference;
                            
                             public static void main(String[] args) throws Exception {
                            
                             PojoCache cache = new PojoCache();
                             cache.startService();
                            
                             Main main = new Main();
                             Main main2 = new Main();
                            
                             main.reference = main2;
                             main2.reference = main;
                            
                             cache.putObject("/main",main);
                            
                             main2.reference = main; // <--
                            
                             System.out.println("Done...");
                             }
                            }


                            results in:

                            Exception in thread "main" java.lang.RuntimeException: PojoCache.putObject(): fqn: /main/reference/reference
                            at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:478)
                            at org.jboss.cache.aop.CacheInterceptor.invoke(CacheInterceptor.java:115)
                            at org.jboss.aop.joinpoint.FieldWriteInvocation.invokeNext(FieldWriteInvocation.java:51)
                            at Main.reference_w_$aop(Main.java)
                            at Main.main(Main.java:21)
                            Caused by: java.lang.IllegalStateException: AOPInstance.incrementRefCount(): source fqn: /main/reference/reference is already present.
                            at org.jboss.cache.aop.AOPInstance.incrementRefCount(AOPInstance.java:92)
                            at org.jboss.cache.aop.InternalDelegate.incrementRefCount(InternalDelegate.java:98)
                            at org.jboss.cache.aop.ObjectGraphHandler.incrementRefCount(ObjectGraphHandler.java:212)
                            at org.jboss.cache.aop.ObjectGraphHandler.setupRefCounting(ObjectGraphHandler.java:192)
                            at org.jboss.cache.aop.ObjectGraphHandler.objectGraphPut(ObjectGraphHandler.java:88)
                            at org.jboss.cache.aop.TreeCacheAopDelegate._putObject(TreeCacheAopDelegate.java:201)
                            at org.jboss.cache.aop.PojoCache._putObject(PojoCache.java:731)
                            at org.jboss.cache.aop.PojoCache.putObject(PojoCache.java:462)
                            ... 4 more