
xdmp:transaction-locks( [$host-id as xs:unsignedLong], [$txn-id as xs:unsignedLong] ) as element(transaction-locks)
Returns all URIs currently locked for read or write by a transaction. If the transaction is waiting to lock a URI, that URI is returned too.
http://marklogic.com/xdmp/privileges/my-transaction-locks
http://marklogic.com/xdmp/privileges/any-transaction-locks
let $document1:= fn:doc("doc1.xml")
let $document2:= fn:doc("doc2.xml")
let $update1 := xdmp:document-insert("doc3.xml",<doc/>)
let $update2 := xdmp:document-insert("doc4.xml",<doc/>)
return xdmp:transaction-locks()
=>
<transaction-locks xmlns="http://marklogic.com/xdmp/status/host">
  <read>doc1.xml</read>
  <read>doc2.xml</read>
  <write>doc3.xml</write>
  <write>doc4.xml</write>
</transaction-locks>
let $serialize := xdmp:lock-for-update("lockname")
return xdmp:transaction-locks()
=>
<transaction-locks xmlns="http://marklogic.com/xdmp/status/host">
  <write>lockname</write>
</transaction-locks>
let $_ := xdmp:spawn-function(
  function () {
    xdmp:set-transaction-name("holder"),
    xdmp:lock-for-update("lock-uri"),
    xdmp:sleep(1000)},
  <options xmlns="xdmp:eval">
     <update>auto</update>
     <commit>auto</commit>
  </options>)
let $_ := xdmp:spawn-function(
  function () {
    xdmp:set-transaction-name("waiter"),
    xdmp:lock-for-update("lock-uri")},
  <options xmlns="xdmp:eval">
     <update>auto</update>
     <commit>auto</commit>
  </options>)
let $hostid := xdmp:host()
let $txns := xdmp:host-status($hostid)/*:transactions
let $holder := $txns/*:transaction[*:transaction-name = "holder"]/*:transaction-id
let $waiter := $txns/*:transaction[*:transaction-name = "waiter"]/*:transaction-id
return
  (xdmp:transaction-locks($hostid,$holder),
   xdmp:transaction-locks($hostid,$waiter))
=>
(<transaction-locks xmlns="http://marklogic.com/xdmp/status/host">
   <write>lock-uri</write>
 </transaction-locks>,
 <transaction-locks xmlns="http://marklogic.com/xdmp/status/host">
   <write>lock-uri</write>
   <waiting>lock-uri</waiting>
 </transaction-locks>)