5 Replies Latest reply on Dec 14, 2006 12:30 PM by manik

    Transactions problem

    qwier

      Hi all,
      I am trying to figure out how to get transactions work with the cache.

      Please have a look at the following code snippet:

      InitialContext ic = new InitialContext();
      UserTransaction ut = (UserTransaction)ic.lookup("UserTransaction");
      ut.begin();
      Integer x = (Integer)cache.get("/Test","TestInteger");
      x = x+1;
      Thread.sleep(5000);
      cache.put("/Test", "TestInteger", x);
      ut.commit();
      


      This code is simultaneously running from two different JBoss instances within one cluster.
      How can I manage to get the x value increased by 2? Now it is increased by 1.

      Below are my cache settings related to transactions:
      TransactionManagerLookupClass=org.jboss.cache.DummyTransactionManagerLookup
      IsolationLevel=SERIALIZABLE (actually here I tried all of the possible values)
      CacheMode=REPL_SYNC
      NodeLockingScheme=PESSIMISTIC

      Thanks!

        • 1. Re: Transactions problem
          manik

          If they run simultaneously, both transactions won't succeed. One of them will fail since there will be a race condition to commit at the same time, and both transactions will have locks on the node in question.

          If you removed your sleep time, chances of success are higher, but there will still be that race condition. This is expected since cluster-wide locks are not obtained when you read your node using a cache.get().

          • 2. Re: Transactions problem
            qwier

             

            "manik.surtani@jboss.com" wrote:
            If you removed your sleep time, chances of success are higher, but there will still be that race condition. This is expected since cluster-wide locks are not obtained when you read your node using a cache.get().


            Thanks!
            But how can I obtain cluster-wide locks when modifying data inside the cache?

            • 3. Re: Transactions problem
              manik

              You can't. We don't do cluster-wide locks. :-) Remote locks are obtained on transaction commit time.

              • 4. Re: Transactions problem
                qwier

                 

                "manik.surtani@jboss.com" wrote:
                You can't. We don't do cluster-wide locks. :-) Remote locks are obtained on transaction commit time.


                OK., Lets assume a situation where N services on N different JBoss instances are reading and modifying data, how data integrity can be achieved? Only by catching failed transactions and re-running them again?

                • 5. Re: Transactions problem
                  manik

                  Yes.

                  You would want SYNC_REPL though.