Return-Path: Delivered-To: apmail-jackrabbit-dev-archive@www.apache.org Received: (qmail 9349 invoked from network); 12 Feb 2007 10:37:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 12 Feb 2007 10:37:53 -0000 Received: (qmail 64042 invoked by uid 500); 12 Feb 2007 10:37:59 -0000 Delivered-To: apmail-jackrabbit-dev-archive@jackrabbit.apache.org Received: (qmail 64008 invoked by uid 500); 12 Feb 2007 10:37:58 -0000 Mailing-List: contact dev-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list dev@jackrabbit.apache.org Received: (qmail 63996 invoked by uid 99); 12 Feb 2007 10:37:58 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Feb 2007 02:37:58 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of marcel.reutegger@gmx.net designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 12 Feb 2007 02:37:48 -0800 Received: (qmail invoked by alias); 12 Feb 2007 10:37:26 -0000 X-Provags-ID: V01U2FsdGVkX1+QfZVR/baQ3f/3ARWQ59HTyM4tCP5EgkZ+Jq30q9 tLnw== Message-ID: <45D04380.7050503@gmx.net> Date: Mon, 12 Feb 2007 11:37:52 +0100 From: Marcel Reutegger User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: dev@jackrabbit.apache.org Subject: Re: Concurrent Node Modification using Locked utility class causes issues References: <8896073.post@talk.nabble.com> In-Reply-To: <8896073.post@talk.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org vijay s wrote: > Problem: > > I am able to get my application working with the Locked utility class, but I > believe the locking of the folder to add content is causing some issues when > I try to "concurrently" add many nodes to a single folder. > > Jackrabbit throws a random ItemNotFoundException after I add about 400 nodes > concurrently in 20 threads --> > (javax.jcr.ItemNotFoundException: > a3214cbe-2a89-4550-8b1b-2b76cce821c0/{http://www.jcp.org/jcr/1.0}lockOwner). > > Once such an error happens in one of my threads, the rest of the threads get > stuck in some form of a deadlock and my server crashes. The crashes become > more frequent and detrimental as I increase the number of concurrent threds. this is strange. our test cases for the utility use 100 concurrent threads and run without any errors. See: http://svn.apache.org/repos/asf/jackrabbit/tags/1.2.1/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/LockTest.java > Questions: > > 1) Is there any alternative to this locking procedure to add child nodes to > a node. Do we "have" to lock a parent node to add child nodes ? No, as of version 1.2.1 jackrabbit is able to handle concurrent addNode() from multiple sessions without the need to lock the parent node. See: http://issues.apache.org/jira/browse/JCR-584 > I have found > that I get better reliability when I do not use the Locked utility class, > but just synchronize the code in a way where only one session can add nodes > to a particular folder. I really do not want to single thread the > application. Any recommendations on a better approach will be really > appreciated. Any insights on this particular cause of the > ItemNotFoundException will also be helpful. See my comments inline > Code Snippet: > > public void addContent(final String nodeId, final String nodeType, final > Map properties) { > System.out.println("Adding project "+nodeId); Where do you get the session from? What does the parameter do? > Session session = getSession(true); > try { > final Node folder = session.getRootNode().getNode("assemblies"); > Node child = null; > if (!folder.hasNode(nodeId)) { > Object retChild = new Locked() { > protected Object run(Node folder) throws RepositoryException { > Node c = folder.addNode(nodeId, nodeType != null ? nodeType > : "nt:unstructured"); > c.addMixin("mix:versionable"); > for (Object key : properties.keySet()) { > c.setProperty((String) key, (String) properties > .get(key)); > } > folder.save(); > return c; > } > }.with(folder, false,100000); > if(retChild==Locked.TIMED_OUT){ > throw new RuntimeException("Exception occured when adding a node. > Please try again"); > } else { > child = (Node)retChild; > } This call is not needed. There shouldn't be any changes on the session at this point. > session.save(); > child = folder.getNode(nodeId); > System.out.println("Added project "+child.getPath()+" successfully"); > } > } catch (InterruptedException ex) { > throw new RuntimeException(ex); > } catch (RepositoryException ex) { > throw convertJCRAccessException(ex); > } finally { > session.logout(); > } > } Otherwise the code looks ok to me. Are you able to get the stacktrace of the root cause? The one that shows where the ItemNotFoundException is thrown. regards marcel > Exception Snippet: > org.springframework.dao.DataRetrievalFailureException: Item not found; > nested exception is javax.jcr.ItemNotFoundException: > a3214cbe-2a89-4550-8b1b-2b76cce821c0/{http://www.jcp.org/jcr/1.0}lockOwner > at > org.springmodules.jcr.SessionFactoryUtils.translateException(SessionFactoryUtils.java:197) > at > org.springmodules.jcr.JcrAccessor.convertJcrAccessException(JcrAccessor.java:58) > at > org.springmodules.jcr.support.JcrDaoSupport.convertJCRAccessException(JcrDaoSupport.java:117) > at ContentDaoImpl.addContent(ContentDaoImpl.java:44) > at ContentServiceImpl.addNewProject(ContentServiceImpl.java:51) >