[jboss-user] [JBoss Cache] - Lost update problem...

Marco Dubacher do-not-reply at jboss.com
Sat Oct 2 07:40:15 EDT 2010


Marco Dubacher [http://community.jboss.org/people/dubacher] created the discussion

"Lost update problem..."

To view the discussion, visit: http://community.jboss.org/message/564660#564660

--------------------------------------------------------------
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
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/564660#564660]

Start a new discussion in JBoss Cache at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2052]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20101002/6f4e1644/attachment.html 


More information about the jboss-user mailing list