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
Integer count = cache.get("counter");
count = count + 1;
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?
WriteSkewTest.java.zip 1.5 K
Jeremy, I'm assuming that the test works fine for you but it should fail?
I've just run it locally and it fails indicating that it detects a write skew.
Your ported over test: https://github.com/galderz/infinispan/commit/94bdd9c2fbc3ac1e6d3af2889208293fed147e40
The test _fails_ for me also.
The same assertion at line 101 fails. Meaning that 'result' is false for the thread so that at least one uniqueValuesSet.add(value) returned false (an attempt to add a duplicate value) for some value = v (say).
This indicates to me that it did not detect a write skew: i.e. both threads read the counter as v - 1, incremented it to v and successfully place it back into the cache. Instead I would expect one thread to throw an exception (on either the put or the commit).
Jeremy, I've had a good look at the test and in some cases, write skew is detected sometimes (see logs) but most often it's not, so I think this is a bug.
I've created https://issues.jboss.org/browse/ISPN-1941 to get this solved.