jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <jukka.zitt...@gmail.com>
Subject Concurrent addNode (Was: [jira] Commented: (JCR-1552) Concurrent conflicting property creation sometimes doesn't fail)
Date Thu, 24 Apr 2008 17:29:24 GMT
Hi,

Let's keep JCR-1552 focused on the setProperty semantics. The addNode
method is a whole different issue so I'm taking it back to the mailing
list.

On Thu, Apr 24, 2008 at 5:19 PM, Thomas Mueller (JIRA) <jira@apache.org> wrote:
> When concurrently updating or adding nodes (so far I was talking about properties only),
> the same algorithm can be used. One problem is the following use case:
>
>  Node b = a.hasNode(x) ? a.getNode(x) : a.addNode(x);
>
> With multiple threads / sessions you end up with same name siblings sometimes.
> That's probably not what the user wants.

The best solution IMHO is not to allow SNS in the first place. For
example this won't be a problem within an nt:folder node.

> I don't know if there is a solution for nodes without using locks.

Yes, you can use a JCR lock on the parent node to avoid SNSs in such
cases, but IMHO a node type constraint is better in this case.

> For SQL databases, one solution is using the MERGE statement (sometimes
> called UPSERT from INSERT or UPDATE).

Another solution would be a custom getOrAddNode() method, like the one
I've implemented in [1]. It's not a perfect solution, but works pretty
well in practice.

[1] https://svn.apache.org/repos/asf/james/server/trunk/jcr-backend-function/src/main/java/org/apache/james/jcr/JCRStoreBean.java

BR,

Jukka Zitting

Mime
View raw message