【问题标题】: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)

【问题讨论】:

    标签: marklogic


    【解决方案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(.),
          " ")
      

      【讨论】:

        猜你喜欢
        • 2018-09-15
        • 1970-01-01
        • 1970-01-01
        • 2011-12-15
        • 1970-01-01
        • 2017-09-07
        • 2012-04-19
        • 2020-05-16
        • 1970-01-01
        相关资源
        最近更新 更多