This page was generated
January  28,  2016
4:03  AM
XQuery & XSLT Built-In & Modules Function Reference

Module: Flexible Replication

The Flexible Replication API module contains functions that allow you to write scripts to configure flexible replication.

The Flexible Replication API is installed as the following file:

install_dir/Modules/MarkLogic/flexrep.xqy

where install_dir is the directory in which MarkLogic Server is installed.

To use the flexrep.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

   import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
           at "/MarkLogic/flexrep.xqy"; 

The library uses the flexrep: namespace, which is not predefined in the server.

MarkLogic recommends enabling the URI Lexicon when using Flexible Replication; the URI lexicon will improve performance, especially when the database grows to a large number of documents.

Function Summary
flexrep:apply This function applies an update element to the current database.
flexrep:configuration-create This function creates a new replication configuration element.
flexrep:configuration-delete This function deletes a replication configuration.
flexrep:configuration-domain-ids This function returns the IDs of the domains configured for the Master database.
flexrep:configuration-get This function gets the replication configuration for a CPF domain.
flexrep:configuration-get-alerting-uri Get the alerting URI associated with a FlexRep configuraiton.
flexrep:configuration-get-domain-name This function returns the domain name associated with the specified replication configuration.
flexrep:configuration-get-id This function returns the ID of the replication configuration.
flexrep:configuration-insert This function inserts a replication configuration to the database.
flexrep:configuration-set-alerting-uri Set the alerting URI for a FlexRep configuration.
flexrep:configuration-target This function returns a specified target for a configuration, or throws an error if it does not exist.
flexrep:configuration-target-get-documents-per-batch This function returns the value of the documents-per-batch setting for the replication target.
flexrep:configuration-target-get-enabled This function returns true if the specified replication target is enabled, otherwise it returns false.
flexrep:configuration-target-get-filter-module This function returns the filter module used by the specified replcation target.
flexrep:configuration-target-get-filter-options This function retunrs the filter options configured for the specified replcation target.
flexrep:configuration-target-get-http-options This function returns the HTTP options configured for the specified replcation target.
flexrep:configuration-target-get-id This function returns the ID of the named replicaiton target.
flexrep:configuration-target-get-immediate-push Get the immediate push flag for a target.
flexrep:configuration-target-get-name This function returns the name of the specified target.
flexrep:configuration-target-get-replicate-cpf This function returns true if CFG replcation is enabled for the specified replication target, otherwise it returns false.
flexrep:configuration-target-get-retry-seconds-max This function sets the replication retry maximum value for the specified replication target.
flexrep:configuration-target-get-retry-seconds-min This function returns the value of the minimum retry setting for the replication target.
flexrep:configuration-target-get-urls This function returns the URLs for the specified targets.
flexrep:configuration-target-get-user-id Get the user ID associated with a target, if one exists.
flexrep:configuration-target-set-documents-per-batch This function sets the documents-per-batch value for the specified replication target.
flexrep:configuration-target-set-enabled This function enables or disables the specified replication target.
flexrep:configuration-target-set-filter-module This function sets the specified filter for this replication configuration.
flexrep:configuration-target-set-filter-options This function sets the specified filter options for this replication configuration.
flexrep:configuration-target-set-http-options This function sets the HTTP options on the specified replication target.
flexrep:configuration-target-set-immediate-push Set a target's "immediate push" flag.
flexrep:configuration-target-set-name This function sets the name of the specified replcation target.
flexrep:configuration-target-set-replicate-cpf This function enables and disables CPF replication.
flexrep:configuration-target-set-retry-seconds-max This function sets the replication retry maximum value for the specified replication target.
flexrep:configuration-target-set-retry-seconds-min This function sets the replication retry minimum value for the specified replication target.
flexrep:configuration-target-set-urls This function sets the URLs for the specified replication target.
flexrep:configuration-target-set-user-id Set a target's user-id.
flexrep:configuration-targets This function returns the replication targets for a configuration.
flexrep:configure-database This function creates any indexes needed for CPF based replication.
flexrep:database-needs-configuration This function checks the configuration of a database to see if it has all of the necessary indexes for Flexible Replication to work at its best.
flexrep:delete This function applies a delete element to the current database.
flexrep:do-pull This function is used by a Replica to pull updates from the Master.
flexrep:document-reset This function resets the URI status for all replication targets.
flexrep:document-status This function returns the flexrep:document-status element for the document at the specified URI in the specified domain.
flexrep:domain-alerting-uri Generate an alerting URI for a CPF domain.
flexrep:domain-status This function returns the replication status for the specified replicated CPF domain.
flexrep:domain-target-reset This function resets the URI status for the specified replication targets.
flexrep:domain-target-statuses This function returns the status for each domain target.
flexrep:get-domain-name Get a CPF domain's name.
flexrep:get-target-name Get a target's name, or nothing if the domain or target does not exist.
flexrep:inbound-filter-create This function creates an inbound filter element.
flexrep:inbound-filter-delete This function deletes the inbound filter for this database.
flexrep:inbound-filter-get This function gets any inbound filter that is contained in the database, or an empty sequence if none is configured.
flexrep:inbound-filter-insert This function inserts an inbound filter configuration into the database.
flexrep:process This function processes one or more replicated updates for the specified domain ID, ordered by oldest changes first, and returns the results.
flexrep:pull-create This function creates a configuration on a Replica database to pull updates from the Master database.
flexrep:pull-delete This function deletes the pull configuration from the Replica database.
flexrep:pull-get This function returns the pull replication configuration for the specified domain.
flexrep:pull-get-all This function returns the pull replication configurations for all of the domains.
flexrep:pull-get-by-id This function returns the pull replication configuration for the specified Pull ID.
flexrep:pull-get-domain-id This function returns the ID of the domain associated with the specified pull configuration.
flexrep:pull-get-enabled Get the enabled flag for a pull configuration.
flexrep:pull-get-http-options This function returns the HTTP options associated with the specified pull configuration.
flexrep:pull-get-id This function returns the ID for the specified pull configuration.
flexrep:pull-get-name This function returns the name of the specified pull configuration.
flexrep:pull-get-target-id This function returns the ID of the target associated with the specified pull configuration.
flexrep:pull-get-urls This function returns the URLs associated with the specified pull configuration.
flexrep:pull-insert This function inserts the specified pull configuration into the Replica database.
flexrep:pull-set-domain-id This function sets the domain ID for the specified pull configuration.
flexrep:pull-set-enabled Set the enabled flag for a pull.
flexrep:pull-set-http-options This function sets the HTTP options for the specified pull configuration.
flexrep:pull-set-name This function sets the name of the specified pull configuration.
flexrep:pull-set-target-id This function sets the ID of the replication target for the specified pull replication configuration.
flexrep:pull-set-urls This function sets the URLs for the specified pull configuration.
flexrep:push-local-forest This function pushes pending replication updates (either retries or zero-day) for the specified forest on the current host.
flexrep:push-local-forest-target Push a batch of documents from a single forest to a single target, and respawn a new task to do this repeatedly until either nothing remains to replicate or the spawn limit is reached.
flexrep:push-local-forests This function pushes deletes and any pending replication updates (either retries or zero-day) from all of the forests on the current host.
flexrep:remote-target-status This function returns the status of the target in a pull replication configuration.
flexrep:target-create This function creates a new target and add it to the specified configuration.
flexrep:target-delete This function deletes a target from a replication configuration.
flexrep:target-error-documents This function returns status information for documents that failed to replicate for the specified domain and targets.
flexrep:target-status This function returns the replication status for the specified targets within the specified replicated domain.
Function Detail
flexrep:apply(
$update as element(flexrep:update),
$content as document-node()?
)  as   empty-sequence()
Summary:

