To get the total size of all forests that are tied to a specific database

I am trying to get the total size of all forests that are tied to a specific database.

Using the code below, I have the size of all individual forests, but am stuck on how to achieve a solution:

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) 
+5
source share
2 answers

I think you are looking for something like:

 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 

NTN!

+5
source

It's better to call xdmp: forest-status () with a sequence of forest identifiers, rather than creating a bunch of separate calls, the work is done in parallel.

 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(.), " ") 
+5
source

Source: https://habr.com/ru/post/1244334/


All Articles