# Set up a cluster of Liberators

You can define two or more Liberators as a cluster. Here’s how to do this.

For more about clustering, see [Liberator clustering features and concepts](liberator-clustering.md).

## Clustering Liberators without the Caplin Deployment Framework

Here’s an example of how to configure a Liberator cluster when you’re not using the Deployment Framework. Here we’ve assumed there are just two Liberators in the cluster, but the same approach applies when you’re clustering more.

**Config for the first Liberator in the cluster:**

```
cluster-index 0
cluster-cache-source-routing  TRUE
cluster-cache-request-objects TRUE
cluster-heartbeat-time        15
cluster-heartbeat-slack-time  5

add-cluster-node
   cluster-addr <First-Liberators-network-interface-address>
   cluster-port <First-Liberators-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Liberators-network-interface-address>
   cluster-port <Second-Liberators-network-port-number>
end-cluster-node
```

**Config for the second Liberator in the cluster:**

```
cluster-index 1
cluster-cache-source-routing  TRUE
cluster-cache-request-objects TRUE
cluster-heartbeat-time        15
cluster-heartbeat-slack-time  5

add-cluster-node
   cluster-addr <First-Liberators-network-interface-address>
   cluster-port <First-Liberators-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Liberators-network-interface-address>
   cluster-port <Second-Liberators-network-port-number>
end-cluster-node
```

**Here’s an explanation of the configuration items that we’ve used:**

