使用具有范围分区的Admin API创建林时出错。为创建的新林引发错误ADMIN-DUPLICATENAME。
我正在使用Admin API,我每周创建两个目录林,附加这些目录林,然后分配范围边界(上下限)。创建第一个目录林后,即使我的目录林不存在,它也会给出ADMIN-DUPLICATENAME错误。请提出我在这里想念的东西。我正在使用范围分区作为分配策略,并使用了该逻辑可在其上起作用且锁定已关闭的日期范围索引。
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
let $config := admin:get-configuration()
let $year := fn:year-from-date(fn:current-date())
let $database := "test"
let $database-id := xdmp:database($database)
let $forest-name := ()
for $each in (1 to 2)
let $initial-lower-bound := xs:date(fn:concat($year,"-06-01"))
let $initial-upper-bound := xs:date($initial-lower-bound) + xs:dayTimeDuration("P7D")
let $result :=
(:Forest 1 Setup:)
let $forest-name-1 := fn:concat("WK_",$each,"_",$year,"_TEST_FIN-","01")
let $spec-forest-1 := admin:forest-create($config, $forest-name-1 , xdmp:host(), ())
let $_ := admin:save-configuration-without-restart($spec-forest-1)
let $attatch-forest1 := admin:save-configuration-without-restart(admin:database-attach-forest($config, $database-id, xdmp:forest($forest-name-1) ))
let $bound-forest1 := admin:save-configuration-without-restart(admin:forest-set-range-policy-range($config, xdmp:forest($forest-name-1), $initial-lower-bound, $initial-upper-bound))
(:Forest 2 Setup:)
let $forest-name-2 := fn:concat("WK_",$each,"_",$year,"_TEST_FIN-","02")
let $spec-forest-2 := admin:forest-create($config, $forest-name-2 , xdmp:host(), ())
let $_ := admin:save-configuration-without-restart($spec-forest-2)
let $attatch-forest2 := admin:save-configuration-without-restart(admin:database-attach-forest($config, $database-id, xdmp:forest($forest-name-2) ))
let $bound-forest2 := admin:save-configuration-without-restart(admin:forest-set-range-policy-range($config, xdmp:forest($forest-name-2), $initial-lower-bound, $initial-upper-bound))
(:Populate Forest Name array:)
let $forest_Name := (fn:insert-before($forest-name, 1, $forest-name-1), fn:insert-before($forest-name, 1, $forest-name-2))
let $_ := xdmp:set($initial-lower-bound,$initial-upper-bound)
return $forest-name
return $result
有趣的是,如果我使用try catch块并捕获错误ADMIN-DUPLICATENAME的异常,它将创建目录林名称并完成代码的逻辑而不会退出。请提出为什么我会看到这个。我什至使用admin:save-configuration,但问题仍然存在。我正在通过qconsole上的http服务器在9.0-9.1上针对Test数据库运行它。
答案 0 :(得分:1)
您具有XQuery语句来创建每个林,但是您正在循环调用它们。您还比需要更多地保存配置。
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
let $config := admin:get-configuration()
let $year := fn:year-from-date(fn:current-date())
let $database := "test"
let $database-id := xdmp:database($database)
let $forest-name := ()
let $initial-lower-bound := xs:date(fn:concat($year,"-06-01"))
let $initial-upper-bound := xs:date($initial-lower-bound) + xs:dayTimeDuration("P7D")
(:Forest 1 Setup:)
let $forest-name-1 := fn:concat("WK_",$each,"_",$year,"_TEST_FIN-","01")
let $config := admin:forest-create($config, $forest-name-1 , xdmp:host(), ())
let $config := admin:database-attach-forest($config, $database-id, xdmp:forest($forest-name-1) )
let $config := admin:forest-set-range-policy-range($config, xdmp:forest($forest-name-1), $initial-lower-bound, $initial-upper-bound)
(:Forest 2 Setup:)
let $forest-name-2 := fn:concat("WK_",$each,"_",$year,"_TEST_FIN-","02")
let $config := admin:forest-create($config, $forest-name-2 , xdmp:host(), ())
let $config := admin:database-attach-forest($config, $database-id, xdmp:forest($forest-name-2) )
let $config := admin:forest-set-range-policy-range($config, xdmp:forest($forest-name-2), $initial-lower-bound, $initial-upper-bound)
(:Populate Forest Name array:)
let $forest_Name := (fn:insert-before($forest-name, 1, $forest-name-1), fn:insert-before($forest-name, 1, $forest-name-2))
let $_ := xdmp:set($initial-lower-bound,$initial-upper-bound)
let $_ := xdmp:save-configuration-without-restart($config)
return $forest-name
答案 1 :(得分:1)
请尝试使用此代码。确保将$ number-of-forests更新为希望创建的数量。
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare function local:save-config($config){
xdmp:invoke-function(
function() { admin:save-configuration-without-restart($config) },
<options xmlns="xdmp:eval">
<update>true</update>
</options>)
};
let $config := admin:get-configuration()
let $year := fn:year-from-date(fn:current-date())
let $database := "test"
let $number-of-forests := 4
let $database-id := xdmp:database($database)
(:Establish initial upper and lower bounds for range index:)
let $initial-lower-bound := xs:date(fn:concat($year,"-06-01"))
let $initial-upper-bound := xs:date($initial-lower-bound) + xs:dayTimeDuration("P7D")
(:IMPORTANT: Check to ensure selected database is not the same as one being updated:)
let $check :=
if(xdmp:database() eq $database-id) then
fn:error(xs:QName("OOPS"), "The selected database in the pulldown menu is same as one being updated. Select a different database from the pulldown menu and try again." , ())
else ()
(:Construct Forest Names and store in sequence:)
let $forest-names := (1 to $number-of-forests) ! fn:concat("WK_",.,"_",$year,"_TEST_FIN-","01")
(:Loop over Forest names and create forests:)
let $create-forests :=
for $forest-name in $forest-names
return xdmp:set($config, admin:forest-create($config, $forest-name, xdmp:host(), ()))
(:Save Forests in separate transaction:)
let $save-config := local:save-config($config)
let $config := admin:get-configuration()
(:Attach Forests to Database while also specifying range assignment policy for each forest:)
let $attach-forests :=
for $forest-name in $forest-names
let $_ := xdmp:set($config, admin:forest-set-range-policy-range($config, xdmp:forest($forest-name), $initial-lower-bound, $initial-upper-bound))
let $_ := xdmp:set($config, admin:database-attach-forest($config, $database-id, xdmp:forest($forest-name)))
return
(
xdmp:set($initial-lower-bound,$initial-upper-bound),
xdmp:set($initial-upper-bound, xs:date($initial-upper-bound) + xs:dayTimeDuration("P7D"))
)
(:Save database configuration with attached forests in separate transaction:)
let $save-config := local:save-config($config)
let $config := admin:get-configuration()
(:For each forest, create a duplicate:)
let $dup-forests :=
for $name in admin:database-get-attached-forests($config, $database-id) ! xdmp:forest-name(.)
let $dup-name := fn:substring-before($name, "-") || "-02"
where fn:starts-with($name, "WK_")
return xdmp:set($config, admin:forest-copy($config, xdmp:forest($name), $dup-name,()))
(:Save duplicate forests configuration:)
let $save-config := local:save-config($config)
let $config := admin:get-configuration()
(:Attach duplicate forests:)
let $attach-duplicate-forests :=
for $name in admin:database-get-attached-forests($config, $database-id) ! xdmp:forest-name(.)
let $dup-name := fn:substring-before($name, "-") || "-02"
where fn:starts-with($name, "WK_")
return xdmp:set($config, admin:database-attach-forest($config, $database-id, xdmp:forest($dup-name)))
(:Save duplicate forests attachment configuration:)
let $save-config := local:save-config($config)
return admin:database-get-attached-forests($config, $database-id) ! xdmp:forest-name(.)