Joining a replication cluster

To join an existing cluster you should specify at least:

  • name
  • and host:port of another working node of the cluster you are joining
‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
JOIN CLUSTER posts AT '10.12.1.35:9312'
‹›
Response
{u'error': u'', u'total': 0, u'warning': u''}

In case of a single replication cluster, i.e. in most cases the above is just enough. In case you are creating multiple replication clusters path needs to be set as well and the directory should be available.

‹›
  • SQL
SQL
📋
JOIN CLUSTER c2 at '127.0.0.1:10201' 'c2' as path

A node joins a cluster by getting data from another specified node and, if successful, it updates node lists in all other cluster nodes similar to how it's done manually via ALTER CLUSTER ... UPDATE nodes. This list is used to rejoin nodes to the cluster on restart.

There are two lists of nodes:

  • cluster_<name>_nodes_set: used to rejoin nodes to the cluster on restart, it is updated across all nodes same way as ALTER CLUSTER ... UPDATE nodes does. JOIN CLUSTER does the same update automatically. Cluster status shows this list as cluster_<name>_nodes_set.
  • cluster_<name>_nodes_view: list of all active nodes used for replication. This list doesn't require manual management. ALTER CLUSTER ... UPDATE nodes actually copies this list of nodes to the list of nodes used to rejoin on restart. Cluster status shows this list as cluster_<name>_nodes_view.

When nodes are located in different network segments or in different datacenters, nodes option may be set explicitly. That allows to minimize traffic between nodes and to use gateway nodes for datacenters intercommunication. The following command joins an existing cluster using the nodes option.

Note: that when this syntax is used, cluster_<name>_nodes_set list is not updated automatically. Use ALTER CLUSTER ... UPDATE nodes to update it.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
JOIN CLUSTER click_query 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312' as nodes
‹›
Response
{u'error': u'', u'total': 0, u'warning': u''}

JOIN CLUSTER works synchronously and completes as soon as the node receives all data from the other nodes in the cluster and is in sync with them.

Deleting a replication cluster

Delete statement removes a cluster specified with name. The cluster gets removed from all the nodes, but its indexes are left intact and become active local non-replicated indexes.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
DELETE CLUSTER click_query
‹›
Response
{u'error': u'', u'total': 0, u'warning': u''}

Adding and removing an index from a replication cluster

ALTER CLUSTER <cluster_name> ADD <index_name> adds an existing local index to the cluster. The node which receives the ALTER query sends the index to the other nodes in the cluster. All the local indexes with the same name on the other nodes of the cluster get replaced with the new index.

After the index is replicated, write statements can be performed on any node but index name must be prefixed with the cluster name like INSERT INTO <clusterName>:<indexName>.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
ALTER CLUSTER click_query ADD clicks_daily_index
‹›
Response
{u'error': u'', u'total': 0, u'warning': u''}

ALTER CLUSTER <cluster_name> DROP <index_name> forgets about a local index, i.e., it doesn't remove the index files on the nodes but just makes it an active non-replicated index.

After an index is removed from a cluster, it becomes a 'local' index and write statements must use just the index name as INSERT INTO <indexName>, without the cluster prefix.

‹›
  • SQL
  • HTTP
  • PHP
  • Python
  • javascript
  • Java
📋
ALTER CLUSTER posts DROP weekly_index
‹›
Response
{u'error': u'', u'total': 0, u'warning': u''}