Marklogic管理API在创建林时出错

Marklogic管理API在创建林时出错,marklogic,marklogic-9,Marklogic,Marklogic 9,使用带范围分区的管理API创建林时出错。为创建的新林抛出错误ADMIN-DUPLICATENAME 我使用管理API,每周创建两个林,附加这些林,然后分配范围界限(上限和下限)。创建第一个林后,它会给出一个ADMIN-DUPLICATENAME错误,即使我的林不存在。请说明我在这里遗漏了什么。我使用范围分区作为分配策略,并使用此逻辑工作的日期范围索引,锁定处于关闭状态 xquery version "1.0-ml"; import module namespace admin = "http:/

使用带范围分区的管理API创建林时出错。为创建的新林抛出错误ADMIN-DUPLICATENAME

我使用管理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配置,但问题仍然存在。我在9.0-9.1上使用http server over qconsole对测试数据库运行它。

您有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

您有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

请尝试此代码。确保将$number森林更新为您希望创建的数量


xquery版本“1.0-ml”;
导入模块命名空间管理=”http://marklogic.com/xdmp/admin“在“/MarkLogic/admin.xqy”;
声明函数本地:保存配置($config){
xdmp:调用函数(
function(){admin:保存配置而不重新启动($config)},
真的
)
};
让$config:=admin:get-configuration()
设$year:=fn:year from date(fn:current-date())
让$database:=“测试”
让$number森林:=4
让$database id:=xdmp:database($database)
(:建立范围索引的初始上限和下限:)
let$initial lower bound:=xs:date(fn:concat($year,“-06-01”))
设$initial上限:=xs:date($initial下限)+xs:dayTimeDuration(“P7D”)
(:要点:检查以确保所选数据库与正在更新的数据库不同:)
让我们检查一下:=
如果是(xdmp:database()eq$database id),则
fn:错误(xs:QName(“OOPS”),“下拉菜单中选定的数据库与正在更新的数据库相同。请从下拉菜单中选择其他数据库,然后重试。”,())
else()
(:构造林名称并按顺序存储:)
让$FREST NAME:=(1到$FREST数量)!fn:concat(“工作日”、“年”、“年”、“测试日”、“01”)
(:循环林名称并创建林:)
让$createforests:=
对于$forest name中的$forest name
返回xdmp:set($config,admin:forest create($config,$forest name,xdmp:host(),())
(:在单独事务中保存林:)
让$save config:=local:save config($config)
让$config:=admin:get-configuration()
(:将林附加到数据库,同时为每个林指定范围分配策略:)
让我们看看森林:=
对于$forest name中的$forest name
让$\uxdmp:set($config,admin:forest set-range策略范围($config,xdmp:forest($forest-name),$initial-lower-bound,$initial-upper-bound))
让$xdmp:set($config,admin:database-attach-forest($config,$database-id,xdmp:forest($forest-name)))
返回
(
xdmp:set($initial lower bound,$initial upper bound),
xdmp:set($初始上限,xs:date($初始上限)+xs:dayTimeDuration(“P7D”))
)
(:在单独的事务中保存带有附加林的数据库配置:)
让$save config:=local:save config($config)
让$config:=admin:get-configuration()
(:为每个林创建一个副本:)
让$dup森林:=
对于admin:database中的$name,获取附加林($config,$database id)!xdmp:林名称(.)
让$dup name:=fn:substring在($name,“-”)| |“-02”之前
其中fn:以($name,“WK_u2;”)开头
返回xdmp:set($config,admin:forest copy($config,xdmp:forest($name),$dup name,())
(:保存重复林配置:)
让$save config:=local:save config($config)
让$config:=admin:get-configuration()
(:附加重复林:)
让$附加重复的林:=
对于admin:database中的$name,获取附加林($config,$database id)!xdmp:林名称(.)
让$dup name:=fn:substring在($name,“-”)| |“-02”之前
其中fn:以($name,“WK_u2;”)开头
返回xdmp:set($config,admin:database-attach-forest($config,$database-id,xdmp:forest($dup-name)))
(:保存重复的林附件配置:)
让$save config:=local:save config($config)
return admin:database get attached forests($config,$database id)!xdmp:林名称(.)

请尝试此代码。确保将$number森林更新为您希望创建的数量


xquery版本“1.0-ml”;
导入模块命名空间管理=”http://marklogic.com/xdmp/admin“在“/MarkLogic/admin.xqy”;
声明函数本地:保存配置($config){
xdmp:调用函数(
function(){admin:保存配置而不重新启动($config)},
真的
)
};
让$config:=admin:get-configuration()
设$year:=fn:year from date(fn:current-date())
让$database:=“测试”
让$number森林:=4
让$database id:=xdmp:database($database)
(:建立范围索引的初始上限和下限:)
let$initial lower bound:=xs:date(fn:concat($year,“-06-01”))
设$initial上限:=xs:date($initial下限)+xs:dayTimeDuration(“P7D”)
(:要点:检查以确保所选数据库与正在更新的数据库不同:)
让我们检查一下:=
如果是(xdmp:database()eq$database id),则
fn:错误(xs:QName(“OOPS”),“下拉菜单中选定的数据库与正在更新的数据库相同。请从下拉菜单中选择其他数据库,然后重试。”,())
else()
(:构造林名称并按顺序存储:)
让$FREST NAME:=(1到$FREST数量)!fn:concat(“工作日”、“年”、“年”、“测试日”、“01”)
(:循环林名称并创建林:)
让美元创造价值