This function applies an update element to the current database.

Parameters:
$update : The update element to apply to the database.
$content : The updated document node.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $update :=
    <flexrep:update xmlns:flexrep=
      "http://marklogic.com/xdmp/flexible-replication">
        <doc:uri xmlns:doc="xdmp:document-load">/content/foo.xml</doc:uri>
        <flexrep:last-updated>2010-03-04T14:30:16.56-08:00</flexrep:last-updated>
        <doc:format xmlns:doc="xdmp:document-load">xml</doc:format>
        <doc:permissions xmlns:doc="xdmp:document-load"/>
        <doc:collections xmlns:doc="xdmp:document-load"/>
        <doc:document-quality xmlns:doc="xdmp:document-load">0</doc:document-quality>
        <prop:properties xmlns:prop="http://marklogic.com/xdmp/property"/>
    </flexrep:update>

    let $doc := fn:doc("/content/foo.xml")

    return flexrep:apply($update, $doc)

   (: Applies the specified update element to /content/foo.xml. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:configuration-create(
$domain-id as xs:unsignedLong
)  as   element(flexrep:configuration)
Summary:

This function creates a new replication configuration element. The returned element must be subsequently inserted to the database with flexrep:configuration-insert.

Parameters:
$domain-id : The ID of the replicated domain.

Example:
  (: This query must be executed on the Master database. :)

  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the ID of the replicated CPF domain from the Triggers database. :)
  let $domain:= xdmp:eval(
    'xquery version "1.0-ml";
     import module namespace dom = "http://marklogic.com/cpf/domains" 
       at "/MarkLogic/cpf/domains.xqy";
     fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
     (),
     <options xmlns="xdmp:eval">
       <database>{xdmp:database("MyTriggers")}</database>
     </options>)

   (: Create a replication configuration for the Replicated Content domain. :)
   let $cfg := flexrep:configuration-create($domain)

   (: Insert the replication configuration element into the database. :)
   return flexrep:configuration-insert($cfg) 

   (: Create a new replication configuration element for the Replication 
      Content domain and insert it into the Master database. :)
     

flexrep:configuration-delete(
$domain-id as xs:unsignedLong
)  as   empty-sequence()
Summary:

This function deletes a replication configuration. This removes the configuration document as well as any other documents that were created to track replication state. The properties that track state within individual documents are not removed.

Parameters:
$domain-id : The ID of the replicated domain.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)

  return flexrep:configuration-delete($domain)

  (: Deletes the replication configuration for the "Replicated Content" domain. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:configuration-domain-ids(  ) as  xs:unsignedLong*
Summary:

This function returns the IDs of the domains configured for the Master database.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  flexrep:configuration-domain-ids  ( )

  (: Returns the IDs of the domains used by the database on which the query 
     is executed. )
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:configuration-get(
$domain-id as xs:unsignedLong,
[$assert as xs:boolean]
)  as   element(flexrep:configuration)?
Summary:

This function gets the replication configuration for a CPF domain.

Parameters:
$domain-id : The ID of the replicated domain.
$assert (optional): Set to true to throw an exception if the configuration does not exist. The default value is false.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  return
      flexrep:configuration-get($domain, fn:true()) 
 
  (: Returns the replication configuration element for the "Replicated Content"
     domain. :)
      

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:configuration-get-alerting-uri(
$cfg as element(flexrep:configuration)
)  as   xs:string?
Summary:

Get the alerting URI associated with a FlexRep configuraiton.

Parameters:
$cfg : Parameter description...

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:configuration-get-alerting-uri($cfg) 
    

flexrep:configuration-get-domain-name(
$cfg as element(flexrep:configuration)
)  as   xs:string
Summary:

This function returns the domain name associated with the specified replication configuration.

Parameters:
$cfg : The replication configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())

  return flexrep:configuration-get-domain-name($cfg)

  (: Returns the domain name for the specified replication configuration. :)
     

flexrep:configuration-get-id(
$cfg as element(flexrep:configuration)
)  as   xs:unsignedLong
Summary:

This function returns the ID of the replication configuration.

Parameters:
$cfg : The replication configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())

  return flexrep:configuration-get-id($cfg)

  (: Returns the ID of the specified replication configuration. :)
     

flexrep:configuration-insert(
$cfg as element(flexrep:configuration)
)  as   empty-sequence()
Summary:

This function inserts a replication configuration to the database.

Parameters:
$cfg : The replication configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := flexrep:configuration-target-set-enabled(
	 $cfg,
	 $target-id,
	 fn:false())

  return flexrep:configuration-insert($cfg) 

  (: Disables push replication on the Master database. :)
  

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:configuration-set-alerting-uri(
$cfg as element(flexrep:configuration),
$uri as xs:string?
)  as   element(flexrep:configuration)
Summary:

Set the alerting URI for a FlexRep configuration. This enables query-based replication to any targets that are configured with a user-id. The alerting URI may be anywhere within the database, however flexrep:domain-alerting-uri() returns a convenient directory withini the FlexRep configuration area.

Parameters:
$cfg : The replication configuration.
$uri : The alerting configuration URI.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:configuration-insert(
  flexrep:configuration-set-alerting-uri($cfg,
    flexrep:domain-alerting-uri($domain-id)))
    

flexrep:configuration-target(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
[$assert as xs:boolean]
)  as   element(flexrep:target)?
Summary:

This function returns a specified target for a configuration, or throws an error if it does not exist.

Parameters:
$cfg : The replication configuration.
$target-id : The target ID.
$assert (optional): Set to true to throw an exception if the configuration does not exist. The default value is false.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return flexrep:configuration-target($cfg, $target-id, fn:true()) 

  (: Returns the configuration for the "Replica" target. :)
      

