获取附加到特定数据库的所有林的总大小

时间:2016-03-03 07:16:25

标签: marklogic

我正在尝试获取附加到特定数据库的所有林的总大小。

使用下面的代码我已经掌握了所有单独森林的大小,但仍坚持如何实现解决方案:

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
for $forests in xdmp:forest-status(xdmp:database-forests(xdmp:database($db-name)))
let $space := $forests//forest:device-space
let $f_name := $forests//forest:forest-name
for $stand in $forests//forest:stands
let $f_size := fn:sum($stand/forest:stand/forest:disk-size)

2 个答案:

答案 0 :(得分:5)

我认为你正在寻找类似的东西:

xquery version "1.0-ml";

declare namespace forest = "http://marklogic.com/xdmp/status/forest";

for $db-id in xdmp:databases()
let $db-name := xdmp:database-name($db-id)
let $db-size :=
  fn:sum(
    for $f-id in xdmp:database-forests($db-id)
    let $f-status := xdmp:forest-status($f-id)
    let $space := $f-status/forest:device-space
    let $f-name := $f-status/forest:forest-name
    let $f-size :=
      fn:sum(
        for $stand in $f-status/forest:stands/forest:stand
        let $stand-size := $stand/forest:disk-size/fn:data(.)
        return $stand-size
      )
    return $f-size
  )
order by $db-size descending
return $db-name || " = " || $db-size

HTH!

答案 1 :(得分:5)

最好使用一系列林ID来调用xdmp:forest-status(),而不是进行一系列单独的调用,以便并行完成工作。

I