Hi Bob, To my knowledge a read lock (which is only applied in transactions that are marked as updating queries) will not prevent other transaction to perform an update. So then you would be better off with first updating some fixed other doc, which is synchronized for sure.
You will indeed have to put this in an eval to be able to call this multiple times in a single transaction, but you may also need to pass in the different-transaction option as well.. Kind regards, Geert > drs. G.P.H. (Geert) Josten Consultant Daidalos BV Hoekeindsehof 1-4 2665 JZ Bleiswijk T +31 (0)10 850 1200 F +31 (0)10 850 1199 mailto:[email protected] http://www.daidalos.nl/ KvK 27164984 P Please consider the environment before printing this mail. De informatie - verzonden in of met dit e-mailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. > From: [email protected] > [mailto:[email protected]] On Behalf Of > Bob Runstein > Sent: donderdag 15 april 2010 16:47 > To: [email protected] > Subject: [MarkLogic Dev General] RE: Unique Sequence Id > > Hi Geert, > > I've implemented this with a single document using eval: > declare function get-next-id() as xs:int { let $query := > "xquery version '1.0-ml'; let $uri := '/sequence' > let $nextId := > if (fn:doc-available($uri)) then > fn:data(fn:doc($uri)/nextId > else 1 > let $insert := xdmp:document-insert($uri, <nextId>{$nextId + > 1}</nextId>, xdmp:default-permissions()) return nextId" > > return xdmp:eval($query) > }; > > My expectation is that the /sequence document would be locked > when reading the nextId because the eval statement includes > an update. Am I mistaken in this? > > Bob > > -------------------------------------------------------------- > ---------------------- > > The most simplest way would be to have two documents. Perform > a dummy update on the first, read the second doc after that, > increment the number you got from the second, and update the > second doc with the new number. The dummy update will cause a > transaction long write lock on the first document, which > causes automatic synchronisation. You will need to do the > update first, as reading the second doc will not prevent it > being updated or read by others.. > > Kind regards, > Geert > > > _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
