Reputation: 1086
Getting XDMP-CONFLICTINGUPDATES
while trying to execute the following statements:
(dls:document-update($uri,$content,"Main Document Updated",fn:true(),xdmp:default-permissions(),$content-collection),
dls:document-checkin($uri, fn:true()),
dls:document-update($sub-uri,$sub-content,"sub Document Updated",fn:true(),xdmp:default-permissions(),$content-sub-collection),
dls:document-checkin($sub-uri, fn:true()),
cin:update-version ($sub-uri))
declare function cin:update-version ($sub-uri){
let $id := xs:int(fn:doc($sub-uri)//id)
return
xdmp:node-replace(fn:doc($sub-uri)//id,element id {fn:sum(($id,1))})
};
Little confused with the transaction rule for multi statements transaction. As the lock on the document is already released. why should it have any problem in doing node replace on it?
Upvotes: 0
Views: 923
Reputation: 7842
The sample code won't run as written because of syntax errors: there are missing variables and there is a function after the expression body. But looking past that, there is nothing here to suggest a multi-statement transaction. Instead this looks like a single statement, and so the multiple updates to $uri
conflict with each other. The call to dls:document-update
updates $uri
and then dls:document-checkin
tries to update the same document in the same transaction, causing a conflict. The same logic applies to $sub-uri
. In the docs, http://docs.marklogic.com/dls:document-update notes that "This function must be called in a separate transaction from the dls:document-checkout and dls:document-checkin".
MarkLogic transactions behave differently than you might expect, because XQuery is not an imperative or procedural language. Try reading up on transactions at http://docs.marklogic.com/guide/app-dev/transactions
In most cases I prefer to write separate transactions as separate requests, but here is the first part of your query written using semicolons to separate transactions. You might try rewriting the same code in xdmp:commit
style, to understand the difference.
(: multiple statements with semicolons :)
(: statement 1 :)
import module namespace dls="http://marklogic.com/xdmp/dls"
at "/MarkLogic/dls.xqy";
declare variable $content := <test>content</test>;
declare variable $content-collection := "content";
declare variable $uri := "test";
dls:document-update(
$uri,
$content,
"Main Document Updated",
fn:true(),
xdmp:default-permissions(),
$content-collection) ;
(: statement 2 :)
import module namespace dls="http://marklogic.com/xdmp/dls"
at "/MarkLogic/dls.xqy";
declare variable $uri := "test";
dls:document-checkin($uri, fn:true())
Upvotes: 2