Loading TOC...

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">
    <transaction-mode>update-auto-commit</transaction-mode>
  </options>)
let $_ := xdmp:spawn-function(
  function () {
    xdmp:set-transaction-name("waiter"),
    xdmp:lock-for-update("lock-uri")},
  <options xmlns="xdmp:eval">
    <transaction-mode>update-auto-commit</transaction-mode>
  </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.

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.
  • error from console, it removed in ML9? [1.0-ml] XDMP-UNDFUN: (err:XPST0017) Undefined function xdmp:transaction-locks()
    • You might want to check for a typo or confirm you're passing the correct type and number of parameters This function works fine in my environment.
      • this 「xdmp:transaction-locks()」 work on 9.0-1.1/linux not work on 8.0-5.8/linux not work on 9.0-20160909/win10
        • Then I recommend you contact MarkLogic Support. The comments section of the documentation is not the best place to debug or report product problems.