[infinispan-dev] Fix or document? Concurrent replaceWithVersion w/ same value might all return true - ISPN-4972

Galder Zamarreño galder at redhat.com
Thu Nov 27 09:58:34 EST 2014


For those who were wondering, I’ve not forgotten about this thread, but in the last few days I saw something that made my reconsider this...

To be more precise, I saw some code of a user that was trying to keep a counter using Hot Rod. When inspected closely, Will and I realised that the user code had a very subtle bug that meant that ISPN-4972 could happen when the counter was first updated.

I’ve just tried the code in place of the `incrementCounter` method in the counter stress test we have in the testsuite [1] and the test fails as expected. You end up with incorrect counter number, e.g. should count to 4000 but ends up with 4001.

This is quite dangerous and spotting these kind of issues in the user code can take up a lot of time, so I’m rethinking again what to do about this. I’m not sure yet. I’ll reply back.

Cheers,

[1] https://github.com/infinispan/infinispan/blob/master/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ReplaceWithVersionConcurrencyTest.java

On 13 Nov 2014, at 14:08, Radim Vansa <rvansa at redhat.com> wrote:

> I agree with Galder, fixing it is not worth the cost.
> 
> Actually, there are often bugs that I'd call rather 'quirks', not 
> honoring the ConcurrentMap contract (recently we have discussed with Dan 
> [1] and [2]) which are quite complex to fix. Another one that's 
> considered not a bug is that a read does not have transactional semantics.
> Galder, where will you document that? I think that special page in 
> documentation should accumulate such cases, linked to JIRAs for case 
> that eventually we'll resolve them (with that glorious MVCC). And of 
> course, link from javadoc to this document (though I am not sure whether 
> we can correctly keep that in sync with latest release. Could we have a 
> redirection from http://infinispan.org/docs/latest to 
> http://infinispan.org/docs/7.0.x/ ?
> 
> Radim
> 
> [1] https://issues.jboss.org/browse/ISPN-3918
> [2] https://issues.jboss.org/browse/ISPN-4286
> 
> On 11/13/2014 01:51 PM, Galder Zamarreño wrote:
>> Hi all,
>> 
>> Re: https://issues.jboss.org/browse/ISPN-4972
>> 
>> Embedded cache provides atomicity of a replace() call passing in the previous value. This limitation might be lifted when we adopt Java 8 and we can pass in a lambda or similar, which can be executed right when the value is compared now, and if it returns true it’s applied. The lambda could compare both value and metadata for example.
>> 
>> Anyway, given the current status, I’m considering whether it’s worth fixing this particular issue. Fixing the issue would require adding some kind of locking in the Hot Rod server so that the version retrieval, comparison and replace call, can all happen atomically.
>> 
>> This is not ideal, and on top of that, as Radim said, the chances of this happening in real life are limited, or more precisely it’s effects are minimal. In other words, if two concurrent threads call replace with the same value, the end result is that the new value would be stored, but as a result of the code, both replaces would return true which is not strictly right.
>> 
>> I’d rather document this than add unnecessary locking in the Hot Rod server where it deals with the versioned replace call.
>> 
>> Thoughts?
>> --
>> Galder Zamarreño
>> galder at redhat.com
>> twitter.com/galderz
>> 
>> 
>> _______________________________________________
>> infinispan-dev mailing list
>> infinispan-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/infinispan-dev
> 
> 
> -- 
> Radim Vansa <rvansa at redhat.com>
> JBoss DataGrid QA
> 
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev


--
Galder Zamarreño
galder at redhat.com
twitter.com/galderz




More information about the infinispan-dev mailing list