To create a replication cluster, you must set its name at a minimum.
If you are creating a single cluster or the first cluster, you may omit the path option. In this case, the data_dir option will be used as the cluster path. However, for all subsequent clusters, you must specify the path and the path must be available. The nodes option may also be set to list all nodes in the cluster.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
CREATE CLUSTER posts
CREATE CLUSTER click_query '/var/data/click_query/' as path
CREATE CLUSTER click_query '/var/data/click_query/' as path, 'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312' as nodes
POST /cli -d "
CREATE CLUSTER posts
"
POST /cli -d "
CREATE CLUSTER click_query '/var/data/click_query/' as path
"
POST /cli -d "
CREATE CLUSTER click_query '/var/data/click_query/' as path, 'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312' as nodes
"
$params = [
'cluster' => 'posts',
]
];
$response = $client->cluster()->create($params);
$params = [
'cluster' => 'click_query',
'body' => [
'path' => '/var/data/click_query/'
]
]
];
$response = $client->cluster()->create($params);
$params = [
'cluster' => 'click_query',
'body' => [
'path' => '/var/data/click_query/',
'nodes' => 'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312'
]
]
];
$response = $client->cluster()->create($params);
utilsApi.sql('CREATE CLUSTER posts')
utilsApi.sql('CREATE CLUSTER click_query \'/var/data/click_query/\' as path')
utilsApi.sql('CREATE CLUSTER click_query \'/var/data/click_query/\' as path, \'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312\' as nodes')
res = await utilsApi.sql('CREATE CLUSTER posts');
res = await utilsApi.sql('CREATE CLUSTER click_query \'/var/data/click_query/\' as path');
res = await utilsApi.sql('CREATE CLUSTER click_query \'/var/data/click_query/\' as path, \'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312\' as nodes');
utilsApi.sql("CREATE CLUSTER posts");
utilsApi.sql("CREATE CLUSTER click_query '/var/data/click_query/' as path");
utilsApi.sql("CREATE CLUSTER click_query '/var/data/click_query/' as path, 'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312' as nodes");
utilsApi.Sql("CREATE CLUSTER posts");
utilsApi.Sql("CREATE CLUSTER click_query '/var/data/click_query/' as path");
utilsApi.Sql("CREATE CLUSTER click_query '/var/data/click_query/' as path, 'clicks_mirror1:9312,clicks_mirror2:9312,clicks_mirror3:9312' as nodes");
If the nodes option is not specified when creating a cluster, the first node that joins the cluster will be saved as the nodes option.
To join an existing cluster, you must specify at least:
- The nameof the cluster
- The
host:port
of another node in the cluster you are joining
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
JOIN CLUSTER posts AT '10.12.1.35:9312'
POST /cli -d "
JOIN CLUSTER posts AT '10.12.1.35:9312'
"
$params = [
'cluster' => 'posts',
'body' => [
'10.12.1.35:9312'
]
];
$response = $client->cluster->join($params);
utilsApi.sql('JOIN CLUSTER posts AT \'10.12.1.35:9312\'')
res = await utilsApi.sql('JOIN CLUSTER posts AT \'10.12.1.35:9312\'');
utilsApi.sql("JOIN CLUSTER posts AT '10.12.1.35:9312'");
utilsApi.Sql("JOIN CLUSTER posts AT '10.12.1.35:9312'");
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
In most cases, the above is sufficient when there is a single replication cluster. However, if you are creating multiple replication clusters, you must also set the path and ensure that the directory is available.
- SQL
JOIN CLUSTER c2 at '127.0.0.1:10201' 'c2' as path
A node joins a cluster by obtaining data from a specified node and, if successful, updates the node lists across all other cluster nodes in the same way as if it was done manually through ALTER CLUSTER ... UPDATE nodes. This list is used to re-join nodes to the cluster upon restart.
There are two lists of nodes:
1.cluster_<name>_nodes_set
: used to re-join nodes to the cluster upon restart. It is updated across all nodes in the same way as ALTER CLUSTER ... UPDATE nodes does. JOIN CLUSTER
command performs this update automatically. The Cluster status displays this list as cluster_<name>_nodes_set
.
2. cluster_<name>_nodes_view
: this list contains all active nodes used for replication and does not require manual management. ALTER CLUSTER ... UPDATE nodes actually copies this list of nodes to the list of nodes used to re-join upon restart. The Cluster status displays this list as cluster_<name>_nodes_view
.
When nodes are located in different network segments or data centers, the nodes option may be set explicitly. This minimizes traffic between nodes and utilizes gateway nodes for intercommunication between data centers. The following code joins an existing cluster using the nodes option.
Note: The cluster
cluster_<name>_nodes_set
list is not updated automatically when this syntax is used. To update it, use ALTER CLUSTER ... UPDATE nodes.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
JOIN CLUSTER click_query 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312' as nodes
POST /cli -d "
JOIN CLUSTER click_query 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312' as nodes
"
$params = [
'cluster' => 'posts',
'body' => [
'nodes' => 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312'
]
];
$response = $client->cluster->join($params);
utilsApi.sql('JOIN CLUSTER click_query \'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312\' as nodes')
res = await utilsApi.sql('JOIN CLUSTER click_query \'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312\' as nodes');
utilsApi.sql("JOIN CLUSTER click_query 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312' as nodes");
utilsApi.Sql("JOIN CLUSTER click_query 'clicks_mirror1:9312;clicks_mirror2:9312;clicks_mirror3:9312' as nodes");
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
The JOIN CLUSTER
command 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.
The DELETE CLUSTER
statement removes the specified cluster with its name. Once the cluster is deleted, it is removed from all nodes, but its tables remain intact and become active local non-replicated tables.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
DELETE CLUSTER click_query
POST /cli -d "DELETE CLUSTER click_query"
$params = [
'cluster' => 'click_query',
'body' => []
];
$response = $client->cluster()->delete($params);
utilsApi.sql('DELETE CLUSTER click_query')
res = await utilsApi.sql('DELETE CLUSTER click_query');
utilsApi.sql("DELETE CLUSTER click_query");
utilsApi.Sql("DELETE CLUSTER click_query");
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
ALTER CLUSTER <cluster_name> ADD <table_name>[, <table_name>]
adds one or more existing local tables to the cluster. The node that receives the ALTER query sends the table(s) to the other nodes in the cluster. All the local tables with the same name on the other nodes of the cluster are replaced with the new table(s).
Once the tables are replicated, write statements can be performed on any node, but the table names must be prefixed with the cluster name, like INSERT INTO <clusterName>:<table_name>
.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
ALTER CLUSTER click_query ADD clicks_daily_index
POST /cli -d "
ALTER CLUSTER click_query ADD clicks_daily_index
"
$params = [
'cluster' => 'click_query',
'body' => [
'operation' => 'add',
'table' => 'clicks_daily_index'
]
];
$response = $client->cluster()->alter($params);
utilsApi.sql('ALTER CLUSTER click_query ADD clicks_daily_index')
res = await utilsApi.sql('ALTER CLUSTER click_query ADD clicks_daily_index');
utilsApi.sql("ALTER CLUSTER click_query ADD clicks_daily_index");
utilsApi.Sql("ALTER CLUSTER click_query ADD clicks_daily_index");
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
ALTER CLUSTER <cluster_name> DROP <table_name>[, <table_name>]
forgets about one or more existing table(s), meaning it does not remove the table(s) files on the nodes, but rather just makes them inactive, non-replicated table(s).
Once a table is removed from a cluster, it becomes a local
table, and write statements must use just the table name, like INSERT INTO <table_name>
, without the cluster prefix.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
- C#
ALTER CLUSTER posts DROP weekly_index
POST /cli -d "
ALTER CLUSTER posts DROP weekly_index
"
$params = [
'cluster' => 'posts',
'body' => [
'operation' => 'drop',
'table' => 'weekly_index'
]
];
$response = $client->cluster->alter($params);
utilsApi.sql('ALTER CLUSTER posts DROP weekly_index')
res = await utilsApi.sql('ALTER CLUSTER posts DROP weekly_index');
utilsApi.sql("ALTER CLUSTER posts DROP weekly_index");
utilsApi.Sql("ALTER CLUSTER posts DROP weekly_index");
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}