Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created November 2, 2015 15:11
Show Gist options
  • Select an option

  • Save ableasdale/d7d682d3dcce2f6487df to your computer and use it in GitHub Desktop.

Select an option

Save ableasdale/d7d682d3dcce2f6487df to your computer and use it in GitHub Desktop.
A pattern for configuring / removing replica forests in one update
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
(: Global Variables :)
declare variable $CONFIG as element(configuration) := admin:get-configuration();
declare variable $MASTER as xs:string := "MAIN";
declare variable $REPLICA as xs:string := "REPLICA";
declare variable $TOTAL-FORESTS as xs:integer := 16;
(: Local Module Functions :)
(: Add replica forests for master forests across the cluster :)
declare function local:add-replicas($i){
xdmp:set($CONFIG, admin:forest-add-replica($CONFIG, xdmp:forest(fn:concat($MASTER,'-',$i)), xdmp:forest(fn:concat($REPLICA,'-',$i))))
};
(: Remove replica forests for master across the cluster :)
declare function local:remove-replicas($i){
xdmp:set($CONFIG, admin:forest-remove-replica($CONFIG, xdmp:forest(fn:concat($MASTER,'-',$i)), xdmp:forest(fn:concat($REPLICA,'-',$i))))
};
(: Module "main" below :)
(: Uncomment the three lines below to remove replica forests from masters
for $i in (1 to $TOTAL-FORESTS) return local:remove-replicas($i),
xdmp:log("***** Removing replica forests *****"),
admin:save-configuration($CONFIG)
:)
(: Uncomment the three lines below to add replica forests to masters
for $i in (1 to $TOTAL-FORESTS) return local:add-replicas($i),
xdmp:log("***** Adding replica forests *****"),
admin:save-configuration($CONFIG)
:)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment