reroute.asciidoc 7.5 KB

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