reroute.asciidoc 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. [[cluster-reroute]]
  2. === Cluster reroute API
  3. ++++
  4. <titleabbrev>Cluster reroute</titleabbrev>
  5. ++++
  6. Changes the allocation of shards in a cluster.
  7. [[cluster-reroute-api-request]]
  8. ==== {api-request-title}
  9. `POST /_cluster/reroute`
  10. [[cluster-reroute-api-desc]]
  11. ==== {api-description-title}
  12. The reroute command allows for manual changes to the allocation of individual
  13. shards in the cluster. For example, a shard can be moved from one node to
  14. another explicitly, an allocation can be cancelled, and an unassigned shard can
  15. be explicitly allocated to a specific node.
  16. It is important to note that after processing any reroute commands {es} will
  17. perform rebalancing as normal (respecting the values of settings such as
  18. `cluster.routing.rebalance.enable`) in order to remain in a balanced state. For
  19. example, if the requested allocation includes moving a shard from `node1` to
  20. `node2` then this may cause a shard to be moved from `node2` back to `node1` to
  21. even things out.
  22. The cluster can be set to disable allocations using the
  23. `cluster.routing.allocation.enable` setting. If allocations are disabled then
  24. the only allocations that will be performed are explicit ones given using the
  25. `reroute` command, and consequent allocations due to rebalancing.
  26. It is possible to run `reroute` commands in "dry run" mode by using the
  27. `?dry_run` URI query parameter, or by passing `"dry_run": true` in the request
  28. body. This will calculate the result of applying the commands to the current
  29. cluster state, and return the resulting cluster state after the commands (and
  30. re-balancing) has been applied, but will not actually perform the requested
  31. changes.
  32. If the `?explain` URI query parameter is included then a detailed explanation
  33. of why the commands could or could not be executed is included in the response.
  34. The cluster will attempt to allocate a shard a maximum of
  35. `index.allocation.max_retries` times in a row (defaults to `5`), before giving
  36. up and leaving the shard unallocated. This scenario can be caused by
  37. structural problems such as having an analyzer which refers to a stopwords
  38. file which doesn't exist on all nodes.
  39. Once the problem has been corrected, allocation can be manually retried by
  40. calling the `reroute` API with the `?retry_failed` URI
  41. query parameter, which will attempt a single retry round for these shards.
  42. [[cluster-reroute-api-query-params]]
  43. [role="child_attributes"]
  44. ==== {api-query-parms-title}
  45. `dry_run`::
  46. (Optional, boolean) If `true`, then the request simulates the operation only
  47. and returns the resulting state.
  48. `explain`::
  49. (Optional, boolean) If `true`, then the response contains an explanation of
  50. why the commands can or cannot be executed.
  51. `metric`::
  52. (Optional, string) Limits the information returned to the specified metrics.
  53. Defaults to all but metadata The following options are available:
  54. +
  55. .Options for `metric`
  56. [%collapsible%open]
  57. ======
  58. `_all`::
  59. Shows all metrics.
  60. `blocks`::
  61. Shows the `blocks` part of the response.
  62. `master_node`::
  63. Shows the elected `master_node` part of the response.
  64. `metadata`::
  65. Shows the `metadata` part of the response. If you supply a comma separated
  66. list of indices, the returned output will only contain metadata for these
  67. indices.
  68. `nodes`::
  69. Shows the `nodes` part of the response.
  70. `routing_table`::
  71. Shows the `routing_table` part of the response.
  72. `version`::
  73. Shows the cluster state version.
  74. ======
  75. `retry_failed`::
  76. (Optional, boolean) If `true`, then retries allocation of shards that are
  77. blocked due to too many subsequent allocation failures.
  78. include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=timeoutparms]
  79. [role="child_attributes"]
  80. [[cluster-reroute-api-request-body]]
  81. ==== {api-request-body-title}
  82. `commands`::
  83. (Required, array of objects) Defines the commands to perform. Supported commands are:
  84. +
  85. .Properties of `commands`
  86. [%collapsible%open]
  87. ======
  88. `move`::
  89. Move a started shard from one node to another node. Accepts `index` and
  90. `shard` for index name and shard number, `from_node` for the node to move
  91. the shard from, and `to_node` for the node to move the shard to.
  92. `cancel`::
  93. Cancel allocation of a shard (or recovery). Accepts `index` and `shard` for
  94. index name and shard number, and `node` for the node to cancel the shard
  95. allocation on. This can be used to force resynchronization of existing
  96. replicas from the primary shard by cancelling them and allowing them to be
  97. reinitialized through the standard recovery process. By default only
  98. replica shard allocations can be cancelled. If it is necessary to cancel
  99. the allocation of a primary shard then the `allow_primary` flag must also
  100. be included in the request.
  101. `allocate_replica`::
  102. Allocate an unassigned replica shard to a node. Accepts `index` and `shard`
  103. for index name and shard number, and `node` to allocate the shard to. Takes
  104. <<modules-cluster,allocation deciders>> into account.
  105. Two more commands are available that allow the allocation of a primary shard to
  106. a node. These commands should however be used with extreme care, as primary
  107. shard allocation is usually fully automatically handled by {es}. Reasons why a
  108. primary shard cannot be automatically allocated include the
  109. following:
  110. - A new index was created but there is no node which satisfies the allocation
  111. deciders.
  112. - An up-to-date shard copy of the data cannot be found on the current data
  113. nodes in the cluster. To prevent data loss, the system does not automatically
  114. promote a stale shard copy to primary.
  115. The following two commands are dangerous and may result in data loss. They are
  116. meant to be used in cases where the original data can not be recovered and the
  117. cluster administrator accepts the loss. If you have suffered a temporary issue
  118. that can be fixed, please see the `retry_failed` flag described above. To
  119. emphasise: if these commands are performed and then a node joins the cluster
  120. that holds a copy of the affected shard then the copy on the newly-joined node
  121. will be deleted or overwritten.
  122. `allocate_stale_primary`::
  123. Allocate a primary shard to a node that holds a stale copy. Accepts the
  124. `index` and `shard` for index name and shard number, and `node` to allocate
  125. the shard to. Using this command may lead to data loss for the provided
  126. shard id. If a node which has the good copy of the data rejoins the cluster
  127. later on, that data will be deleted or overwritten with the data of the
  128. stale copy that was forcefully allocated with this command. To ensure that
  129. these implications are well-understood, this command requires the flag
  130. `accept_data_loss` to be explicitly set to `true`.
  131. `allocate_empty_primary`::
  132. Allocate an empty primary shard to a node. Accepts the `index` and `shard`
  133. for index name and shard number, and `node` to allocate the shard to. Using
  134. this command leads to a complete loss of all data that was indexed into
  135. this shard, if it was previously started. If a node which has a copy of the
  136. data rejoins the cluster later on, that data will be deleted. To ensure
  137. that these implications are well-understood, this command requires the flag
  138. `accept_data_loss` to be explicitly set to `true`.
  139. ======
  140. [[cluster-reroute-api-example]]
  141. ==== {api-examples-title}
  142. This is a short example of a simple reroute API call:
  143. [source,console]
  144. --------------------------------------------------
  145. POST /_cluster/reroute
  146. {
  147. "commands" : [
  148. {
  149. "move" : {
  150. "index" : "test", "shard" : 0,
  151. "from_node" : "node1", "to_node" : "node2"
  152. }
  153. },
  154. {
  155. "allocate_replica" : {
  156. "index" : "test", "shard" : 1,
  157. "node" : "node3"
  158. }
  159. }
  160. ]
  161. }
  162. --------------------------------------------------
  163. // TEST[skip:doc tests run with only a single node]