5 Replies Latest reply: Mar 23, 2012 7:05 AM by Jeremy Stone RSS

Write skew semantics

Jeremy Stone Newbie

We are upgrading from JBoss Cache to Infinispan (5.1.2.FINAL).

 

We have code that relies on write skew detection but that does not work in Infinispan.

 

My understanding of write skew detection is that if there are two threads (accessing a local cache simplicity - but presumably this should extend to cluster scenarios) that are both executing code (from https://community.jboss.org/message/649135) of the form:

counter = 0

beginTx

Integer count = cache.get("counter");

count = count + 1;

cache.put("counter", count)

commitTx

 

 

then whatever thread interleavings occur one of the following will occur:

  • the counter will successfully be incremented twice (once by each thread)
  • the counter will be incremented once by one thread and a CacheException will be thrown for the other thread (either at the put or at the commit stages).

 

However this does not seem to be the case. Both threads read the same initial value and successfully update the counter to 1.

 

I attach a test case based on your AbstractClusteredWriteSkewTest (but simplified for a local cache). The only other significant change is that I set result = result & uniqueValuesSet.add(value) in the thread run method (so that it can detect if the result ever becomes false - rather than just checking the last value).

 

Any thoughts - or am I mis-understanding write skew semantics?

 

Thanks.