Cluster Allocation Explain API

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.0/cluster-allocation-explain.html

译文链接 : http://www.apache.wiki/display/Elasticsearch/Cluster+Allocation+Explain+API

贡献者 : 那伊抹微笑

cluster allocation explanation API 的目的是帮助回答这个问题 “为什么这个分片没有被分配”。为了说明分片的分配(未分配状态),发出一个这样的请求 :

  1. $ curl -XGET 'http://localhost:9200/_cluster/allocation/explain' -d'{
  2. "index": "myindex",
  3. "shard": 0,
  4. "primary": false
  5. }'

指定您希望查看的说明的 indexshardid,和 primary 标记一样来指出是否 explain 一个主或者副本分片。

该响应如下 :

  1. {
  2. "shard" : {
  3. "index" : "myindex",
  4. "index_uuid" : "KnW0-zELRs6PK84l0r38ZA",
  5. "id" : 0,
  6. "primary" : false
  7. },
  8. "assigned" : false,
  9. "shard_state_fetch_pending": false,
  10. "unassigned_info" : {
  11. "reason" : "INDEX_CREATED",
  12. "at" : "2016-03-22T20:04:23.620Z"
  13. },
  14. "allocation_delay_ms" : 0,
  15. "remaining_delay_ms" : 0,
  16. "nodes" : {
  17. "V-Spi0AyRZ6ZvKbaI3691w" : {
  18. "node_name" : "H5dfFeA",
  19. "node_attributes" : {
  20. "bar" : "baz"
  21. },
  22. "store" : {
  23. "shard_copy" : "NONE"
  24. },
  25. "final_decision" : "NO",
  26. "final_explanation" : "the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
  27. "weight" : 0.06666675,
  28. "decisions" : [ {
  29. "decider" : "filter",
  30. "decision" : "NO",
  31. "explanation" : "node does not match index include filters [foo:\"bar\"]"
  32. } ]
  33. },
  34. "Qc6VL8c5RWaw1qXZ0Rg57g" : {
  35. "node_name" : "bGG90GE",
  36. "node_attributes" : {
  37. "bar" : "baz",
  38. "foo" : "bar"
  39. },
  40. "store" : {
  41. "shard_copy" : "AVAILABLE"
  42. },
  43. "final_decision" : "NO",
  44. "final_explanation" : "the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
  45. "weight" : -1.3833332,
  46. "decisions" : [ {
  47. "decider" : "same_shard",
  48. "decision" : "NO",
  49. "explanation" : "the shard cannot be allocated on the same node id [Qc6VL8c5RWaw1qXZ0Rg57g] on which it already exists"
  50. } ]
  51. },
  52. "PzdyMZGXQdGhqTJHF_hGgA" : {
  53. "node_name" : "DKDM97B",
  54. "node_attributes" : { },
  55. "store" : {
  56. "shard_copy" : "NONE"
  57. },
  58. "final_decision" : "NO",
  59. "final_explanation" : "the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
  60. "weight" : 2.3166666,
  61. "decisions" : [ {
  62. "decider" : "filter",
  63. "decision" : "NO",
  64. "explanation" : "node does not match index include filters [foo:\"bar\"]"
  65. } ]
  66. }
  67. }
  68. }
编号 描述
Cluster Allocation Explain API - 图1 Whether the shard is assigned or unassigned
Cluster Allocation Explain API - 图2 Whether information about the shard is still being fetched
Cluster Allocation Explain API - 图3 Reason for the shard originally becoming unassigned
Cluster Allocation Explain API - 图4 Configured delay before the shard can be allocated
Cluster Allocation Explain API - 图5 Remaining delay before the shard can be allocated
Cluster Allocation Explain API - 图6 User-added attributes the node has
Cluster Allocation Explain API - 图7 The shard copy information for this node and error (if applicable)
Cluster Allocation Explain API - 图8 Final decision and explanation of whether the shard can be allocated to this node
Cluster Allocation Explain API - 图9 Weight for how much the allocator would like to allocate the shard to this node
Cluster Allocation Explain API - 图10 List of node decisions factoring into final decision about the shard

对于一个已经分配的分片来说,输出与下面相似 :

  1. {
  2. "shard" : {
  3. "index" : "only-foo",
  4. "index_uuid" : "KnW0-zELRs6PK84l0r38ZA",
  5. "id" : 0,
  6. "primary" : true
  7. },
  8. "assigned" : true,
  9. "assigned_node_id" : "Qc6VL8c5RWaw1qXZ0Rg57g",
  10. "shard_state_fetch_pending": false,
  11. "allocation_delay_ms" : 0,
  12. "remaining_delay_ms" : 0,
  13. "nodes" : {
  14. "V-Spi0AyRZ6ZvKbaI3691w" : {
  15. "node_name" : "bGG90GE",
  16. "node_attributes" : {
  17. "bar" : "baz"
  18. },
  19. "store" : {
  20. "shard_copy" : "NONE"
  21. },
  22. "final_decision" : "NO",
  23. "final_explanation" : "the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
  24. "weight" : 1.4499999,
  25. "decisions" : [ {
  26. "decider" : "filter",
  27. "decision" : "NO",
  28. "explanation" : "node does not match index include filters [foo:\"bar\"]"
  29. } ]
  30. },
  31. "Qc6VL8c5RWaw1qXZ0Rg57g" : {
  32. "node_name" : "I8hydUG",
  33. "node_attributes" : {
  34. "bar" : "baz",
  35. "foo" : "bar"
  36. },
  37. "store" : {
  38. "shard_copy" : "AVAILABLE"
  39. },
  40. "final_decision" : "ALREADY_ASSIGNED",
  41. "final_explanation" : "the shard is already assigned to this node",
  42. "weight" : 0.0,
  43. "decisions" : [ {
  44. "decider" : "same_shard",
  45. "decision" : "NO",
  46. "explanation" : "the shard cannot be allocated on the same node id [Qc6VL8c5RWaw1qXZ0Rg57g] on which it already exists"
  47. } ]
  48. },
  49. "PzdyMZGXQdGhqTJHF_hGgA" : {
  50. "node_name" : "H5dfFeA",
  51. "node_attributes" : { },
  52. "store" : {
  53. "shard_copy" : "NONE"
  54. },
  55. "final_decision" : "NO",
  56. "final_explanation" : "the shard cannot be assigned because one or more allocation decider returns a 'NO' decision",
  57. "weight" : 3.6999998,
  58. "decisions" : [ {
  59. "decider" : "filter",
  60. "decision" : "NO",
  61. "explanation" : "node does not match index include filters [foo:\"bar\"]"
  62. } ]
  63. }
  64. }
  65. }
编号 描述
Cluster Allocation Explain API - 图11 Node the shard is currently assigned to
Cluster Allocation Explain API - 图12 The decision is “ALREADY_ASSIGNED” because the shard is currently assigned to this node

您也可以让 Elasticsearch explain 第一个未分配分片的分配情况,它可以通过发送一个空的 body 来找到,例如 :

  1. $ curl -XGET 'http://localhost:9200/_cluster/allocation/explain'

如果您想要去包含所有的那些我们考虑到的最终的决策的决定,该 include_yes_decisions 参数将返回所有的决策 :

  1. $ curl -XGET 'http://localhost:9200/_cluster/allocation/explain?include_yes_decisions=true'

此外,通过设置 include_disk_info参数为 true,您可以返回通过集群信息服务返回收集到的信息,包括硬盘使用和分配大小。

  1. $ curl -XGET 'http://localhost:9200/_cluster/allocation/explain?include_disk_info=true'