I have a function that I wrote for generation of 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 from a qconsole window using the following test code:
let res := util:generate-instrument-Id( 1 )
return fn:error( fn:QName("test", $res ) )
i.e. it executes in another transaction context and updates the document correctly. However, when I try to call the same function from a 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 cleaned up every other piece of code from the service interface to isolate the problem and still receive the same error message.
So here are my questions:
- Under what conditions this error is issued?
- I am sure there are no locks are held on this document (or directory it is put under) by any other process, so what might trigger such a false alarm?
- Since it works from qconsole, I assume if I replicate what it does when executing programs I could solve this problem, as well. Any documentation on how qconsole executes programs?
Thanks a lot
K.
PS: I use MarkLogic 9 on a windows server