Return-Path: Delivered-To: apmail-incubator-jackrabbit-dev-archive@www.apache.org Received: (qmail 14692 invoked from network); 8 Aug 2005 16:35:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 8 Aug 2005 16:35:04 -0000 Received: (qmail 18738 invoked by uid 500); 8 Aug 2005 16:35:03 -0000 Mailing-List: contact jackrabbit-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-dev@incubator.apache.org Received: (qmail 18724 invoked by uid 99); 8 Aug 2005 16:35:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2005 09:35:03 -0700 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [132.203.250.27] (HELO clouso.ulaval.ca) (132.203.250.27) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 08 Aug 2005 09:35:25 -0700 Received: from hermes.ulaval.ca(132.203.250.27) by clouso.ulaval.ca via csmap id 5ddfa7bc_082a_11da_8117_00304811f440_11624; Mon, 08 Aug 2005 12:35:02 -0400 (EDT) Received: from clouso.ulaval.ca (poste015-130.bibl.ulaval.ca [132.203.130.15]) by hermes.ulaval.ca (8.12.9/8.12.9) with ESMTP id j78GYvea010786 for ; Mon, 8 Aug 2005 12:34:57 -0400 Received: from poste015-130.bibl.ulaval.ca(132.203.130.15) by clouso.ulaval.ca via csmap id 5c320a4a_082a_11da_985e_00304811f440_11456; Mon, 08 Aug 2005 12:34:59 -0400 (EDT) Message-Id: <6.1.1.1.2.20050808120000.01a20860@hermes.ulaval.ca> X-Sender: biblnbe@hermes.ulaval.ca X-Mailer: QUALCOMM Windows Eudora Version 6.1.1.1 Date: Mon, 08 Aug 2005 12:31:05 -0400 To: jackrabbit-dev@incubator.apache.org From: Nicolas Belisle Subject: Re: concurrency problem In-Reply-To: <42F4DEFB.4090605@ingen.at> References: <42F4DEFB.4090605@ingen.at> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hi Walter, The problem is that the root Node is concurrently read & modified. Case : s0 : Read the rootNode s1 : Read the rootNode s0 : Modify rootNode : remove testnode-s0 & save() s1 : Modify rootNode : remove testnode-s1 & save() -->ERROR the rootNode=20 contains a reference to an removed node : "testnode-s0" Note: session.save() justs saves the root Node under the covers. If you put= =20 your nodes in a structure like /s0/testnode-s0 your test will succeed. Am I making sense ? or I also get damaged by to much sun in my vacation :-)= ? I also detailed some problems I had with concurrent sessions in the=20 following thread :=20 http://www.mail-archive.com/jackrabbit-dev@incubator.apache.org/msg01677.htm= l I do agree that this behavior is a bit strange (why addNode() does not=20 produce the same exceptions?)... Regards, Nicolas Le 12:02 2005-08-06, vous avez =E9crit: >Hi all, > >I wrote a simple test to simulate some concurrent sessions. But the test=20 >fails with exceptions. Is this a bug or do I get damaged by to much sun in= =20 >my short vacation? > >It happens with CQFileSystem and LocalFileSystem with all persistence=20 >managers. > >cheers, >Walter > >-- >run 1 (empty repository): >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >s0: started. >s1: started. >s2: started. >s3: started. >s4: started. >.................................................s0: ended. >.s1: ended. >s2: ended. >s3: ended. >s4: ended. > > >run 2 (data from run 1): >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >s0: started. >s1: started. >s2: started. >s3: started. >s4: started. >s2: Exception: removing testnode >javax.jcr.nodetype.ConstraintViolationException:=20 >3b2fe68b-7747-459d-92b2-216b0af472e2 needs to be saved as well. > at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1289) > at= org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:747) > at TestSession.run(TestSession.java:61) > at java.lang.Thread.run(Unknown Source) >s3: Exception: removing testnode >javax.jcr.nodetype.ConstraintViolationException:=20 >3b2fe68b-7747-459d-92b2-216b0af472e2 needs to be saved as well. > at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1289) > at= org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:747) > at TestSession.run(TestSession.java:61) > at java.lang.Thread.run(Unknown Source) >s3: ended. >s2: ended. >s4: Exception: removing testnode >javax.jcr.nodetype.ConstraintViolationException:=20 >1dca23f9-e6d5-47b3-830c-a272b9387925 needs to be saved as well. > at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1289) > at= org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:747) > at TestSession.run(TestSession.java:61) > at java.lang.Thread.run(Unknown Source) >s4: ended. >s0: Exception: adding testnode >javax.jcr.ItemNotFoundException: 3b2fe68b-7747-459d-92b2-216b0af472e2 > at=20 >= org.apache.jackrabbit.core.ItemManager.createItemInstance(ItemManager.java:= 498) > at=20 > org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:349) > at=20 >= org.apache.jackrabbit.core.NodeImpl.internalAddChildNode(NodeImpl.java:781) > at=20 > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:725) > at=20 > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:672) > at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1721) > at TestSession.run(TestSession.java:69) > at java.lang.Thread.run(Unknown Source) >s0: ended. >..........s1: ended. > > >Source: >=3D=3D=3D=3D=3D=3D=3D > >import javax.jcr.Node; >import javax.jcr.NodeIterator; >import javax.jcr.Property; >import javax.jcr.PropertyIterator; >import javax.jcr.Repository; >import javax.jcr.RepositoryException; >import javax.jcr.Session; >import javax.jcr.SimpleCredentials; >import javax.jcr.Value; > >import org.apache.jackrabbit.core.RepositoryImpl; >import org.apache.jackrabbit.core.config.RepositoryConfig; > >public class JackRabbitTest { > > public static void performanceTest(Repository r) { > try { > for( int i=3D0; i<5; i++ ) { > Session session =3D r.login(new=20 > SimpleCredentials("admin", "".toCharArray()), null); > TestSession ts =3D new TestSession("s" += i,=20 > session); > Thread th =3D new Thread(ts); > th.start(); > Thread.sleep(100); > } > } catch (Exception e){ > System.err.println(e); > e.printStackTrace(); > } > } > > public static void main(String[] args) { > try { > String configFile =3D "repository.xml"; > String repHomeDir =3D "repository.home"; > > RepositoryConfig c =3D=20 > RepositoryConfig.create(configFile, repHomeDir); > Repository r =3D RepositoryImpl.create(c); > > performanceTest(r); > } catch (Exception e){ > System.err.println(e); > e.printStackTrace(); > } > } >} >------------ >import java.util.Random; > >import javax.jcr.ItemNotFoundException; >import javax.jcr.Node; >import javax.jcr.Session; >import javax.jcr.lock.Lock; > >import org.apache.jackrabbit.value.StringValue; > >public class TestSession implements Runnable { > > Session session; > String identity; > Random r; > > TestSession( String identity, Session s ) { > this.session =3D s; > this.identity =3D identity; > r =3D new Random(); > } > > private void debug(String msg) { > System.out.println( identity + ": " + msg); > } > > private void sleep() { > long l =3D r.nextInt(900)+200; > try { > Thread.sleep( l ); > } catch(InterruptedException ie) { > } > } > > public void run() { > > debug("started."); > String state =3D ""; > try { > Node rn =3D session.getRootNode(); > > state =3D "searching testnode"; > if (rn.hasNode("testnode-" + identity)) { > try { > state =3D "removing testnode"; > rn.getNode("testnode-" += identity).remove(); > session.save(); > sleep(); > } catch(ItemNotFoundException infe) { > debug("error while removing testnode " += =20 > identity); > infe.printStackTrace(); > } > } > state =3D "adding testnode"; > Node n =3D rn.addNode("testnode-" + identity ,=20 > "nt:unstructured"); > > session.save(); > state =3D "setting property"; > n.setProperty("testprop", new StringValue("Hello=20 > World!")); > session.save(); > sleep(); > > for(int i=3D0; i<100; i++) { > state =3D "adding subnode " + i; > n.addNode("x" + i, "nt:unstructured"); > state =3D "adding property to subnode " + i; > n.setProperty("testprop","xxx"); > if(i%10=3D=3D0) { > state =3D "saving pending subnodes"; > session.save(); > System.out.print("."); > } > sleep(); > } > session.save(); > > } catch( Exception e) { > debug("Exception: " + state); > e.printStackTrace(); > } finally { > session.logout(); > } > > debug("ended."); > } >} > >