* [`cluster-index`](liberator-clustering-configuration.md#cluster-index): Uniquely identifies this Liberator in the cluster. Make sure each Liberator in the cluster has a different cluster-index in its configuration file; in this example, the first Liberator has cluster-index 0 and the second has cluster-index 1.

  Index numbers must start at `0` and correspond to the order of the `add-cluster-node` items in the configuration file.
* `[cluster-cache-source-routing](liberator-clustering-configuration.md#cluster-cache-source-routing) TRUE`: Enables [Intelligent Source Routing](liberator-clustering.md#intelligent-source-routing). Also see [Note 1](#note-1) below.
* `[cluster-cache-request-objects](liberator-clustering-configuration.md#cluster-cache-request-objects) TRUE`: The Liberator automatically requests (subscribes to) the objects that the other Liberators in the cluster request. Setting this item to `TRUE` for every Liberator in the cluster means that all the Liberators will request (and cache) an object when one of them requests it. Since `cluster-cach-source-routing` is also `TRUE`, the object is always obtained from the same Integration Adapter or Transformer instance.
* [`cluster-heartbeat-time`](liberator-clustering-configuration.md#cluster-heartbeat-time) is the time in seconds between each cluster heartbeat. The Liberators forming a cluster exchange heartbeat messages at regular intervals, allowing each of them to check that all the others are still present, and take appropriate action if one doesn’t respond.
* [`cluster-heartbeat-slack-time`](liberator-clustering-configuration.md#cluster-heartbeat-slack-time): When this Liberator doesn’t receive an expected cluster heartbeat from another Liberator in the cluster, it waits `cluster-heartbeat-slack-time` seconds before disconnecting from the cluster and trying to reconnect to it.
* [`add-cluster-node`](liberator-clustering-configuration.md#add-cluster-node): Each `add-cluster-node` item defines a Liberator in the cluster by its network interface address and port number. You define all the Liberators in the cluster through a set of `add-cluster-node` items. The set must be in ascending order of the Liberators' `cluster-index` values. You put the `add-cluster-node` items in the configuration of every Liberator in the cluster, so each Liberator identifies every node in the cluster, including itself. You can see that in this example, each of the two Liberators' configurations contains the same set of two `add-cluster-node` items.

**<a name="note-1"></a>Note 1:** For intelligent source routing to work, make sure all the Liberators in the cluster are configured in a compatible way. The source routing works based on the labels given to DataSource peers. So for every Liberator in the cluster, the configuration that defines a particular peer, must use the same `remote-label` name for the peer in the `[`add-peer`](../datasource/datasource-datasource-peers-configuration-part-1.md#add-peer)’s [`remote-label`](../datasource/datasource-datasource-peers-configuration-part-1.md#remote-label) option and in the [data service](../datasource/datasource-data-services.md) definitions ([`add-data-service`](../datasource/datasource-data-services-configuration.md#add-data-service)) that include the Adapter. For example:

```
add-peer
   remote-name fxpriceadapter
   xref:../datasource/datasource-datasource-peers-configuration-part-1.md#remote-label[remote-label]  fxpriceadapter
   ...
end-peer

add-data-service
   service-name fx-prices
   include-pattern ^/FX
   add-source-group
      required
      add-priority
         xref:../datasource/datasource-data-services-configuration.md#remote-label[remote-label] fxpriceadapter
      end-priority
   end-source-group
end-data-service
```

## Clustering Liberators in the Caplin Deployment Framework

The [Caplin Deployment Framework](../deployment-framework/index.md), allows you to easily define a two-Liberator cluster for failover purposes. To enable failover, see How can I... [Set up server failover capability](../deployment-framework/cdf-set-up-server-failover-capability.md) in the Deployment Framework pages. You set up some configuration macro definitions in the `<Framework-root>/global-config/environment.conf` file on the primary and secondary server machines. Setting the macro definitions automatically sets up cluster caching ([`cluster-cache-request-objects`](liberator-clustering-configuration.md#cluster-cache-request-objects) set to `TRUE`), and enables [Intelligent Source Routing](liberator-clustering.md#intelligent-source-routing) ([`cluster-cache-source-routing`](liberator-clustering-configuration.md#cluster-cache-source-routing) set to `TRUE`).

* To change the [`cluster-heartbeat-time`](liberator-clustering-configuration.md#cluster-heartbeat-time), add the macro definition `LIBERATOR_CLUSTER_HEARTBEAT_TIME` to `<Framework-root>/global-config/environment.conf`

  ```
  define LIBERATOR_CLUSTER_HEARTBEAT_TIME <new value>
  ```
* To change the [`cluster-heartbeat-slack-time`](liberator-clustering-configuration.md#cluster-heartbeat-slack-time) from its default, define a value in `<Framework-root>/global_config/overrides/servers/Liberator/etc/cluster.conf`

  ```
  cluster-heartbeat-slack-time <new-value>
  ```
* To change the [`cluster-addr`](liberator-clustering-configuration.md#cluster-addr) settings in the [`add-cluster-node`](liberator-clustering-configuration.md#add-cluster-node) configuration entries:

  The configuration macros `LIBERATOR${THIS_LEG}_HOST` and `LIBERATOR${OTHER_LEG}_HOST` specify the `cluster-addr` values. (These macros are defined in `<Framework-root>/global_config/hosts-defns.conf`)

  You normally use the [`./dfw hosts`](../deployment-framework/cdf-the-deployment-framework-command-utility-dfw.md#hosts) command to set up the hostnames in the macros. See [Configuring server hostnames](../deployment-framework/cdf-set-up-server-failover-capability.md#configuring-server-hostnames) in How can I... [Set up server failover capability](../deployment-framework/cdf-set-up-server-failover-capability.md) and [Change server hostnames](../deployment-framework/cdf-change-server-specific-configuration.md#change-server-hostnames) in How can I ... [Change server-specific configuration](../deployment-framework/cdf-change-server-specific-configuration.md).

  Also see Deployment Framework [Configuration macros and items](../deployment-framework/cdf-configuration-macros-and-items.md).

  If you want to set the `cluster-addr` values directly, edit them in `<Framework-root>/global_config/overrides/servers/Liberator/etc/cluster.conf`
* To change the [`cluster-port`](liberator-clustering-configuration.md#cluster-port) settings in the [`add-cluster-node`](liberator-clustering-configuration.md#add-cluster-node) configuration entries, put new values for the configuration macros `LIBERATOR${THIS_LEG}_CLUSTER_PORT` and `LIBERATOR${OTHER_LEG}_CLUSTER_PORT` in the `<Framework-root>/global_config/overrides/servers/Liberator/etc/cluster.conf` file.

  For example:

  ```
  define LIBERATOR${THIS_LEG}_CLUSTER_PORT   ${THIS_LEG}6003
  define LIBERATOR${OTHER_LEG}_CLUSTER_PORT  ${OTHER_LEG}6003
  ```

  where the value `6003` is the new base port number, replacing the default value `6001`.

**📌 NOTE**\
If you want to set up a cluster of more than two Liberators within the Deployment Framework, **please contact Caplin Support** for advice on how to do this.

---

**See also:**

* Liberator Features and Concepts: [Clustering](liberator-clustering.md)
* Reference: [Clustering configuration](liberator-clustering-configuration.md)
* Reference: [DataSource peers configuration](../datasource/datasource-datasource-peers-configuration-part-1.md)
* Reference: [Data services configuration](../datasource/datasource-data-services-configuration.md)
* Reference: [Deployment Framework configuration macros and items](../deployment-framework/cdf-configuration-macros-and-items.md)
