I have a function that I wrote to generate a sequential number. The function is as follows:
declare function generate-instrument-Id( $cnt as xs:int? )
as xs:int {
let $count := if( $cnt and $cnt > 0 ) then $cnt else 1
let $url := '/private/instrumentId-Sequence.xml'
(: this redirection is needed to write id in another
transaction context :)
return xdmp:invoke-function( function() {
let $id := fn:doc( $url )/instrument/@nextId
let $_ := xdmp:node-replace( $id
, attribute nextId { $id + $count } )
return $id
}
)
};
The function works fine in the qconsole window using the following test code:
let res := util:generate-instrument-Id( 1 )
return fn:error( fn:QName("test", $res ) )
i.e. it runs in a different transaction context and correctly updates the document. However, when I try to call the same function from the REST service, it returns the following error message:
XDMP-LOCKED: xdmp:node-replace(fn:doc("/private/instrumentId-Sequence.xml")/instrument/@nextId, attribute{fn:QName("","nextId")}{"1228"}) -- Document or Directory is locked
Please note that I cleared every part of the code from the service interface in order to isolate the problem, and still get the same error message.
So here are my questions:
- In what conditions is this error issued?
- I am sure that no other locks are stored in this document (or the directory in which it is placed), so what can cause such a false signal?
- qconsole, , , , . , qconsole ?
.
PS: MarkLogic 9 Windows