reroute.asciidoc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. [[cluster-reroute]]
  2. == Cluster Reroute
  3. The reroute command allows for manual changes to the allocation of individual
  4. shards in the cluster. For example, a shard can be moved from one node to
  5. another explicitly, an allocation can be cancelled, and an unassigned shard can
  6. be explicitly allocated to a specific node.
  7. Here is a short example of a simple reroute API call:
  8. [source,js]
  9. --------------------------------------------------
  10. POST /_cluster/reroute
  11. {
  12. "commands" : [
  13. {
  14. "move" : {
  15. "index" : "test", "shard" : 0,
  16. "from_node" : "node1", "to_node" : "node2"
  17. }
  18. },
  19. {
  20. "allocate_replica" : {
  21. "index" : "test", "shard" : 1,
  22. "node" : "node3"
  23. }
  24. }
  25. ]
  26. }
  27. --------------------------------------------------
  28. // CONSOLE
  29. // TEST[skip:doc tests run with only a single node]
  30. It is important to note that after processing any reroute commands
  31. Elasticsearch will perform rebalancing as normal (respecting the values of
  32. settings such as `cluster.routing.rebalance.enable`) in order to remain in a
  33. balanced state. For example, if the requested allocation includes moving a
  34. shard from `node1` to `node2` then this may cause a shard to be moved from
  35. `node2` back to `node1` to even things out.
  36. The cluster can be set to disable allocations using the
  37. `cluster.routing.allocation.enable` setting. If allocations are disabled then
  38. the only allocations that will be performed are explicit ones given using the
  39. `reroute` command, and consequent allocations due to rebalancing.
  40. It is possible to run `reroute` commands in "dry run" mode by using the
  41. `?dry_run` URI query parameter, or by passing `"dry_run": true` in the request
  42. body. This will calculate the result of applying the commands to the current
  43. cluster state, and return the resulting cluster state after the commands (and
  44. re-balancing) has been applied, but will not actually perform the requested
  45. changes.
  46. If the `?explain` URI query parameter is included then a detailed explanation
  47. of why the commands could or could not be executed is included in the response.
  48. The commands supported are:
  49. `move`::
  50. Move a started shard from one node to another node. Accepts
  51. `index` and `shard` for index name and shard number, `from_node` for the
  52. node to move the shard from, and `to_node` for the node to move the
  53. shard to.
  54. `cancel`::
  55. Cancel allocation of a shard (or recovery). Accepts `index` and `shard` for
  56. index name and shard number, and `node` for the node to cancel the shard
  57. allocation on. This can be used to force resynchronization of existing
  58. replicas from the primary shard by cancelling them and allowing them to be
  59. reinitialized through the standard recovery process. By default only
  60. replica shard allocations can be cancelled. If it is necessary to cancel
  61. the allocation of a primary shard then the `allow_primary` flag must also
  62. be included in the request.
  63. `allocate_replica`::
  64. Allocate an unassigned replica shard to a node. Accepts `index` and `shard`
  65. for index name and shard number, and `node` to allocate the shard to. Takes
  66. <<modules-cluster,allocation deciders>> into account.
  67. [float]
  68. === Retrying failed allocations
  69. The cluster will attempt to allocate a shard a maximum of
  70. `index.allocation.max_retries` times in a row (defaults to `5`), before giving
  71. up and leaving the shard unallocated. This scenario can be caused by
  72. structural problems such as having an analyzer which refers to a stopwords
  73. file which doesn't exist on all nodes.
  74. Once the problem has been corrected, allocation can be manually retried by
  75. calling the <<cluster-reroute,`reroute`>> API with the `?retry_failed` URI
  76. query parameter, which will attempt a single retry round for these shards.
  77. [float]
  78. === Forced allocation on unrecoverable errors
  79. Two more commands are available that allow the allocation of a primary shard to
  80. a node. These commands should however be used with extreme care, as primary
  81. shard allocation is usually fully automatically handled by Elasticsearch.
  82. Reasons why a primary shard cannot be automatically allocated include the
  83. following:
  84. - A new index was created but there is no node which satisfies the allocation
  85. deciders.
  86. - An up-to-date shard copy of the data cannot be found on the current data
  87. nodes in the cluster. To prevent data loss, the system does not automatically
  88. promote a stale shard copy to primary.
  89. The following two commands are dangerous and may result in data loss. They are
  90. meant to be used in cases where the original data can not be recovered and the
  91. cluster administrator accepts the loss. If you have suffered a temporary issue
  92. that can be fixed, please see the `retry_failed` flag described above. To
  93. emphasise: if these commands are performed and then a node joins the cluster
  94. that holds a copy of the affected shard then the copy on the newly-joined node
  95. will be deleted or overwritten.
  96. `allocate_stale_primary`::
  97. Allocate a primary shard to a node that holds a stale copy. Accepts the
  98. `index` and `shard` for index name and shard number, and `node` to allocate
  99. the shard to. Using this command may lead to data loss for the provided
  100. shard id. If a node which has the good copy of the data rejoins the cluster
  101. later on, that data will be deleted or overwritten with the data of the
  102. stale copy that was forcefully allocated with this command. To ensure that
  103. these implications are well-understood, this command requires the flag
  104. `accept_data_loss` to be explicitly set to `true`.
  105. `allocate_empty_primary`::
  106. Allocate an empty primary shard to a node. Accepts the `index` and `shard`
  107. for index name and shard number, and `node` to allocate the shard to. Using
  108. this command leads to a complete loss of all data that was indexed into
  109. this shard, if it was previously started. If a node which has a copy of the
  110. data rejoins the cluster later on, that data will be deleted. To ensure
  111. that these implications are well-understood, this command requires the flag
  112. `accept_data_loss` to be explicitly set to `true`.