Pradeep,

This sounds like a reasonable approach.

If you can use the directory itself rather than a separate ID for the 
directory, I think that would be simpler, since the directory is already a sort 
of ID grouping all information below it. Note you can query by directory via 
cts:directory-query() to use the directory as a query mechanism without needing 
an ID separate from the directory.

Another possible solution is to store the directory ID in the properties 
fragment of the actual documents. This would duplicate the data, but still 
allow most functionality.

These are only possible other approaches. Your solution seems to work, and I'm 
sure matches your design.

Best,
Damon

From: [email protected] 
[mailto:[email protected]] On Behalf Of Pradeep Maddireddy
Sent: Monday, April 22, 2013 10:52 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Try Catch Conflicting updates

Hi Damon,

We have a function data:crtdoc-and-directories in a library module which would
i) insert a document into MLS and
ii) then to attach an unqiue id to every directory.To attach an id to every 
directory we are creating a document with the directory name and setting it a 
property.

Let's say the function receives an uri "/root/fldr1/fldr11/abc.xml"  the 
function creates the document with this name and then creates the following 
documents as well
/root/
/root/fldr1/
/root/fldr1/fldr11/  and then sets a property so that every directory can have 
an unique id. The problem is when we are invoking this function from a 
different  module iteratively. for example


for $uri in  ( "/root/fldr1/fldr11/abc.xml"  , "/root/fldr1/fldr11/def.xml" )

return data:crtdoc-and-directories( $uri )

In the above scenario it would try to create same set of documents and update 
the same property which is throwing conflicting errors. All we need is assign a 
unique id to every directory. So I thought of using try catch and ignore the 
update if it errors out as we already have assigned one.

For now I have modified the function to just return the directories without 
creating and then choose distinct directories and then start assigning the id 
values in the invoking module itself. As this function was used in multiple 
places in my project I was hesitating to make this change but had no other 
option.


Thanks
Pradeep Maddireddy

On Mon, Apr 22, 2013 at 6:06 PM, Damon Feldman 
<[email protected]<mailto:[email protected]>> wrote:
Pradeep,

I see that behavior too (thanks for the excellent, self-contained example code).

I can only assume that recent versions of MarkLogic added some conflict 
checking that I was not aware of, which occurs before the transaction commit, 
but that it is not as universal as the checks the commit logic is able to do. 
Someone on the list from MarkLogic Engineering may be able to correct me if I'm 
wrong.

If you know the problem is with multiple properties, Geert's suggestion of 
putting them all in a map, keyed by URI with the required property for each 
URI, should work.

If you can tell us the nature of the problem, there may be other solutions as 
well.

Damon


From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Pradeep Maddireddy
Sent: Monday, April 22, 2013 5:28 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Try Catch Conflicting updates

Hi Damon,

Thank you. Just one more observation

The first query seems to work fine, in every iteration we insert the same 
document and update its property try catch seems to work fine. But in the query 
two we insert the document only once and update the property twice throws  
conflicting updates error.
(: 
---------------------------------------------------------------------------------------------------------
 :)
(: query one  :)
let $uri := "/root/abc.xml"
for $prop in 1 to 2
return
    try
    {
        xdmp:document-insert($uri,<root/>),
        xdmp:document-set-property($uri,<priority>{$prop}</priority>),
        "Successfuly updated property."
    }
    catch($err)
    {
        "Error updating property."
    }
(: 
---------------------------------------------------------------------------------------------------------
 :)
(: query two :)
let $uri := "/root/abc.xml"
let $_ := xdmp:document-insert($uri,<root/>)
for $prop in 1 to 2
return
try
{

xdmp:document-set-property($uri,<priority>{$prop}</priority>),
"Successfuly updated property."
}
catch($err)
{
"Error updating property."
}
(: 
---------------------------------------------------------------------------------------------------------
 :)

Thanks
Pradeep Maddireddy

On Fri, Apr 19, 2013 at 8:09 PM, Damon Feldman 
<[email protected]<mailto:[email protected]>> wrote:
Pradeep,

The commit of all updates from a transaction occurs after the XQuery is done 
running, including the try/catch. So setting the properties did not trigger the 
conflict (or at least it is not detected) inside the try/catch. That code 
completes, then when the system actually processes the transaction commit after 
all code is done, it sees the same fragment being updated in inconsistent ways 
and raises the error.

So you need to look at your program logic to avoid the conflict. Can you 
describe what happens and what you are trying to accomplish at a high level?

Yours,
Damon

--
Damon Feldman
Sr. Principal Consultant, MarkLogic




From: 
[email protected]<mailto:[email protected]>
 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Pradeep Maddireddy
Sent: Friday, April 19, 2013 10:15 AM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] Try Catch Conflicting updates

Hi..!

Try catch doesn't seem to work with conflicting updates problem. I am trying to 
update the same document property in the same transaction so I used try catch 
so that the second update can be ignored but doesn't seem to work. Marklogic is 
still throwing an hard error even when I am using a try catch in the below case.
Is there anything wrong in the below block of code.

My actual situation isn't as straight forward so I cannot use alternate 
approaches.

try {
(
xdmp:document-set-property("/root/abc.xml",<priority>5</priority>),
xdmp:document-set-property("/root/abc.xml",<priority>6</priority>)
)
}
catch($err)
{
  "error"
}

Thanks
Pradeep Maddireddy

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general


_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general

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

Reply via email to