jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vijay s <vijay.sreekan...@gmail.com>
Subject Concurrent Node Modification using Locked utility class causes issues
Date Sat, 10 Feb 2007 00:23:59 GMT

Background:

I am building a small proof of concept for an authoring application using
JackRabbit and am load testing it and am having some issues with
concurrency. I am trying to add a large number of child nodes to the JCR
root node. Each node is getting added in its own session in its own thread.
I get an exception indicating that the root node (/) has been modified
outside the current call and cannot be modified again. 

The exception is similar to the problem discussed on this thread -->
http://www.nabble.com/ItemStateException-tf1192060.html#a3142004

I also read this thread and followed the steps to create a lockable
subfolder and used the Locked utility to lock the sub-folder and started
adding content. -->
http://www.nabble.com/Concurrent-modifications-...-tf1479773.html#a4004939


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.

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 ? 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.


2) Also, are there any additional references to a "how-to" /
"best-practices" guide that I can use to design for efficient and reliable
multiuser / multithreaded access to the JCR Repository.

Thanks
Vijay

Code Snippet:

	public void addContent(final String nodeId, final String nodeType, final
Map properties) {
		System.out.println("Adding project "+nodeId);
		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;
				}
				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();
		}
	}

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)

-- 
View this message in context: http://www.nabble.com/Concurrent-Node-Modification-using-Locked-utility-class-causes-issues-tf3203627.html#a8896073
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.


Mime
View raw message