Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / pki-insert.xqy
Created August 14, 2018 17:13
MarkLogic: Insert Trusted Certificate
xquery version "1.0-ml";
import module namespace pki = "http://marklogic.com/xdmp/pki" at "/MarkLogic/pki.xqy";
pki:insert-trusted-certificates(
xdmp:document-get("/tmp/rootca.cer",
<options xmlns="xdmp:document-get">
<format>text</format>
</options>)
)
@ableasdale
ableasdale / create-master-and-replica-forests-for-3-node-cluster.xqy
Created July 5, 2018 13:41
MarkLogic: Quickly create a group of master and replica forests on a MarkLogic 3-node cluster
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
declare variable $dbname := "DATABASE-NAME_HERE";
declare variable $CONFIG := admin:get-configuration();
(
(: Create Master Forests - A :)
for $j in 1 to 5
@ableasdale
ableasdale / server-status.xqy
Created June 12, 2018 16:04
MarkLogic: get status of all requests for all application servers in a cluster
xquery version "1.0-ml";
declare namespace ss = "http://marklogic.com/xdmp/status/server";
for $host in xdmp:group-hosts(xdmp:groups())
for $server in xdmp:group-servers(xdmp:groups())
return
xdmp:server-status($host, $server)//ss:request-status
@ableasdale
ableasdale / clear-etc.xqy
Last active May 16, 2018 12:16
MarkLogic: Clearing the Expanded Tree Cache for all hosts in a cluster
xquery version "1.0-ml";
declare variable $USER as xs:string := "username";
declare variable $PASS as xs:string := "password";
declare variable $HOSTS as xs:unsignedLong+ := for $i in xdmp:groups() return xdmp:group-hosts($i);
declare variable $PORT as xs:unsignedLong := 8002;
declare variable $ENDPOINT as xs:string := "/v1/eval";
declare variable $PAYLOAD as xs:string := xdmp:quote("xquery=xdmp:expanded-tree-cache-clear()");
declare variable $OPTIONS as element() :=
@ableasdale
ableasdale / collection-listing.xqy
Created May 9, 2018 11:31
MarkLogic: list all collections for a given database along with a count of documents held in that collection
cts:collections() ! element collection-name {attribute count {xdmp:estimate(cts:search(doc(), cts:collection-query(.)))}, .}
@ableasdale
ableasdale / kb-541-5.xqy
Created April 25, 2018 13:47
MarkLogic: Get list of transaction locks
declare namespace server ="http://marklogic.com/xdmp/status/server";
declare variable $host := xdmp:host();
for $server in xdmp:servers()
return
for $request in xdmp:server-status($host,$server)//server:request-status
let $transaction-id := $request/server:transaction-id
let $start-time := $request/server:start-time/text()
order by $request/server:start-time ascending
@ableasdale
ableasdale / kb-541-4.xqy
Created April 25, 2018 13:42
MarkLogic: take a read lock on /thread-1-output.xml and will require an exclusive write lock on /thread-2-output.xml
let $read := fn:doc("/thread-1-output.xml")
return
xdmp:document-insert("/thread-2-output.xml",element root{"Thread 2 finished",element elapsed-time{xdmp:elapsed-time()}})
;
fn:doc("/thread-2-output.xml")
@ableasdale
ableasdale / kb-541-3.xqy
Created April 25, 2018 13:11
MarkLogic: Read a doc as a variable, perform and insert then retrieve the doc in a separate statement
let $read := fn:doc("/for-read-lock.xml")
return
xdmp:document-insert("/thread-2-output.xml",element root{"Thread 2 finished",element elapsed-time{xdmp:elapsed-time()}})
;
fn:doc("/thread-2-output.xml")
@ableasdale
ableasdale / kb-541-2.xqy
Created April 25, 2018 13:07
MarkLogic: read doc and perform an insert, then read another doc in a separate transaction
let $sleep-time-seconds := 20
let $read := fn:doc("/for-read-lock.xml")
let $_ := xdmp:document-insert("/thread-1-output.xml",element root{"Thread 1 finished"})
return
xdmp:sleep($sleep-time-seconds * 1000)
;
fn:doc("/thread-1-output.xml")
@ableasdale
ableasdale / kb-541-1.xqy
Created April 25, 2018 13:06
MarkLogic: Insert document to create read lock
xdmp:document-insert("/for-read-lock.xml",element root{});