获取附加到特定数据库的所有森林的总大小
Posted
技术标签:
【中文标题】获取附加到特定数据库的所有森林的总大小【英文标题】:To get total size of all the forests which are attached to a particular database 【发布时间】:2016-06-16 09:16:05 【问题描述】:我正在尝试。
使用下面的代码,我得到了所有单个森林的大小,但坚持如何实现解决方案:
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)
【问题讨论】:
【参考方案1】:我认为您正在寻找类似的东西:
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!
【讨论】:
【参考方案2】:最好使用一系列森林 ID 调用 xdmp:forest-status(),而不是进行一堆单独的调用,以便并行完成工作。
xquery version "1.0-ml";
declare namespace fs = "http://marklogic.com/xdmp/status/forest";
let $include-replicas := fn:true()
let $db := xdmp:database("MyDatabase")
for $fs in xdmp:forest-status(xdmp:database-forests($db, $include-replicas))
return
fn:string-join(
( $fs/fs:forest-name, fn:sum($fs/fs:stands/fs:stand/fs:disk-size) ) ! fn:string(.),
" ")
【讨论】:
以上是关于获取附加到特定数据库的所有森林的总大小的主要内容,如果未能解决你的问题,请参考以下文章