5 Replies Latest reply on Feb 27, 2013 6:53 PM by Clement Pang

    Struggling with ContraintViolationExceptions when accessing a node (after write)

    Clement Pang Newbie

      I have been trying to get started on ModeShape and I have ran into a problem that I think maybe a race condition when saving child nodes with the same name against a parent node that does NOT allow sns.

       

      Essentially given a CND with:

       

      [foo:baz]

      - some properties

       

      [foo:bar]

      + * (foo:baz)

       

      If one were to write using two threads concurrently to a node of type foo:bar with the name "node1". Those two writes would succeed and subsequent reads to that node would fail with a CVE. Looking at the code that actually determines the child definition of a node I believe confirms my theory. In the method "findChildNodeDefinition" within RepositoryNodeTypeManager, it uses the numberOfExistingChildrenWithSameName as the search parameter when determining the child node definition. As such, if two childs are sucessfully written concurrenlty (I would have expect one write to fail with some sort of a conflict but none was observed), the child definition would be "lost". The code works right away if foo:bar is instead replaced by nt:unstructured

       

      Obviously in that case, you wouldn't be able to detect and reject duplicate child nodes (since unstructured allows sns).

       

      I am trying to concoct a test case to demonstrate this but I just wanted to see if the devs think. In particular, should one of the writes fail (does it fail silently)? What is the expected behavior in a case like this? 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)?

       

      For the record, I was using ModeShape 3.1.2.Final with Jboss 7.1.1.Final, Infinispan 5.1.2 with PESSIMISTIC locking in FULL_XA mode. The error message is:

       

      javax.jcr.nodetype.ConstraintViolationException: Cannot find a definition for a child named 'node1' on the node at '/documents' with primary type 'foo:bar' and mixin types: []