|
Emmanuel Bernard, I investigated this issue a bit and as it turns out, there is a risk of lost updates. It's true that we try try to compare old and new value of an optimistic locking version field, but there is still a time window where we'd not discover updates by competing threads.
I think that really we'd have to pass on the old version to GridDialect#insertOrUpdateTuple() so we can apply "find and update" semantics there. E.g. MongoDB has a find findAndModify() method to which we could pass the tuple {id=123, version=23} when selecting a document for being updated (similar to the "... WHERE ID=123 AND VERSION=23" applied for RDBMS).
We then could either:
-
raise an exception in the dialects themselves if no record was matched or
-
return one of the following (which would I prefer): the number of updated records (0 or 1) OR just a boolean flag OR a Tuple with the new state of the updated (which would be null in the case of a concurrent update)
I assume it's a similar issue for updating embedded associations where we'd have to take care of the version property of the embedding entity document.
|