flexrep:configuration-target-get-documents-per-batch(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:integer
Summary:

This function returns the value of the documents-per-batch setting for the replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-documents-per-batch($cfg, $target-id) 
 
  (: Returns the number of replicated documents set to be sent in each batch. :) 
      

flexrep:configuration-target-get-enabled(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:boolean
Summary:

This function returns true if the specified replication target is enabled, otherwise it returns false.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-enabled($cfg, $target-id) 
 
  (: Returns True if the replication target is enabled.  Otherwise, False is
     returned. :)
      

flexrep:configuration-target-get-filter-module(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   element(flexrep:filter-module)
Summary:

This function returns the filter module used by the specified replcation target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-filter-module($cfg, $target-id) 
 
  (: Returns the name of the filter module used by the replication target. :)
      

flexrep:configuration-target-get-filter-options(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   element(flexrep:filter-options)
Summary:

This function retunrs the filter options configured for the specified replcation target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target_id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-filter-options($cfg, $target_id)

  (: Returns the filter options for the "Replica" target. :)
       

flexrep:configuration-target-get-http-options(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   element(flexrep:http-options)
Summary:

This function returns the HTTP options configured for the specified replcation target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

      let $domain := flexrep:configuration-domain-ids( )

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target_id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-http-options($cfg, $target_id)
  
  (: Returns the HTTP options for the "Replica" target. :)
      

flexrep:configuration-target-get-id(
$cfg as element(flexrep:configuration),
$target-name as xs:string
)  as   xs:unsignedLong
Summary:

This function returns the ID of the named replicaiton target.

Parameters:
$cfg : The replication configuration.
$target-name : The name of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())

  return
      flexrep:configuration-target-get-id($cfg, "Replica")

  (: Returns the ID of the target named "Replica." :)    
     

flexrep:configuration-target-get-immediate-push(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:boolean
Summary:

Get the immediate push flag for a target.

Parameters:
$cfg : The replication configuration.
$target-id : The target ID.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";
 
flexrep:configuration-target-get-immediate-push($domain-id, $target-id)
    

flexrep:configuration-target-get-name(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:string
Summary:

This function returns the name of the specified target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  return
      flexrep:configuration-target-get-name($cfg, 5840231460767636990) 
 
  (: Returns the name of the specified target. :)
      

flexrep:configuration-target-get-replicate-cpf(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:boolean
Summary:

This function returns true if CFG replcation is enabled for the specified replication target, otherwise it returns false.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-replicate-cpf($cfg, $target-id) 
  
   (: Returns True if CPF replication is enabled for the target.  Otherwise, 
      False is returned. :)
      

flexrep:configuration-target-get-retry-seconds-max(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:integer
Summary:

This function sets the replication retry maximum value for the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-retry-seconds-max($cfg, $target-id)

  (: Returns the maximum retry setting for the "Replica" target. :)
      

flexrep:configuration-target-get-retry-seconds-min(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:integer
Summary:

This function returns the value of the minimum retry setting for the replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-retry-seconds-min($cfg, $target-id) 
 
  (: Returns the retry value set for the target configuration. :)
      

flexrep:configuration-target-get-urls(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:string*
Summary:

This function returns the URLs for the specified targets.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:configuration-target-get-urls($cfg, $target-id) 
 
  (: Returns the URLs associated with the "Replica" target. :)
      

flexrep:configuration-target-get-user-id(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   xs:unsignedLong?
Summary:

Get the user ID associated with a target, if one exists. Only query-based targets have an associated user ID.

Parameters:
$cfg : The replication configuration.
$target-id : The target ID.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:configuration-target-get-user-id($cfg, $target-id)
    

flexrep:configuration-target-set-documents-per-batch(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:integer
)  as   element(flexrep:configuration)
Summary:

This function sets the documents-per-batch value for the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The number of documents to be replicated in each batch.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := 
      flexrep:configuration-target-set-documents-per-batch($cfg, $target-id, 20)

  return flexrep:configuration-insert($cfg) 

  (: Sets the replicated documents-per-batch setting for the "Replica" 
     target to 20. :)
      

flexrep:configuration-target-set-enabled(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:boolean
)  as   element(flexrep:configuration)
Summary:

This function enables or disables the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : A value of true enables the replcation target and a value of false disables the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id(
	$cfg,
	"Replica")

  let $cfg := flexrep:configuration-target-set-enabled(
	 $cfg,
	 $target-id,
	 fn:false())

  return flexrep:configuration-insert($cfg) 

  (: Disables push replication on the Master database. :)
      

flexrep:configuration-target-set-filter-module(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$uri as xs:string
)  as   element(flexrep:configuration)
Summary:

This function sets the specified filter for this replication configuration.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$uri : The URI for the filter module.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica") 

  let $cfg := 
      flexrep:configuration-target-set-filter-module($cfg, $target-id, "test.xqy")

  return flexrep:configuration-insert($cfg) 
 
  (: Resets the filter module used by the target to "test.xqy." :)
      

flexrep:configuration-target-set-filter-options(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as element(flexrep:filter-options)
)  as   element(flexrep:configuration)
Summary:

This function sets the specified filter options for this replication configuration. The options specified in the $val parameter are passed to the xdmp:invoke of the filter module, so any of the options you would specify in the xdmp:eval function are recognized.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The filter options in XML format.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	   at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())      
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $filter-opts := 
     <flexrep:filter-options>
       <user-id xmlns="xdmp:eval">{xdmp:user("John")}</user-id>
     </flexrep:filter-options>

  let $cfg := 
    flexrep:configuration-target-set-filter-options(
       $cfg, 
       $target-id, 
       $filter-opts)

  return flexrep:configuration-insert($cfg) 
  
  (: Sets the filter user to "John". :)
   

flexrep:configuration-target-set-http-options(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as element(flexrep:http-options)
)  as   element(flexrep:configuration)
Summary:

This function sets the HTTP options on the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The HTTP options in XML format.

Example:
  (: Execute against the Master database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())

  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica") 

  let $http-options := 
    <flexrep:http-options 
     xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
      <http:authentication xmlns:http="xdmp:http">
        <http:username>replicator</http:username>
        <http:password>admin</http:password>
      </http:authentication>
      <http:client-cert xmlns:http="xdmp:http"/>
      <http:client-key xmlns:http="xdmp:http"/>
      <http:pass-phrase xmlns:http="xdmp:http"/>
    </flexrep:http-options>

  let $cfg := 
      flexrep:configuration-target-set-http-options($cfg, $target-id, $http-options)

  return flexrep:configuration-insert($cfg) 

  (: Resets the username and password used to access the Replica App Server. :)
     

flexrep:configuration-target-set-immediate-push(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$immediate-push as xs:boolean
)  as   element(flexrep:configuration)
Summary:

Set a target's "immediate push" flag. This defaults to true when a target is created. Normally, when a document is created or updated, flexrep will attempt to replicate it to all push targets from a single CPF action, and a single database transaction. When many targets are configured, there is a danger that this transaction will run for a long time and eventually time out. The "immmediate push" flag allows control over which targets should have documents replicated immediately, and which targets should have them replicated via the periodic retry scheduled task.

Query-based targets are always handled by the periodic retry scheduled task.


Parameters:
$cfg : The replication configuration.
$target-id : The target ID.
$immediate-push : True if the target should attempt to push from the CPF action, false if it should only be pushed from the retry task.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";
 
flexrep:configuration-insert(
  flexrep:configuration-target-set-immediate-push(
    $cfg, $target-id, fn:false()))
    

flexrep:configuration-target-set-name(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:string*
)  as   element(flexrep:configuration)
Summary:

This function sets the name of the specified replcation target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The name of the target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := 
      flexrep:configuration-target-set-name($cfg, $target-id, "NewTarget")

  return flexrep:configuration-insert($cfg) 
 
  (: Changes the name of the "Replica" target to "NewTarget." :)
      

flexrep:configuration-target-set-replicate-cpf(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:boolean
)  as   element(flexrep:configuration)
Summary:

This function enables and disables CPF replication.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : A value of true enables CPF replcation on the target and a value of false disables CPF replication on the target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  return flexrep:configuration-get($domain, fn:true()) 

  (: Returns the current replication configuration. :) 
      

flexrep:configuration-target-set-retry-seconds-max(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:integer
)  as   element(flexrep:configuration)
Summary:

This function sets the replication retry maximum value for the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The maximum retry value.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := 
      flexrep:configuration-target-set-retry-seconds-max($cfg, $target-id, 200)

  return flexrep:configuration-insert($cfg) 
 
  (: Sets the minimum retry setting for the "Replica" target to 200. :)
      

flexrep:configuration-target-set-retry-seconds-min(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$val as xs:integer
)  as   element(flexrep:configuration)
Summary:

This function sets the replication retry minimum value for the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$val : The minimum retry value.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := 
      flexrep:configuration-target-set-retry-seconds-min($cfg, $target-id, 20)

  return flexrep:configuration-insert($cfg) 
 
  (: Sets the minimum retry setting for the "Replica" target to 20. :)
      

flexrep:configuration-target-set-urls(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$urls as xs:string*
)  as   element(flexrep:configuration)
Summary:

This function sets the URLs for the specified replication target.

Parameters:
$cfg : The replication configuration.
$target-id : The ID of the replication target.
$urls : One or more URLs for the Replica App Servers.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
	    at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := flexrep:configuration-target-set-urls(
         $cfg, 
         $target-id, 
         "http://server134:8005/")

  return flexrep:configuration-insert($cfg) 
 
  (: Sets the target URL for the "Replica" target to "http://server134:8005/". :)
      

flexrep:configuration-target-set-user-id(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong,
$user-id as xs:unsignedLong?
)  as   element(flexrep:configuration)
Summary:

Set a target's user-id. This is only used for query-based targets, and is only meaningful if the FlexRep configuration also has an alerting URI associated with it. When both of these are true, documents are replicated to the target only if either the document or its properties match one of the user's alerting rules in the alerting configuration.

Parameters:
$cfg : The replication configuration.
$target-id : The target ID.
$user-id : The user ID, or an empty sequence if this is not a query-based target.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:configuration-insert(
  flexrep:configuration-target-set-user-id(
    $cfg, $target-id, $user-id))
    

flexrep:configuration-targets(
$cfg as element(flexrep:configuration)
)  as   element(flexrep:target)*
Summary:

This function returns the replication targets for a configuration.

Parameters:
$cfg : The replication configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())

  return flexrep:configuration-targets($cfg) 

  (: Returns the replication targets configured for the Default Master domain. :)
     

flexrep:configure-database(
$config as element(configuration),
$dbid as xs:unsignedLong
)  as   element(configuration)
Summary:

This function creates any indexes needed for CPF based replication. The input configuration is returned from admin:get-configuration and the configuration returned from this function must be inserted again with admin:save-confguration for the changes to take effect. This function may be called multiple times for the same database with no ill effect.

Parameters:
$config : The server configuration returned from admin:get-configuration
$dbid : The ID of the database to configure.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  import module namespace admin = "http://marklogic.com/xdmp/admin"
      at "/MarkLogic/admin.xqy";

  let $config := admin:get-configuration()

  let $config := flexrep:configure-database(
	$config,
	xdmp:database("Master")) 

  return admin:save-configuration($config)

  (: Creates the indexes needed by the Master database for CPF based replication. :)
      

flexrep:database-needs-configuration(
$config as element(configuration),
$dbid as xs:unsignedLong
)  as   xs:boolean
Summary:

This function checks the configuration of a database to see if it has all of the necessary indexes for Flexible Replication to work at its best. Returns true if the database needs configuration changes, and returns false if the configuration is as-expected.

Parameters:
$config : A configuration specification, typically a call to admin:get-configuration.
$dbid : The database ID of the database to check.

Usage Notes:

Note that this function will return when run against a database that does not have Flexible Replication configured.


Example:
xquery version "1.0-ml"; 
 
import module namespace flexrep = 
      "http://marklogic.com/xdmp/flexible-replication"  
      at "/MarkLogic/flexrep.xqy";
import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

flexrep:database-needs-configuration(
  admin:get-configuration(), xdmp:database("Documents") )

  => true
    

flexrep:delete(
$delete as element(flexrep:delete)
)  as   empty-sequence()
Summary:

This function applies a delete element to the current database.

Parameters:
$delete : The delete element to apply to the database.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $delete :=
    <flexrep:delete xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
        <doc:uri xmlns:doc="xdmp:document-load">/content/foo.xml</doc:uri>
        <flexrep:last-updated>2010-03-04T14:35:12.714-08:00</flexrep:last-updated>
    </flexrep:delete>

   return flexrep:delete($delete)
  
   (: Applies the specified delete element to /content/foo.xml.  This effectively
      deletes the document from both the Master and Replica databases. :) 
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:do-pull(
$pull as element(flexrep:pull)
)  as   element()*
Summary:

This function is used by a Replica to pull updates from the Master. It returns a list of elements; the first element is the response element that was set back to the master, followed by one or more flexrep:ack elements that were posted back to the master.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull := flexrep:pull-get(8720056888183458895) 

  return flexrep:do-pull($pull)

  (: Returns the response and ACK elements last sent to the master. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:document-reset(
$uri as xs:string,
$domain-id as xs:unsignedLong,
[$target-ids as xs:unsignedLong*]
)  as   empty-sequence()
Summary:

This function resets the URI status for all replication targets. A reset involves retaining any record of last success, clearing any failure status, and setting the time for the next replication attempt to the current time. The status is reset for the specified $target-ids. If no $target-ids parameter is specified, then the URI status for all replication targets is reset.

Resetting the URI status for a target is useful if the document has errored out due to too many failures, or if you want to replicate the document again.


Parameters:
$uri : The URI to be assigned the new status.
$domain-id : The ID of the replicated domain.
$target-ids (optional): The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return
      flexrep:document-reset("http://localhost:8011/", $domain, $target-id)

  (: Resets the URI status for the "Replica" target. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:document-status(
$domain-id as xs:unsignedLong,
$uri as xs:string
)  as   element(flexrep:document-status)
Summary:

This function returns the flexrep:document-status element for the document at the specified URI in the specified domain. The returned flexrep:document-status element is extracted from the document's properties, which remain even if the document has been deleted.

Parameters:
$domain-id : The ID of the replicated domain.
$uri : The URI of the document.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $domain := xdmp:eval(
    'xquery version "1.0-ml";
    import module namespace dom = "http://marklogic.com/cpf/domains" 
      at "/MarkLogic/cpf/domains.xqy";
    fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
    (),
    <options xmlns="xdmp:eval">
      <database>{xdmp:database("MyTriggers")}</database>
    </options>)

  return
    flexrep:document-status($domain, "/content/foo.xml")

  (: Returns the status of the document associated with the specified URI and domain. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:domain-alerting-uri(
$domain-id as xs:unsignedLong
)  as   xs:string
Summary:

Generate an alerting URI for a CPF domain. The URI will be a subdirectory of the directory used to store other state for the FlexRep domain. There is no requirement that the alerting configuration that a FlexRep domain be stored in this location, but it is a convenient place to put it.

Parameters:
$domain-id : The CPF domain ID.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";


flexrep:configuration-insert(
  flexrep:configuration-set-alerting-uri($cfg,
    flexrep:domain-alerting-uri($domain-id)))
    

flexrep:domain-status(
$domain-id as xs:unsignedLong,
[$with-targets as xs:boolean],
[$terse as xs:boolean]
)  as   element(flexrep:domain-status)
Summary:

This function returns the replication status for the specified replicated CPF domain.

Parameters:
$domain-id : The ID of the replicated domain.
$with-targets (optional): Set to true to include status information for each target. Otherwise set to false.
$terse (optional): Set to true to prevent counts from being returned for each of the individual states (deleted, error, updated, and so on). Otherwise set to false.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)
 
  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return flexrep:domain-status($domain, fn:true(), fn:false())

  (: Returns the status of the domain and its targets. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:domain-target-reset(
$domain-id as xs:unsignedLong,
$target-ids as xs:unsignedLong*,
[$errors-only as xs:boolean]
)  as   empty-sequence()
Summary:

This function resets the URI status for the specified replication targets. A reset involves retaining any record of last success, clearing any failure status, and setting the time for the next replication attempt to the current time. The status is reset for the specified $target-ids.

Resetting the URI status for a target is useful if the document has errored out due to too many failures, or if you want to replicate the document again.


Parameters:
$domain-id : The ID of the replicated domain.
$target-ids : The ID of the replication target.
$errors-only (optional): When set to true, only reset the status for documents with errors. The default is false.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)
 
  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return flexrep:domain-target-reset($domain, ($target-id))

  (: Resets the URI status for the "Replica" target. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:domain-target-statuses(  ) as  element(flexrep:domain-target-status)*
Summary:

This function returns the status for each domain target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  flexrep:domain-target-statuses()

  (: Returns the status for the targets in each domain configured for the database. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:get-domain-name(
$domain-id as xs:unsignedLong
)  as   xs:string
Summary:

Get a CPF domain's name.

Parameters:
$domain-id : The CPF domain ID.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:get-domain-name($domain-id)
    

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:get-target-name(
$domain-id as xs:unsignedLong,
$target-id as xs:unsignedLong
)  as   xs:string?
Summary:

Get a target's name, or nothing if the domain or target does not exist.

Parameters:
$domain-id : The domain ID.
$target-id : The target ID.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:get-target-name($domain-id, $target-id)
    

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:inbound-filter-create(
$filter-module as xs:string,
$filter-options as element(flexrep:filter-options)?
)  as   element(flexrep:inbound-filter)
Summary:

This function creates an inbound filter element.

Parameters:
$filter-module : The name of the filter module (e.g. "/my-filter.xqy").
$filter-options : Eval options to be used when running the filter.

Example:
 
xquery version "1.0-ml"; 
  
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:inbound-filter-insert(
  flexrep:inbound-filter-create(
    "/my-inbound-filter.xqy",
    <flexrep:filter-options xmlns="xdmp:eval">
      <modules>{xdmp:database("my-modules-database")}</modules>
      <root>/some/directory/</root>
    </flexrep:filter-options>))
    

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:inbound-filter-delete(  ) as  empty-sequence()
Summary:

This function deletes the inbound filter for this database. If no filter is currently configured, an error will be thrown.

Example:
 
xquery version "1.0-ml"; 
  
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:inbound-filter-delete().
    

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:inbound-filter-get(  ) as  element(flexrep:inbound-filter)?
Summary:

This function gets any inbound filter that is contained in the database, or an empty sequence if none is configured.

Example:
 
xquery version "1.0-ml"; 
  
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:inbound-filter-get()
    

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:inbound-filter-insert(
$filter as element(flexrep:inbound-filter)
)  as   empty-sequence()
Summary:

This function inserts an inbound filter configuration into the database. A single inbound filter applies to all inbound flexible replication to the database. The filter receives two external variables as input, and should return the filtered form of the replication information. An example is shown below.

Parameters:
$filter : An inbound filter configuration.

Example:

xquery version "1.0-ml"; 
  
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:inbound-filter-insert(
  flexrep:inbound-filter-create(
    "/my-inbound-filter.xqy",
    <flexrep:filter-options xmlns="xdmp:eval">
      <modules>{xdmp:database("my-modules-database")}</modules>
      <root>/some/directory/</root>
    </flexrep:filter-options>))
    

The following example shows an identity filter, that also inserts a log document into the database to track the inbound replication information.

xquery version "1.0-ml";

import module
  namespace flexrep = "http://marklogic.com/xdmp/flexible-replication"
  at "/MarkLogic/flexrep.xqy";

declare namespace doc = "xdmp:document-load";

declare variable $dts as element(flexrep:domain-target-status) external;
declare variable $update as node()* external;
	        
xdmp:document-insert(
  "/inbound-log/" || xdmp:random() || ".xml",
  <inbound-log time="{fn:current-dateTime()}">
    { for $u in $update
      let $exists :=
        attribute exists {
          fn:exists(
            ( fn:doc($u/doc:uri),
              xdmp:document-properties($u/doc:uri)
            ))
        }
      return
	typeswitch ($u)
	case element(flexrep:update)  return
	  element flexrep:update {
	    $exists,
	    $u/@*,
	    $u/*
	  }
	case element (flexrep:delete) return
	  element flexrep:delete {
	    $exists,
	    $u/@*,
	    $u/*
	  }
	default return ()
    }
  </inbound-log>,
  ("read", "update") ! xdmp:permission("flexrep-user", .)),

$update	        
    

The $dts variable can be used to determine where the inbound replication is coming from. Below is an example. The received-from element is either the IP address that a push is coming from, or the URL that was used if the replication was the result of a pull.

<document-target-status xmlns="http://marklogic.com/xdmp/flexible-replication">
  <domain-id>82381923712932</domain-id>
  <domain-name>Default Documents</domain-name>
  <target-id>637261830239283</target-id>
  <target-name>San Francisco</target-name>
  <received-from>10.100.42.3</received-from>
  <received-at>2014-11-20T16:14:57.876111-08:00</received-at>
</document-target-status>
    

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:process(
$domain-id as xs:unsignedLong,
[$size as xs:unsignedInt?],
[$targets as xs:unsignedLong*],
[$forest-ids as xs:unsignedLong*],
[$uris as xs:string*]
)  as   element(flexrep:results)
Summary:

This function processes one or more replicated updates for the specified domain ID, ordered by oldest changes first, and returns the results.

Parameters:
$domain-id : The ID of the replicated domain.
$size (optional): The maximum number of replications. If not specified, the maximum is one.
$targets (optional): The IDs of the replication targets.
$forest-ids (optional): The forest IDs from which to process replications. If none are specified, replications from all forests are considered.
$uris (optional): The URIs of specific documents to process.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
		  at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)

  return flexrep:process($domain) 

  (: Processes the replicated updates for the "Replicated Content" domain. :)
     

flexrep:pull-create(
$name as xs:string,
$domain-id as xs:unsignedLong,
$target-id as xs:unsignedLong,
$urls as xs:string+,
$http-options as element(flexrep:http-options)?
)  as   element(flexrep:pull)
Summary:

This function creates a configuration on a Replica database to pull updates from the Master database. If a configuration already exists for the given target and domain IDs, then the configuration is overwritten.

Parameters:
$name : The name of the pull configuration.
$domain-id : The ID of the domain containing the replicated content. This value is obtained from the Trigger database used by the Master database.
$target-id : The ID of the replication target. This value is obtained from the Master database.
$urls : The URL of the Master App Server.
$http-options : The HTTP options in XML format.

Example:
  (: This query must be executed on a Replica database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Specify the ID of the replicated CPF domain obtained from the Master's 
     Triggers database. :)
  let $domain:= 9535475951259984368

  (: Specify the ID of the replication target obtained from the Master database. :)
  let $target-id := 18130470845627037840

  (: Specify the HTTP options for the replication target. :)
  let $http-options := 
    <flexrep:http-options
     xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
      <http:authentication xmlns:http="xdmp:http">
        <http:username>admin</http:username>
        <http:password>admin</http:password>
      </http:authentication>
      <http:client-cert xmlns:http="xdmp:http"/>
      <http:client-key xmlns:http="xdmp:http"/>
      <http:pass-phrase xmlns:http="xdmp:http"/>
    </flexrep:http-options>

  let $pullconfig := flexrep:pull-create(
    "Master",
    $domain,
    $target-id,
    "http://localhost:8010/",
    $http-options)

  (: Insert the pull configuration into the Replica database. :)
  return flexrep:pull-insert($pullconfig) 

  (: Creates a pull replication configuration element for the specified domain. :)
     

flexrep:pull-delete(
$domain-id as xs:unsignedLong,
[$target-id as xs:unsignedLong]
)  as   empty-sequence()
Summary:

This function deletes the pull configuration from the Replica database.

Parameters:
$domain-id : The ID of the domain containing the replicated content. This value is obtained from the Trigger database used by the Master database.
$target-id (optional): The optional ID of the target. When used, you can specify a specific domain/target combination from which to delete the pull configuration.

Example:
  (: Execute against a Replica database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $domain := 9535475951259984368

  return  flexrep:pull-delete($domain)

  (: Removes the Pull Replication configuration element from the Replica database. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:pull-get(
$domain-id as xs:unsignedLong,
[$assert as xs:boolean]
)  as   element(flexrep:pull)*
Summary:

This function returns the pull replication configuration for the specified domain.

Parameters:
$domain-id : The ID of the domain containing the replicated content. This value is obtained from the Trigger database used by the Master database.
$assert (optional): Set to true to throw an exception if the configuration does not exist. The default value is false.

Example:
  (: Execute against a Replica database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
    at "/MarkLogic/flexrep.xqy";

  flexrep:pull-get(9535475951259984368,  fn:true())

  (: Returns the Pull Configuration for the specified domain. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:pull-get-all(  ) as  element(flexrep:pull)*
Summary:

This function returns the pull replication configurations for all of the domains.

Example:
  (: Execute against a Master database. :)  
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  flexrep:pull-get-all()

  (: Returns the Pull Configurations for all of the domains. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:pull-get-by-id(
$pull-id as xs:unsignedLong,
[$assert as xs:boolean]
)  as   element(flexrep:pull)?
Summary:

This function returns the pull replication configuration for the specified Pull ID.

Parameters:
$pull-id : The ID of the pull replication configuration.
$assert (optional): Determines whether to generate an error if the pull configuration does not exist. Set to fn:true() to generate an error, or fn:false() to return an empty sequence if the pull configuration does not exist. The default is fn:false().

Example:
  (: Execute on the Replica database. :) 
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  flexrep:pull-get-by-id(2261113583548708683)

  (: Returns the pull replication configuration for the specified ID. :)
    

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:pull-get-domain-id(
$pull as element(flexrep:pull)
)  as   xs:unsignedLong
Summary:

This function returns the ID of the domain associated with the specified pull configuration.

Parameters:
$pull : The pull configuration.

Example:
  (: Execute against a Replica database. :)  
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  for $pull-config in flexrep:pull-get-all() 

  return flexrep:pull-get-domain-id($pull-config)

  (: Returns the domain IDs associated with each pull configuration. :)
     

flexrep:pull-get-enabled(
$pull as element(flexrep:pull)
)  as   xs:boolean
Summary:

Get the enabled flag for a pull configuration.

Parameters:
$pull : The pull configuration.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";
 
flexrep:pull-insert(
  flexrep:pull-set-enabled(
    $pull, fn:not(flexrep:pull-get-enabled($pull))))
    

flexrep:pull-get-http-options(
$pull as element(flexrep:pull)
)  as   element(flexrep:http-options)
Summary:

This function returns the HTTP options associated with the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.

Example:
  (: Execute against a Replica database. :)   
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 

  return flexrep:pull-get-http-options($pull-config)

  (: Returns the HTTP options associated with the specified pull configuration. :)
     

flexrep:pull-get-id(
$pull as element(flexrep:pull)
)  as   xs:unsignedLong
Summary:

This function returns the ID for the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 

  return flexrep:pull-get-id($pull-config) 

  (: Returns the ID for the specified pull configuration. :)
     

flexrep:pull-get-name(
$pull as element(flexrep:pull)
)  as   xs:string
Summary:

This function returns the name of the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 

  return flexrep:pull-get-name($pull-config) 
 
  (: Returns the name of the specified pull configuration. :)
     

flexrep:pull-get-target-id(
$pull as element(flexrep:pull)
)  as   xs:unsignedLong
Summary:

This function returns the ID of the target associated with the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.

Example:
  (: Execute against a Replica database. :)   
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  for $pull-config in flexrep:pull-get-all() 

  return flexrep:pull-get-target-id($pull-config)

  (: Returns the target IDs associated with each pull configuration. :)
     

flexrep:pull-get-urls(
$pull as element(flexrep:pull)
)  as   xs:string*
Summary:

This function returns the URLs associated with the specified pull configuration.

Parameters:
$pull : The pull configuration.

Example:
  (: Execute against a Replica database. :)   
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 

  return flexrep:pull-get-urls($pull-config)

  (: Returns the target URLs associated with the specified pull configuration. :)
     

flexrep:pull-insert(
$pull as element(flexrep:pull)
)  as   empty-sequence()
Summary:

This function inserts the specified pull configuration into the Replica database.

Parameters:
$pull : The pull replication configuration obtained by the flexrep:pull-get function.

Example:
  (: This query must be executed on a Replica database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Specify the ID of the replicated CPF domain obtained from the Master's 
     Triggers database. :)
  let $domain:= 9535475951259984368

  (: Specify the ID of the replication target obtained from the Master database. :)
  let $target-id := 18130470845627037840

  (: Specify the HTTP options for the replication target. :)
  let $http-options := 
    <flexrep:http-options 
     xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
      <http:authentication xmlns:http="xdmp:http">
        <http:username>admin</http:username>
        <http:password>admin</http:password>
      </http:authentication>
      <http:client-cert xmlns:http="xdmp:http"/>
      <http:client-key xmlns:http="xdmp:http"/>
      <http:pass-phrase xmlns:http="xdmp:http"/>
    </flexrep:http-options>

  let $pullconfig := flexrep:pull-create(
    "Master",
    $domain,
    $target-id,
    "http://localhost:8010/",
    $http-options)

  (: Insert the pull configuration into the Replica database. :)
  return flexrep:pull-insert($pullconfig) 

  (: Inserts a pull replication configuration element into the Replica database. :)
     

http://marklogic.com/xdmp/privileges/flexrep-admin


flexrep:pull-set-domain-id(
$pull as element(flexrep:pull),
$domain-id as xs:unsignedLong
)  as   element(flexrep:pull)
Summary:

This function sets the domain ID for the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.
$domain-id : The domain ID to set for the pull configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 
  let $pull-config := flexrep:pull-set-domain-id($pull-config, 2235475951259984368) 

  return flexrep:pull-insert($pull-config) 

  (: Sets the domain ID for the pull configuration. :)
     

flexrep:pull-set-enabled(
$pull as element(flexrep:pull),
$flag as xs:boolean
)  as   element(flexrep:pull)
Summary:

Set the enabled flag for a pull. This provides a way for a target cluster to disable pull replication when necessary.

Parameters:
$pull : The pull configuration.
$flag : True if the pull is enabled, false if it is disabled.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

flexrep:pull-insert(
  flexrep:pull-set-enabled(
    $pull, fn:not(flexrep:pull-get-enabled($pull))))
    

flexrep:pull-set-http-options(
$pull as element(flexrep:pull),
$http-options as element(flexrep:http-options)
)  as   element(flexrep:pull)
Summary:

This function sets the HTTP options for the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.
$http-options : The HTTP options in XML format to set for the pull configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $http-options :=
    <flexrep:http-options 
     xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
      <http:authentication xmlns:http="xdmp:http">
        <http:username>replicator</http:username>
        <http:password>admin</http:password>
      </http:authentication>
      <http:client-cert xmlns:http="xdmp:http"/>
      <http:client-key xmlns:http="xdmp:http"/>
      <http:pass-phrase xmlns:http="xdmp:http"/>
    </flexrep:http-options>

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 
  let $pull-config := flexrep:pull-set-http-options($pull-config, $http-options)

  return flexrep:pull-insert($pull-config)

  (: Sets the specified HTTP options for the specified Pull Configuration. :)
      

flexrep:pull-set-name(
$pull as element(flexrep:pull),
$name as xs:string
)  as   element(flexrep:pull)
Summary:

This function sets the name of the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.
$name : The name to be set for the pull configuration.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 
  let $pull-config := flexrep:pull-set-name($pull-config, "MasterRep") 

  return flexrep:pull-insert($pull-config) 
 
  (: Sets the name of the specified pull configuration to "MasterRep." :)
     

flexrep:pull-set-target-id(
$pull as element(flexrep:pull),
$target-id as xs:unsignedLong
)  as   element(flexrep:pull)
Summary:

This function sets the ID of the replication target for the specified pull replication configuration.

Parameters:
$pull : The pull replication configuration obtained by the flexrep:pull-get function.
$target-id : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 
  let $pull-config := flexrep:pull-set-target-id($pull-config, 11130470845627037840) 

  return flexrep:pull-insert($pull-config) 

  (: Sets the ID of the replication target for the specified pull configuration. :)
     

flexrep:pull-set-urls(
$pull as element(flexrep:pull),
$urls as xs:string+
)  as   element(flexrep:pull)
Summary:

This function sets the URLs for the specified pull configuration.

Parameters:
$pull : The pull replication configuration returned by the flexrep:pull-get function.
$urls : THe URLs to set for the pull configuration.

Example:
  (: Execute against a Replica database. :)   
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pull-config := flexrep:pull-get(9535475951259984368, fn:true()) 
  let $pull-config := flexrep:pull-set-urls($pull-config, "http://server321:8010/")

  return flexrep:pull-insert($pull-config)

  (: Sets the URL for the specified Pull Configuration to "http://server321:8010/". :)
     

flexrep:push-local-forest(
$domain-id as xs:unsignedLong,
$forest-id as xs:unsignedLong,
$max-spawn as xs:unsignedLong
)  as   empty-sequence()
Summary:

This function pushes pending replication updates (either retries or zero-day) for the specified forest on the current host. If any updates are found, a new task is spawned to call this function again. This continues until all pending replication updates have been processed.

Parameters:
$domain-id : The ID of the replicated domain.
$forest-id : The ID of the replicated forest.
$max-spawn : The limit to the number of doable spawns. If a task respawns itself too many times, a spawn will eventually fail with an exception.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
      at "/MarkLogic/admin.xqy";

  let $forest-id :=  
      admin:forest-get-id(admin:get-configuration(), "MasterForest")

  return
      flexrep:push-local-forest(5864248273900832906, $forest-id)
 
  (: Pushes all pending replication updates from the "MasterForest" forest on the host. :)
        

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:push-local-forest-target(
$domain-id as xs:unsignedLong,
$target-id as xs:unsignedLong,
$forest-id as xs:unsignedLong,
$max-spawn as xs:unsignedLong
)  as   empty-sequence()
Summary:

Push a batch of documents from a single forest to a single target, and respawn a new task to do this repeatedly until either nothing remains to replicate or the spawn limit is reached. Typically deployments do not need to call this directly, and instead rely on the push-local-forests.xqy scheduled task.

Parameters:
$domain-id : The domain ID.
$target-id : The target ID.
$forest-id : The forest ID.
$max-spawn : The maximum number of times to respawn.

Example:

xquery version "1.0-ml"; 
 
import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";
 
flexrep:push-local-forest-target($domain-id, $target-id, $forest-id, 10)
    

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:push-local-forests(  ) as  empty-sequence()
Summary:

This function pushes deletes and any pending replication updates (either retries or zero-day) from all of the forests on the current host. A separate task is spawned for each combination of CPF domain and local forest which in turn calls the push-local-forest to increase parallelism.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  flexrep:push-local-forests()

  (: Pushes all pending replication updates from all of the forests on the host. :)
        

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:remote-target-status(
$pull as element(flexrep:pull)
)  as   element(flexrep:target-status)?
Summary:

This function returns the status of the target in a pull replication configuration.

Parameters:
$pull : The pull replication configuration containing the pull target (master database).

Example:
  (: Execute on the Replica database. :) 
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  let $pullconfig := flexrep:pull-get-by-id(2261113583548708683)

  return flexrep:remote-target-status($pullconfig) 

  (: Returns the status of the master database from which replca is pulling
     updates. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user


flexrep:target-create(
$cfg as element(flexrep:configuration),
$name as xs:string,
$urls as xs:string*,
$retry-seconds-min as xs:unsignedInt?,
$retry-seconds-max as xs:unsignedInt?,
$documents-per-batch as xs:unsignedInt?,
$enabled as xs:boolean?,
$http-options as element(flexrep:http-options)?,
$replicate-cpf as xs:boolean?,
$filter-module as xs:string?,
$filter-options as element(flexrep:filter-options)?,
[$user-id as xs:unsignedLong?],
[$immediate-push as xs:boolean]
)  as   element(flexrep:configuration)
Summary:

This function creates a new target and add it to the specified configuration. A random ID is chosen for the target. You must subsequently use flexrep:configuration-insert to write the modified configuration into the database.

Parameters:
$cfg : The configuration to which to add the target.
$name : The name of the target.
$urls : The URLs to be used to push replicated content to, with the load spread across them if there is more than one. If none are specified, the target is expected to do a pull.
$retry-seconds-min : The minimum time to wait before scheduling a push retry.
$retry-seconds-max : The maximum time to wait before scheduling a push retry.
$documents-per-batch : The number of documents to attempt to replicate from a single invocation of the scheduled replication task.
$enabled : Specifies whether or not this target is enabled.
$http-options : The HTTP options in XML format.
$replicate-cpf : Determines whether to replicate CPF. Set to fn:true to replicate CPF. Otherwise set to fn:false. In most circumstances, you will not want to replicate CPF.
$filter-module : A main module to filter replication attempts.
$filter-options : The options to pass to the filter module.
$user-id (optional): The user ID if this is a query-based target.
$immediate-push (optional): Specifies whether to push to the query-based target immediately. The default is fn:true().

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the ID of the replicated CPF domain from the Triggers database. :)
  let $domain:= xdmp:eval(
    'xquery version "1.0-ml";
    import module namespace dom = "http://marklogic.com/cpf/domains" 
      at "/MarkLogic/cpf/domains.xqy";
    fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
    (),
    <options xmlns="xdmp:eval">
      <database>{xdmp:database("MyTriggers")}</database>
    </options>)

  (: Obtain the replication configuration. :)
  let $cfg := flexrep:configuration-get($domain, fn:true()) 

  (: Specify the HTTP options for the replication target. :)
  let $http-options := 
    <flexrep:http-options
      xmlns:flexrep="http://marklogic.com/xdmp/flexible-replication">
      <http:authentication xmlns:http="xdmp:http">
        <http:username>admin</http:username>
        <http:password>admin</http:password>
      </http:authentication>
      <http:client-cert xmlns:http="xdmp:http"/>
      <http:client-key xmlns:http="xdmp:http"/>
      <http:pass-phrase xmlns:http="xdmp:http"/>
    </flexrep:http-options>

  (: Create the replication target. :)
  let $cfg := flexrep:target-create(
    $cfg,
    "Replica",
    "http://localhost:8011/",
    60,
    300,
    10,
    fn:true(),
    $http-options,
    fn:false(),
    (),
    () ) 

  (: Insert the changes to the replication configuration. :)
  return flexrep:configuration-insert($cfg) 
 
  (: Creates a replication target, named "Replica." :)   
    

flexrep:target-delete(
$cfg as element(flexrep:configuration),
$target-id as xs:unsignedLong
)  as   element(flexrep:configuration)
Summary:

This function deletes a target from a replication configuration. You must use the flexrep:configuration-insert function to insert the configuration for the delete to take place. When the configuration is inserted, any additional documents created to track state for the target will be removed.

Parameters:
$cfg : The replication configuration.
$target-id : The target ID.

Example:
  (: Execute on the Master database. :)
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain:= xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Default Master" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("Triggers")}</database>
         </options>)

  let $cfg := flexrep:configuration-get($domain, fn:true()) 
 
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  let $cfg := flexrep:target-delete(
        $cfg,
        $target-id)

  return flexrep:configuration-insert($cfg) 
 
  (: Deletes the target, named "Replica," from the Master database. :)
      

flexrep:target-error-documents(
$domain-id as xs:unsignedLong,
$target-ids as xs:unsignedLong*
)  as   element(flexrep:document-target-status)*
Summary:

This function returns status information for documents that failed to replicate for the specified domain and targets. The sequence of status elements returned is ordered in reverse chronological order of the last time replication was attempted for the document.

Parameters:
$domain-id : The ID of the replicated domain.
$target-ids : The ID of the replication target.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)
 
  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return flexrep:target-error-documents($domain, ($target-id))

  (: Returns the status of the documents in the "Replicated Content" domain
    that failed to replicate to the "Replica" target.  :)
     

flexrep:target-status(
$domain-id as xs:unsignedLong,
$target-ids as xs:unsignedLong*
)  as   element(flexrep:target-status)*
Summary:

This function returns the replication status for the specified targets within the specified replicated domain.

Parameters:
$domain-id : The ID of the replicated domain.
$target-ids : The IDs of the replication targets.

Example:
  xquery version "1.0-ml"; 

  import module namespace flexrep = "http://marklogic.com/xdmp/flexible-replication" 
      at "/MarkLogic/flexrep.xqy";

  (: Obtain the domain ID from the database used by the Master to enable CPF. :)
  let $domain := xdmp:eval(
        'xquery version "1.0-ml";
         import module namespace dom = "http://marklogic.com/cpf/domains" 
            at "/MarkLogic/cpf/domains.xqy";
         fn:data(dom:get( "Replicated Content" )//dom:domain-id)',
         (),
         <options xmlns="xdmp:eval">
            <database>{xdmp:database("MyTriggers")}</database>
         </options>)
 
  let $cfg := flexrep:configuration-get($domain, fn:true())
  let $target-id := flexrep:configuration-target-get-id($cfg, "Replica")

  return flexrep:target-status($domain, $target-id) 

  (: Returns the status of the specified target. :)
     

http://marklogic.com/xdmp/privileges/flexrep-user