5 Replies Latest reply on Nov 2, 2004 3:00 PM by jiwils

    Node Locking

    jiwils

      I have a situation where I might attempt to add some information to the cache with the put(FQN, String, String) method across multiple VMs. How can I ensure that this information is written to the cache only once such that I can check for presence of the stuff to add in the cache and then add it only if necessary and not have it added by another VM between the check and the add code?

      I've noticed that nodes appear to have locks, but I can not figure out how to explicitly set them. Do I have to use a transaction manager to do this? What if I am running standalone? Is there a transaction manager I can use?

      Any ideas on how I might accomplish this?

        • 1. Re: Node Locking
          belaban

          Yes, use a TxManager. If you don't run inside the container, use DummyTransactionManager. Check the XML file(s) for an example.

          Bela

          • 2. Re: Node Locking
            jiwils

             

            "bela" wrote:
            Yes, use a TxManager. If you don't run inside the container, use DummyTransactionManager. Check the XML file(s) for an example.


            Great! Thanks for the advice. I have looked at the code/XML examples where the DummyTransactionManager was used, but I assumed it was just a "dummy"/mock obect for testing because of its name.

            • 3. Re: Node Locking
              belaban

              It doesn't support TX recovery etc, but I think it handles the before/afterCompletion() 2PC protocol correctly.

              Bela

              • 4. Re: Node Locking

                Just add addition comments.

                1. You don't need a tm to set the isolation level. With tx, the underlying lock behaving like an "auto-commit" with isolation level.

                2. One advantage of using tm is you get batch replication update during prepare/commit phase. So that has performance implication.

                3. DummyTransaction manager is only single-threaded now (e.g., support one tx at one time). We may extend it to handle multiple threads in the future.

                I will put these into FAQ.

                Thanks,

                -Ben

                • 5. Re: Node Locking
                  jiwils

                  So, my code looks something like this:

                  if (cach.containsKey(key))
                  {
                   throw something;
                  }
                  
                  <acquire lock>/<begin transaction>
                  if (cach.containsKey(key))
                  {
                   <release lock>/<rollback transaction>
                   throw something;
                  }
                  
                  cache.put(blah, key, value);
                  <release lock>/<commit transaction>
                  

                  Given these semantics, would I need to use a SERIALIZABLE isolation level, or could I get by with REPEATABLE_READ?