0 Replies Latest reply on Oct 2, 2010 7:39 AM by dubacher

    Lost update problem...

    dubacher

      Hi there.

       

      I have the problem that to threads want to create the new same node with the same key but different value at the same time. The value set by the threads depend on the value already set in the cache.

       

      So each thread does the following.

      1. Get the value for a fqn/key in the cache (i.e. returns the value 5)

      2. Increment the value by a certain value (i.e. 5 + 3 = 8)

      3. Put the value back in the cache (i.e. 8).

       

      At the moment the JBossCache ist configured as follows:

      Mode = local

      Transaction = yes.

      IsolationLevel = Repeatable_Read

       

      Now if the node for the given fqn/key exists we are able to detect concurrent write conflicts by enabling "WriteSkewCheck". But initially for the given fqn/key no node does exist. If to threads happend to create this fqn/key at the same time we have the following scenario.

       

      Thread 1: Start Transaction

      Thread 1: Get the node with fqn/key. Null is returned.

      Thread 1: Create a new node an puts it into the cache by calling cache.put(Fqn.fromString("mynode"), 1, 3) whereas 1 is the key and 3 the value.

      Thread 2: Start Transaction

      Thread 2: Get the node with fqn/key. Null is returned as we have transaction isolation...

      Thread 2: Create a new node an puts it into the cache by calling cache.put(Fqn.fromString("mynode"), 1, 5). The thread has to wait because of write lock of thread 2.

      Thread 1: Commit transaction

      Thread 2: Receives lock (before running into TimeoutException) and writes the value 5 in the cache.

      Thread 2: Commit transaction.

       

      So now we have for the given fqn/key the value 5 in the cache, whereas the correct result should be 8 (= 3 + 5). So we have a lost update problem.

       

      My question: How do you solve such a problem with JBossCache? I tried using Interceptors etc. but didn't succeed up to now...

       

      I you need more information I am happy to give you more detailled explanations.

       

      cheers,

      marco