Hi Raghu,

The best way to ensure concurrent threads not creating a file at the same uri, 
*is* by using locks. Here is code and some explanation on how to best do that: 
http://registry.demo.marklogic.com/package/ml-unique

Cheers,
Geert

From: 
<[email protected]<mailto:[email protected]>>
 on behalf of Raghu 
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Tuesday, May 23, 2017 at 8:54 PM
To: General MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] concurrent invocation of xquery ending up with 
duplicate writes

All,

I have a reader.xqy, which does only read operation and does not write to the 
forest, except for one doc insert. I don't want that reader query to obtain 
lock on all referenced documents, so I move that document insert logic to a 
seperate writer.xqy and invoke it from reader.xqy.

My current logic is

if random-xml already exists

DO NOTHING

else INSERT RANDOM-XML

The problem I am facing is,

when I invoke the reader xqy using multiple threads concurrently, I am ending 
up with duplicate writer xmls even though I have validations in place. How do I 
make sure that even if the reader xml is invoked concurrently by several 
threads, only one of the invocation has to insert an xml?


Note: I need that random-xml inserted, before the reader.xqy completes 
execution and the URI of the random-xml involves dynamically generated ID and 
NOT a constant URI.

Thanks in advance
Raghu

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to