You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Alexander Nesterov <al...@gmail.com> on 2008/01/31 13:00:22 UTC
Exceptions when adding nodes from concurrently running sessions
Hello,
I have problems with adding child nodes to one parent node from
different sessions running in concurrent threads.
I've wrote a test which creates two sessions and launches two threads
used to add nodes to the same parent node. The names of child nodes
are unique. According to JCR-584 "Improve handling of concurrent node
modifications" the following scenario "session 1 adds or removes child
node 'x', session 2 adds or removes child node 'y'" should run
gracefully. But my test constantly fails with various exceptions like:
Exception in thread "Thread-8" java.lang.RuntimeException:
javax.jcr.nodetype.ConstraintViolationException: /A/7 needs to be
saved as well.
or
Exception in thread "Thread-8" java.lang.RuntimeException:
javax.jcr.RepositoryException: /A: unable to update item.: Unable to
resolve path for item:
016b885a-64aa-45b9-a990-05cbabb4586f/{http://www.jcp.org/jcr/1.0}primaryType:
Unable to resolve path for item:
016b885a-64aa-45b9-a990-05cbabb4586f/{http://www.jcp.org/jcr/1.0}primaryType
The code of my test is the following:
public void testSync() throws Exception
{
Node rootNode = getSession ().getRootNode ();
rootNode.addNode ("A");
rootNode.save();
final Session session1 = getRepository().login (new SimpleCredentials
("userName", "password".toCharArray()));
final Session session2 = getRepository().login (new SimpleCredentials
("userName", "password".toCharArray()));
Thread thread1 = new Thread (new Runnable()
{
public void run()
{
try
{
addNodes ("A", session1, 0);
}
catch (RepositoryException ex)
{
throw new RuntimeException (ex);
}
}
});
Thread thread2 = new Thread (new Runnable()
{
public void run()
{
try
{
addNodes ("A", session2, 1001);
}
catch (RepositoryException ex)
{
throw new RuntimeException (ex);
}
}
});
thread1.start();
thread2.start();
thread1.join();
thread2.join();
}
private void addNodes (String parentName, Session session, int startIndex)
throws RepositoryException
{
Node parentNode = session.getRootNode().getNode (parentName);
for (int i = startIndex; i < startIndex + 100; i++)
{
String name = Integer.toString (i);
parentNode.addNode (name);
parentNode.save();
}
}
The test fails both on Jackrabbit 1.3.3 and 1.4.
Do I get something wrong or is it a bug in Jackrabbit?
TIA,
--
Alexander Nesterov
Re: Exceptions when adding nodes from concurrently running sessions
Posted by Stefan Guggisberg <st...@gmail.com>.
On Feb 1, 2008 5:22 PM, Alexander Nesterov <al...@gmail.com> wrote:
> Hi Stefan,
>
> I've created a jira case JCR-1359 "Adding nodes from concurrently
> running sessions cause exceptions".
excellent, thanks!
cheers
stefan
>
> --
> Alexander Nesterov
>
> On Jan 31, 2008 3:32 PM, Stefan Guggisberg <st...@gmail.com> wrote:
> > hi alexander
> ...
>
> >
> > this seems to be a bug. could you please create a jira issue
> > and include your test case?
> >
>
Re: Exceptions when adding nodes from concurrently running sessions
Posted by Alexander Nesterov <al...@gmail.com>.
Hi Stefan,
I've created a jira case JCR-1359 "Adding nodes from concurrently
running sessions cause exceptions".
--
Alexander Nesterov
On Jan 31, 2008 3:32 PM, Stefan Guggisberg <st...@gmail.com> wrote:
> hi alexander
...
>
> this seems to be a bug. could you please create a jira issue
> and include your test case?
>
Re: Exceptions when adding nodes from concurrently running sessions
Posted by Stefan Guggisberg <st...@gmail.com>.
hi alexander
On Jan 31, 2008 1:00 PM, Alexander Nesterov <al...@gmail.com> wrote:
> Hello,
>
> I have problems with adding child nodes to one parent node from
> different sessions running in concurrent threads.
>
> I've wrote a test which creates two sessions and launches two threads
> used to add nodes to the same parent node. The names of child nodes
> are unique. According to JCR-584 "Improve handling of concurrent node
> modifications" the following scenario "session 1 adds or removes child
> node 'x', session 2 adds or removes child node 'y'" should run
> gracefully. But my test constantly fails with various exceptions like:
>
> Exception in thread "Thread-8" java.lang.RuntimeException:
> javax.jcr.nodetype.ConstraintViolationException: /A/7 needs to be
> saved as well.
>
> or
>
> Exception in thread "Thread-8" java.lang.RuntimeException:
> javax.jcr.RepositoryException: /A: unable to update item.: Unable to
> resolve path for item:
> 016b885a-64aa-45b9-a990-05cbabb4586f/{http://www.jcp.org/jcr/1.0}primaryType:
> Unable to resolve path for item:
> 016b885a-64aa-45b9-a990-05cbabb4586f/{http://www.jcp.org/jcr/1.0}primaryType
>
> The code of my test is the following:
>
> public void testSync() throws Exception
> {
> Node rootNode = getSession ().getRootNode ();
> rootNode.addNode ("A");
> rootNode.save();
>
> final Session session1 = getRepository().login (new SimpleCredentials
> ("userName", "password".toCharArray()));
> final Session session2 = getRepository().login (new SimpleCredentials
> ("userName", "password".toCharArray()));
>
> Thread thread1 = new Thread (new Runnable()
> {
> public void run()
> {
> try
> {
> addNodes ("A", session1, 0);
> }
> catch (RepositoryException ex)
> {
> throw new RuntimeException (ex);
> }
> }
> });
>
> Thread thread2 = new Thread (new Runnable()
> {
> public void run()
> {
> try
> {
> addNodes ("A", session2, 1001);
> }
> catch (RepositoryException ex)
> {
> throw new RuntimeException (ex);
> }
> }
> });
>
> thread1.start();
> thread2.start();
>
> thread1.join();
> thread2.join();
> }
>
> private void addNodes (String parentName, Session session, int startIndex)
> throws RepositoryException
> {
> Node parentNode = session.getRootNode().getNode (parentName);
> for (int i = startIndex; i < startIndex + 100; i++)
> {
> String name = Integer.toString (i);
> parentNode.addNode (name);
> parentNode.save();
> }
> }
>
> The test fails both on Jackrabbit 1.3.3 and 1.4.
>
> Do I get something wrong or is it a bug in Jackrabbit?
this seems to be a bug. could you please create a jira issue
and include your test case?
thanks!
stefan
>
> TIA,
> --
> Alexander Nesterov
>