Loading TOC...

MarkLogic 12 EA 1 Product Documentation
xdmp:transaction-locks

xdmp:transaction-locks(
   [$host-id as xs:unsignedLong],
   [$txn-id as xs:unsignedLong]
) as element(transaction-locks)

Summary

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.

Parameters
host-id An optional host ID. If omitted, the local App Server host is assumed. If a host ID is specified, then a transaction ID should also be specified.
txn-id An optional transaction ID. If omitted, the current transaction is assumed. If a transaction ID is specified, then a host ID should also be specified.

Required Privileges

http://marklogic.com/xdmp/privileges/my-transaction-locks

http://marklogic.com/xdmp/privileges/any-transaction-locks

See Also

Example

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>

Example

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>

Example

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)/&#42;:transactions
let $holder := $txns/&#42;:transaction[*:transaction-name = "holder"]/&#42;:transaction-id
let $waiter := $txns/&#42;:transaction[*:transaction-name = "waiter"]/&#42;: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>)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.