3 Replies Latest reply on May 18, 2004 7:29 AM by Bela Ban

    TreeCacheAOP  transacctional add, remove for Collection

    arojo Newbie

      Hello, I'm trying to execute concurrent add,remove over a Collection for a TreeAOPCache with multiple members. I'm finding some problems that leave the Caches at inconsistent state.

      I've created a version of testConcurrentPut() method fot TreeAOPCache to be executed at:

      org.jboss.test.cache.test.standAloneAop.ReplicatedTxAopTest

      The method adds a new value at the same collection for distinct Cache members. The TX commit replication doesn't commit successfully but there aren't any Exception thrown.

      The "tester" Cache finish with "languaje" German and the "tester1" cache finish with "languaje" English.

      Probably I'm missing something important or is this a TreeCacheAOP limitation?. Is there a better way of working with collections at TreeCacheAOP?. Thank you.

      public void testConcurrentPuts() throws Exception
       {
       Thread t1 = new Thread()
       {
       Transaction tx;
      
       public void run()
       {
       try {
       tester1.createPerson("/person/test6", "p6", 50);
       UserTransaction tx = getTransaction();
       tx.begin();
       tester.addLanguage("/person/test6", "German");
       _pause(4000);
       tx.commit();
       } catch (Exception ex) {
       fail(ex.toString());
       }
       }
       };
      
       Thread t2 = new Thread()
       {
       Transaction tx;
      
       public void run()
       {
       try {
       _pause(1000); // give Thread1 time to createPerson
       UserTransaction tx = getTransaction();
       tx.begin();
       tester1.addLanguage("/person/test6", "English");
       tx.commit();
       } catch (Exception ex) {
       fail(ex.toString());
       }
       }
       };
      
       t1.start();
       t2.start();
      
       t1.join();
       t2.join();
      
       int size = tester.getLanguagesSize("/person/test6");
       assertTrue(size == 1);
       for (int i = 0; i < size; i++) {
       System.out.println("tester:" + i + " : " + tester.getLanguage("/person/test6", i));
       }
       size = tester1.getLanguagesSize("/person/test6");
       assertTrue(size == 1);
       for (int i = 0; i < size; i++) {
       System.out.println("tester1:" + i + " : " + tester1.getLanguage("/person/test6", i));
       }
       }
      
      static void _pause(long millis)
       {
       try {
       Thread.sleep(millis);
       } catch (Exception ex) {
       }
       }
      


        • 1. Re: TreeCacheAOP  transacctional add, remove for Collection
          Ben Wang Master

          Hi,

          This seems to be a bug in the replication locking protocol. I'd expect that if you do a concurrent transaction on both instances, the one that does commit first will time out and rollback. Then the second one to commit should succeed (in this case, Thread 1, "German").

          And this should have nothing to do with the aop part, i.e., TreeCache only.

          I will let you know when I have a fix.

          Thanks,

          -Ben

          • 2. Re: TreeCacheAOP  transacctional add, remove for Collection
            arojo Newbie

            Hello,
            First congratulations for a great work. I've look at the code to see if I can help to fix this. As I see it the Transaction system detects the conflict and changes both transaction status to

            Status.STATUS_ROLLEDBACK;

            at DummyTransaction.commit() but it doesnt communicate the exception. Should the transaction state be checked after the commit to force the rollback?. Maybe a rollback exception could be thrown at the commit method.

            public void commit()
             throws RollbackException, HeuristicMixedException,
             HeuristicRollbackException, SecurityException, SystemException {
            
             status=Status.STATUS_COMMITTING;
             try {
             notifyBeforeCompletion();
             status=Status.STATUS_COMMITTED;
             notifyAfterCompletion(status);
             }
             catch(Throwable t) {
             status=Status.STATUS_ROLLEDBACK;
            
             /*********************** NEW CODE **************/
             throw new RollbackException(t.getMessage());
             /****************************************************/
            
             }
            
             // Disassociate tx from thread.
             tm_.setTransaction(null);
             }
            


            Thanks
            Alvaro

            • 3. Re: TreeCacheAOP  transacctional add, remove for Collection
              Bela Ban Master

              done, checked into CVS head.
              Thanks,
              Bela