Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quick recovery after node restart in elasticsearch

Consider the below settings in the elasticsearch.yml

gateway.recover_after_data_nodes: 3
gateway.recover_after_time: 5m
gateway.expected_data_nodes: 3

Current setting: Say, I have 3 data nodes. Now if I decide to restart a data node(due to a small change in setting), the recovery will start immediately after node restart as per the expected_data_nodes setting. There will be many unassigned shards, which will get allocated slowly depending on the data it contains.

In order to avoid that, is there any way to allocate all the unassigned shards to a specific node?(in my case the restarted node) and once that is done, ES should take over the rebalancing.

Mainly I want to avoid the heavy timelag of the cluster state from yellow to green.(it is in the range of hours in my case)

Can I use the cluster reroute api for this purpose?

or is there any other api to transfer all the unassigned shards to specific node at one go?

like image 972
Vamsi Krishna Avatar asked Apr 26 '13 08:04

Vamsi Krishna


People also ask

How do I reset Elasticsearch nodes?

The correct way to restart a node is to shut it down, using either the shutdown API or sending a TERM signal to the process (eg with kill $PID ). Once shut down, you can start a new node using whatever you use to run elasticsearch, eg the service wrapper, or just starting it from the command line.

What happens when an Elasticsearch node goes down?

If a data node goes down for some reason, all of its shards will become “unassigned shards” and Elasticsearch will try to assign them on different nodes (by duplicating other replicas of those shards). During that time, the cluster state might be red or yellow.

What is Elasticsearch recovery?

In Elasticsearch, recovery refers to the process of recovering an index or shard when something goes wrong. There are many ways to recover an index or shard, such as by re-indexing the data from a backup / failover cluster to the current one, or by restoring from an Elasticsearch snapshot.


1 Answers

For Elasticsearch version >= 1.0.0:

curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.enable": "none"}}'
/etc/init.d/elasticsearch restart
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.enable": "all"}}'

For earlier version of ES:

curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.disable_allocation": true}}'
/etc/init.d/elasticsearch restart
curl -XPUT localhost:9200/_cluster/settings -d '{"transient":{"cluster.routing.allocation.disable_allocation": false}}'

Shard keep unallocated until "cluster.routing.allocation.disable_allocation": false, then shards recover on the server just restarted (starting at size they were before shutdown) It is very quick.

Reference: http://elasticsearch-users.115913.n3.nabble.com/quick-recovery-after-node-restart-in-elasticsearch-td4033876.html#a4034211

like image 161
Vamsi Krishna Avatar answered Oct 06 '22 00:10

Vamsi Krishna