Deleting a replication cluster
Delete statement removes a cluster specified with name. The cluster gets removed from all the nodes, but its tables are left intact and become active local non-replicated tables.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
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");
Response
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
Adding and removing a table from a replication cluster
ALTER CLUSTER <cluster_name> ADD <table_name>
adds an existing local table to the cluster. The node which receives the ALTER query sends the table to the other nodes in the cluster. All the local tables with the same name on the other nodes of the cluster get replaced with the new table.
After the table is replicated, write statements can be performed on any node but table name must be prefixed with the cluster name like INSERT INTO <clusterName>:<table_name>
.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
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',
'index' => '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");
Response
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
ALTER CLUSTER <cluster_name> DROP <table_name>
forgets about a local table, i.e., it doesn’t remove the table files on the nodes but just makes it an active non-replicated table.
After a table is removed from a cluster, it becomes a ‘local’ table and write statements must use just the table name as INSERT INTO <table_name>
, without the cluster prefix.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
ALTER CLUSTER posts DROP weekly_index
POST /cli -d "
ALTER CLUSTER posts DROP weekly_index
"
$params = [
'cluster' => 'posts',
'body' => [
'operation' => 'drop',
'index' => '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");
Response
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
Managing replication nodes
ALTER CLUSTER <cluster_name> UPDATE nodes
statement updates node lists on each node of the cluster to include every active node in the cluster. See Joining a cluster for more info on node lists.
- SQL
- JSON
- PHP
- Python
- javascript
- Java
SQL JSON PHP Python javascript Java
ALTER CLUSTER posts UPDATE nodes
POST /cli -d "
ALTER CLUSTER posts UPDATE nodes
"
$params = [
'cluster' => 'posts',
'body' => [
'operation' => 'update',
]
];
$response = $client->cluster()->alter($params);
utilsApi.sql('ALTER CLUSTER posts UPDATE nodes')
res = await utilsApi.sql('ALTER CLUSTER posts UPDATE nodes');
utilsApi.sql("ALTER CLUSTER posts UPDATE nodes");
Response
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
For example, when the cluster was initially created, the list of nodes used for rejoining the cluster was 10.10.0.1:9312,10.10.1.1:9312
. Since then other nodes joined the cluster and now we have the following active nodes: 10.10.0.1:9312,10.10.1.1:9312,10.15.0.1:9312,10.15.0.3:9312
.
But the list of nodes used for rejoining the cluster is still the same. Running the ALTER CLUSTER ... UPDATE nodes
copies the list of active nodes to the list of nodes used to rejoin on restart. After this, the list of nodes used on restart includes all the active nodes in the cluster.
Both lists of nodes can be viewed using Cluster status statement (cluster_post_nodes_set
and cluster_post_nodes_view
).
Removing node from cluster
To remove a node from a replication cluster you need to:
- stop the node
- remove info about the cluster in
<data_dir>/manticore.json
(/var/lib/manticore/manticore.json
in most cases) on the node you’ve stopped - run
ALTER CLUSTER cluster_name UPDATE nodes
on any other node
After this the other nodes will forget about the detached node and the node will forget about the cluster. It won’t impact tables neither in the cluster nor on the detached node.