-
1. Re: Struggling with ContraintViolationExceptions when accessing a node (after write)
rhauch Feb 19, 2013 8:12 PM (in response to clementp)1 of 1 people found this helpfulIf one were to write using two threads concurrently to a node of type foo:bar with the name "node1". Those two writes would succeed
This actually is not the way ModeShape works. ModeShape uses node-level transactional locks, which means even if the two sessions are saved at exactly the same time, only one session will obtain the lock in its transaction, forcing the other session (with a different transaction) to wait until the lock is released (when the other transaction commits or rolls back). We tried to explain that a bit in this blog post.
Now, it is a possibliity that the two sessions are timed such that they both pass their validation but then lock on the persisting operation.
Can you create a simple test case that replicates this? And can you please log an issue in our JIRA?
In particular, should one of the writes fail (does it fail silently)? What is the expected behavior in a case like this?
It does not fail at the moment, so it is probably persisting both the child nodes. When the second one is read, it is likely encountering the inability to find a child node definition for the second child node. Does this match where you're seeing the exception being thrown?
Should the developer "lock" the parent node before attempting the write to fix this (although I think this is a rather common use case of transactions and isolation)?
That certainly would be a workaround to prevent the concurrent sessions from modifying the same parent node, though it's not ideal.
-
2. Re: Struggling with ContraintViolationExceptions when accessing a node (after write)
rhauch Feb 19, 2013 8:17 PM (in response to rhauch)1 of 1 people found this helpfulOh, one more thing. It shouldn't be related to AS7, and should be reproducible in a JavaSE environment with a real transaction manager. Note that our unit tests fit the bill, and you could probably add a test method to ConcurrentWriteTest. In particular, this existing test is relatively similar (though it's simultaneously removing rather than adding) and uses a CyclicBarrier to artificially force the session.save() calls to occur at the same time (or as close as we can get them):
If you don't want to create a test case, just having your client code and complete CNDs would be sufficient.
-
3. Re: Struggling with ContraintViolationExceptions when accessing a node (after write)
clementp Feb 19, 2013 9:26 PM (in response to rhauch)Thanks Randall. I'll have the code checked out and tests running inside IntelliJ already, I am just trying to understand the CND that's being used (since I need a custom one that's not nt:unstructured) and how the test harness is used.
-
4. Re: Struggling with ContraintViolationExceptions when accessing a node (after write)
clementp Feb 19, 2013 9:55 PM (in response to clementp)Issue created in Jira: https://issues.jboss.org/browse/MODE-1821
Testcase created in Github: https://github.com/panghy/modeshape/commit/4d268ee8369a052fc329e72dc9c4ac33e258e211
Let me know if more background info is needed. The test case shows that serliazed call do fail but concurrent calls succeed with more than the expected number of nodes written (no failures on the save).
-
5. Re: Struggling with ContraintViolationExceptions when accessing a node (after write)
clementp Feb 27, 2013 6:53 PM (in response to clementp)Fixed in 3.1.3.Final. Thanks.