[MarkLogic Dev General] Locking documents
Steve
steve.a.bennett at gmail.com
Wed Nov 5 01:21:15 PST 2008
I've got an XQuery module that has an if-then-else statement that
inserts data into a document. The basic flow is:
let $testNode := doc($docName)/doc/keywords/keyword[@value eq $testKeyword]
return
(
if (fn:exists($testNode)) then
(
(: Update the document by replacing the $testNode :)
)
else
(
(: Update the document by inserting a new node :)
)
)
I'm invoking this module using the Java XCC API. The Java program that
executes the request has multiple threads, all connecting as the same
MarkLogic user. The problem is that if two threads hit the
fn:exists(..) check at the same time then multiple nodes are inserted.
Is there any way that I can stop this happening by acquiring a lock on
the document before updating it? I've looked at the
xdmp:local-acquire(..) function, but that locks the document to the
current user, and as the threads are connecting as the same user, this
won't help the situation.
More information about the General
mailing list