API администратора Marklogic выдает ошибку при создании леса - PullRequest
0 голосов
/ 09 июня 2019

Ошибка при создании леса с использованием 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, но проблема все еще сохраняется.Я запускаю его на 9.0-9.1 для тестовой базы данных, используя http-сервер через qconsole.

Ответы [ 2 ]

1 голос
/ 12 июня 2019

Пожалуйста, попробуйте этот код. Убедитесь, что вы обновили $ number-of-forest на любое количество, которое вы хотите создать.


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(.)
1 голос
/ 10 июня 2019

У вас есть операторы 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
...