reroute.asciidoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. [[cluster-reroute]]
  2. == Cluster Reroute
  3. The reroute command allows to explicitly execute a cluster reroute
  4. allocation command including specific commands. For example, a shard can
  5. be moved from one node to another explicitly, an allocation can be
  6. canceled, or an unassigned shard can be explicitly allocated on a
  7. specific node.
  8. Here is a short example of how a simple reroute API call:
  9. [source,js]
  10. --------------------------------------------------
  11. POST /_cluster/reroute
  12. {
  13. "commands" : [
  14. {
  15. "move" : {
  16. "index" : "test", "shard" : 0,
  17. "from_node" : "node1", "to_node" : "node2"
  18. }
  19. },
  20. {
  21. "allocate_replica" : {
  22. "index" : "test", "shard" : 1,
  23. "node" : "node3"
  24. }
  25. }
  26. ]
  27. }
  28. --------------------------------------------------
  29. // CONSOLE
  30. // TEST[skip:doc tests run with only a single node]
  31. An important aspect to remember is the fact that once when an allocation
  32. occurs, the cluster will aim at re-balancing its state back to an even
  33. state. For example, if the allocation includes moving a shard from
  34. `node1` to `node2`, in an `even` state, then another shard will be moved
  35. from `node2` to `node1` to even things out.
  36. The cluster can be set to disable allocations, which means that only the
  37. explicitly allocations will be performed. Obviously, only once all
  38. commands has been applied, the cluster will aim to be re-balance its
  39. state.
  40. Another option is to run the commands in `dry_run` (as a URI flag, or in
  41. the request body). This will cause the commands to apply to the current
  42. cluster state, and return the resulting cluster after the commands (and
  43. re-balancing) has been applied.
  44. If the `explain` parameter is specified, a detailed explanation of why the
  45. commands could or could not be executed is returned.
  46. The commands supported are:
  47. `move`::
  48. Move a started shard from one node to another node. Accepts
  49. `index` and `shard` for index name and shard number, `from_node` for the
  50. node to move the shard `from`, and `to_node` for the node to move the
  51. shard to.
  52. `cancel`::
  53. Cancel allocation of a shard (or recovery). Accepts `index`
  54. and `shard` for index name and shard number, and `node` for the node to
  55. cancel the shard allocation on. It also accepts `allow_primary` flag to
  56. explicitly specify that it is allowed to cancel allocation for a primary
  57. shard. This can be used to force resynchronization of existing replicas
  58. from the primary shard by cancelling them and allowing them to be
  59. reinitialized through the standard reallocation process.
  60. `allocate_replica`::
  61. Allocate an unassigned replica shard to a node. Accepts the
  62. `index` and `shard` for index name and shard number, and `node` to
  63. allocate the shard to. Takes <<modules-cluster,allocation deciders>> into account.
  64. Two more commands are available that allow the allocation of a primary shard
  65. to a node. These commands should however be used with extreme care, as primary
  66. shard allocation is usually fully automatically handled by Elasticsearch.
  67. Reasons why a primary shard cannot be automatically allocated include the following:
  68. - A new index was created but there is no node which satisfies the allocation deciders.
  69. - An up-to-date shard copy of the data cannot be found on the current data nodes in
  70. the cluster. To prevent data loss, the system does not automatically promote a stale
  71. shard copy to primary.
  72. As a manual override, two commands to forcefully allocate primary shards
  73. are available:
  74. `allocate_stale_primary`::
  75. Allocate a primary shard to a node that holds a stale copy. Accepts the
  76. `index` and `shard` for index name and shard number, and `node` to
  77. allocate the shard to. Using this command may lead to data loss
  78. for the provided shard id. If a node which has the good copy of the
  79. data rejoins the cluster later on, that data will be overwritten with
  80. the data of the stale copy that was forcefully allocated with this
  81. command. To ensure that these implications are well-understood,
  82. this command requires the special field `accept_data_loss` to be
  83. explicitly set to `true` for it to work.
  84. `allocate_empty_primary`::
  85. Allocate an empty primary shard to a node. Accepts the
  86. `index` and `shard` for index name and shard number, and `node` to
  87. allocate the shard to. Using this command leads to a complete loss
  88. of all data that was indexed into this shard, if it was previously
  89. started. If a node which has a copy of the
  90. data rejoins the cluster later on, that data will be deleted!
  91. To ensure that these implications are well-understood,
  92. this command requires the special field `accept_data_loss` to be
  93. explicitly set to `true` for it to work.
  94. [float]
  95. === Retry failed shards
  96. The cluster will attempt to allocate a shard a maximum of
  97. `index.allocation.max_retries` times in a row (defaults to `5`), before giving
  98. up and leaving the shard unallocated. This scenario can be caused by
  99. structural problems such as having an analyzer which refers to a stopwords
  100. file which doesn't exist on all nodes.
  101. Once the problem has been corrected, allocation can be manually retried by
  102. calling the <<cluster-reroute,`reroute`>> API with `?retry_failed`, which
  103. will attempt a single retry round for these shards.