Skip to content

Instantly share code, notes, and snippets.

View ableasdale's full-sized avatar

Alex Bleasdale ableasdale

View GitHub Profile
@ableasdale
ableasdale / Main.java
Created April 30, 2013 14:45
"read-after-write" Cluster XCC Example
package com.marklogic;
import com.marklogic.xcc.*;
import java.net.URI;
import java.util.UUID;
public class Main {
public static void main(String[] args) throws Exception {
@ableasdale
ableasdale / gist:5502456
Created May 2, 2013 14:10
XCC/J Document Delete Template
import com.marklogic.xcc.*;
import com.marklogic.xcc.exceptions.RequestException;
import java.net.URI;
public class XccDeleteModule {
public static void main(String[] args){
System.out.println("XccDeleteModule.main: start");
ContentSource cs = null;
@ableasdale
ableasdale / gist:5502634
Created May 2, 2013 14:37
Try/Catch with both a submitRequest() and a commit()
try {
s.submitRequest(r);
s.commit();
} catch (RequestException e) {
@ableasdale
ableasdale / gist:5502736
Created May 2, 2013 14:50
Get the TransactionMode in XCC/J
System.out.println(s.getTransactionMode());
@ableasdale
ableasdale / gist:5502748
Created May 2, 2013 14:52
Setting the TransactionMode for an UPDATE
s.setTransactionMode(Session.TransactionMode.UPDATE);
@ableasdale
ableasdale / gist:5878567
Created June 27, 2013 17:36
Resolve hostnames of all hosts in the cluster
xquery version "1.0-ml";
import module namespace admin = 'http://marklogic.com/xdmp/admin' at '/MarkLogic/admin.xqy';
for $h in xdmp:hosts()
return xdmp:host-name($h)
@ableasdale
ableasdale / gist:5878835
Created June 27, 2013 18:08
Hit an endpoint on each host in a cluster
xquery version "1.0-ml";
import module namespace admin = 'http://marklogic.com/xdmp/admin' at '/MarkLogic/admin.xqy';
declare variable $USER as xs:string := "q";
declare variable $PASS as xs:string := "q";
declare variable $PORT as xs:string := "9999";
declare variable $ENDPOINT as xs:string := "/endpoint.xqy";
declare function local:generate-cluster-endpoints() as xs:string* {
@ableasdale
ableasdale / gist:5899947
Created July 1, 2013 10:56
Extract a sequence of forest ids local to a given host
xquery version "1.0-ml";
declare namespace fs="http://marklogic.com/xdmp/status/forest";
declare variable $DATABASE as xs:string := "YOUR-DATABASE-HERE";
declare function local:get-host-forest-ids() as xs:unsignedLong+ {
for $f in xdmp:database-forests(xdmp:database($DATABASE))
where xdmp:forest-status($f)/fs:host-id eq xdmp:host()
return
$f
@ableasdale
ableasdale / gist:5960481
Last active April 10, 2019 17:00
Bash Script for extracting information from ErrorLogs
#!/bin/bash
# default argument check
if [[ -z $1 ]]; then
echo Usage: ./report.sh \[MarkLogic ErrorLog File\]
echo e.g. ./report.sh ErrorLog.txt
exit 1
fi
DOC=$1
@ableasdale
ableasdale / flash-backup.xqy
Last active December 22, 2015 17:49
Set Forests to Flash Backup Mode
xquery version "1.0-ml";
(:~
: This module allows for the convenient setting of all forests in a given database into a
: specific mode for common management operations. These include:
: <ul>
: <li>Flash backup - Forests can be quiesced so a safe "flash backup" of the filesystem can take place</li>
: <li>All - The "default" for newly created forests; allows both inserts and updates to take place for fragments in
: all forests in that database</li>
: <li>Read only - Places forest in a state where documents can be read from the forest but not updated or removed</li>