fault-detection.asciidoc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. [[cluster-fault-detection]]
  2. === Cluster fault detection
  3. The elected master periodically checks each of the nodes in the cluster to
  4. ensure that they are still connected and healthy. Each node in the cluster also
  5. periodically checks the health of the elected master. These checks are known
  6. respectively as _follower checks_ and _leader checks_.
  7. Elasticsearch allows these checks to occasionally fail or timeout without
  8. taking any action. It considers a node to be faulty only after a number of
  9. consecutive checks have failed. You can control fault detection behavior with
  10. <<modules-discovery-settings,`cluster.fault_detection.*` settings>>.
  11. If the elected master detects that a node has disconnected, however, this
  12. situation is treated as an immediate failure. The master bypasses the timeout
  13. and retry setting values and attempts to remove the node from the cluster.
  14. Similarly, if a node detects that the elected master has disconnected, this
  15. situation is treated as an immediate failure. The node bypasses the timeout and
  16. retry settings and restarts its discovery phase to try and find or elect a new
  17. master.
  18. [[cluster-fault-detection-filesystem-health]]
  19. Additionally, each node periodically verifies that its data path is healthy by
  20. writing a small file to disk and then deleting it again. If a node discovers
  21. its data path is unhealthy then it is removed from the cluster until the data
  22. path recovers. You can control this behavior with the
  23. <<modules-discovery-settings,`monitor.fs.health` settings>>.
  24. [[cluster-fault-detection-cluster-state-publishing]]
  25. The elected master node
  26. will also remove nodes from the cluster if nodes are unable to apply an updated
  27. cluster state within a reasonable time. The timeout defaults to 2 minutes
  28. starting from the beginning of the cluster state update. Refer to
  29. <<cluster-state-publishing>> for a more detailed description.
  30. [[cluster-fault-detection-troubleshooting]]
  31. ==== Troubleshooting an unstable cluster
  32. //tag::troubleshooting[]
  33. Normally, a node will only leave a cluster if deliberately shut down. If a node
  34. leaves the cluster unexpectedly, it's important to address the cause. A cluster
  35. in which nodes leave unexpectedly is unstable and can create several issues.
  36. For instance:
  37. * The cluster health may be yellow or red.
  38. * Some shards will be initializing and other shards may be failing.
  39. * Search, indexing, and monitoring operations may fail and report exceptions in
  40. logs.
  41. * The `.security` index may be unavailable, blocking access to the cluster.
  42. * The master may appear busy due to frequent cluster state updates.
  43. To troubleshoot a cluster in this state, first ensure the cluster has a
  44. <<discovery-troubleshooting,stable master>>. Next, focus on the nodes
  45. unexpectedly leaving the cluster ahead of all other issues. It will not be
  46. possible to solve other issues until the cluster has a stable master node and
  47. stable node membership.
  48. Diagnostics and statistics are usually not useful in an unstable cluster. These
  49. tools only offer a view of the state of the cluster at a single point in time.
  50. Instead, look at the cluster logs to see the pattern of behaviour over time.
  51. Focus particularly on logs from the elected master. When a node leaves the
  52. cluster, logs for the elected master include a message like this (with line
  53. breaks added to make it easier to read):
  54. [source,text]
  55. ----
  56. [2022-03-21T11:02:35,513][INFO ][o.e.c.c.NodeLeftExecutor] [instance-0000000000]
  57. node-left: [{instance-0000000004}{bfcMDTiDRkietFb9v_di7w}{aNlyORLASam1ammv2DzYXA}{172.27.47.21}{172.27.47.21:19054}{m}]
  58. with reason [disconnected]
  59. ----
  60. This message says that the `NodeLeftExecutor` on the elected master
  61. (`instance-0000000000`) processed a `node-left` task, identifying the node that
  62. was removed and the reason for its removal. When the node joins the cluster
  63. again, logs for the elected master will include a message like this (with line
  64. breaks added to make it easier to read):
  65. [source,text]
  66. ----
  67. [2022-03-21T11:02:59,892][INFO ][o.e.c.c.NodeJoinExecutor] [instance-0000000000]
  68. node-join: [{instance-0000000004}{bfcMDTiDRkietFb9v_di7w}{UNw_RuazQCSBskWZV8ID_w}{172.27.47.21}{172.27.47.21:19054}{m}]
  69. with reason [joining after restart, removed [24s] ago with reason [disconnected]]
  70. ----
  71. This message says that the `NodeJoinExecutor` on the elected master
  72. (`instance-0000000000`) processed a `node-join` task, identifying the node that
  73. was added to the cluster and the reason for the task.
  74. Other nodes may log similar messages, but report fewer details:
  75. [source,text]
  76. ----
  77. [2020-01-29T11:02:36,985][INFO ][o.e.c.s.ClusterApplierService]
  78. [instance-0000000001] removed {
  79. {instance-0000000004}{bfcMDTiDRkietFb9v_di7w}{aNlyORLASam1ammv2DzYXA}{172.27.47.21}{172.27.47.21:19054}{m}
  80. {tiebreaker-0000000003}{UNw_RuazQCSBskWZV8ID_w}{bltyVOQ-RNu20OQfTHSLtA}{172.27.161.154}{172.27.161.154:19251}{mv}
  81. }, term: 14, version: 1653415, reason: Publication{term=14, version=1653415}
  82. ----
  83. These messages are not especially useful for troubleshooting, so focus on the
  84. ones from the `NodeLeftExecutor` and `NodeJoinExecutor` which are only emitted
  85. on the elected master and which contain more details. If you don't see the
  86. messages from the `NodeLeftExecutor` and `NodeJoinExecutor`, check that:
  87. * You're looking at the logs for the elected master node.
  88. * The logs cover the correct time period.
  89. * Logging is enabled at `INFO` level.
  90. Nodes will also log a message containing `master node changed` whenever they
  91. start or stop following the elected master. You can use these messages to
  92. determine each node's view of the state of the master over time.
  93. If a node restarts, it will leave the cluster and then join the cluster again.
  94. When it rejoins, the `NodeJoinExecutor` will log that it processed a
  95. `node-join` task indicating that the node is `joining after restart`. If a node
  96. is unexpectedly restarting, look at the node's logs to see why it is shutting
  97. down.
  98. The <<health-api>> API on the affected node will also provide some useful
  99. information about the situation.
  100. If the node did not restart then you should look at the reason for its
  101. departure more closely. Each reason has different troubleshooting steps,
  102. described below. There are three possible reasons:
  103. * `disconnected`: The connection from the master node to the removed node was
  104. closed.
  105. * `lagging`: The master published a cluster state update, but the removed node
  106. did not apply it within the permitted timeout. By default, this timeout is 2
  107. minutes. Refer to <<modules-discovery-settings>> for information about the
  108. settings which control this mechanism.
  109. * `followers check retry count exceeded`: The master sent a number of
  110. consecutive health checks to the removed node. These checks were rejected or
  111. timed out. By default, each health check times out after 10 seconds and {es}
  112. removes the node removed after three consecutively failed health checks. Refer
  113. to <<modules-discovery-settings>> for information about the settings which
  114. control this mechanism.
  115. [discrete]
  116. ===== Diagnosing `disconnected` nodes
  117. Nodes typically leave the cluster with reason `disconnected` when they shut
  118. down, but if they rejoin the cluster without restarting then there is some
  119. other problem.
  120. {es} is designed to run on a fairly reliable network. It opens a number of TCP
  121. connections between nodes and expects these connections to remain open forever.
  122. If a connection is closed then {es} will try and reconnect, so the occasional
  123. blip should have limited impact on the cluster even if the affected node
  124. briefly leaves the cluster. In contrast, repeatedly-dropped connections will
  125. severely affect its operation.
  126. The connections from the elected master node to every other node in the cluster
  127. are particularly important. The elected master never spontaneously closes its
  128. outbound connections to other nodes. Similarly, once a connection is fully
  129. established, a node never spontaneously close its inbound connections unless
  130. the node is shutting down.
  131. If you see a node unexpectedly leave the cluster with the `disconnected`
  132. reason, something other than {es} likely caused the connection to close. A
  133. common cause is a misconfigured firewall with an improper timeout or another
  134. policy that's <<long-lived-connections,incompatible with {es}>>. It could also
  135. be caused by general connectivity issues, such as packet loss due to faulty
  136. hardware or network congestion. If you're an advanced user, you can get more
  137. detailed information about network exceptions by configuring the following
  138. loggers:
  139. [source,yaml]
  140. ----
  141. logger.org.elasticsearch.transport.TcpTransport: DEBUG
  142. logger.org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport: DEBUG
  143. ----
  144. In extreme cases, you may need to take packet captures using `tcpdump` to
  145. determine whether messages between nodes are being dropped or rejected by some
  146. other device on the network.
  147. [discrete]
  148. ===== Diagnosing `lagging` nodes
  149. {es} needs every node to process cluster state updates reasonably quickly. If a
  150. node takes too long to process a cluster state update, it can be harmful to the
  151. cluster. The master will remove these nodes with the `lagging` reason. Refer to
  152. <<modules-discovery-settings>> for information about the settings which control
  153. this mechanism.
  154. Lagging is typically caused by performance issues on the removed node. However,
  155. a node may also lag due to severe network delays. To rule out network delays,
  156. ensure that `net.ipv4.tcp_retries2` is <<system-config-tcpretries,configured
  157. properly>>. Log messages that contain `warn threshold` may provide more
  158. information about the root cause.
  159. If you're an advanced user, you can get more detailed information about what
  160. the node was doing when it was removed by configuring the following logger:
  161. [source,yaml]
  162. ----
  163. logger.org.elasticsearch.cluster.coordination.LagDetector: DEBUG
  164. ----
  165. When this logger is enabled, {es} will attempt to run the
  166. <<cluster-nodes-hot-threads>> API on the faulty node and report the results in
  167. the logs on the elected master. The results are compressed, encoded, and split
  168. into chunks to avoid truncation:
  169. [source,text]
  170. ----
  171. [DEBUG][o.e.c.c.LagDetector ] [master] hot threads from node [{node}{g3cCUaMDQJmQ2ZLtjr-3dg}{10.0.0.1:9300}] lagging at version [183619] despite commit of cluster state version [183620] [part 1]: H4sIAAAAAAAA/x...
  172. [DEBUG][o.e.c.c.LagDetector ] [master] hot threads from node [{node}{g3cCUaMDQJmQ2ZLtjr-3dg}{10.0.0.1:9300}] lagging at version [183619] despite commit of cluster state version [183620] [part 2]: p7x3w1hmOQVtuV...
  173. [DEBUG][o.e.c.c.LagDetector ] [master] hot threads from node [{node}{g3cCUaMDQJmQ2ZLtjr-3dg}{10.0.0.1:9300}] lagging at version [183619] despite commit of cluster state version [183620] [part 3]: v7uTboMGDbyOy+...
  174. [DEBUG][o.e.c.c.LagDetector ] [master] hot threads from node [{node}{g3cCUaMDQJmQ2ZLtjr-3dg}{10.0.0.1:9300}] lagging at version [183619] despite commit of cluster state version [183620] [part 4]: 4tse0RnPnLeDNN...
  175. [DEBUG][o.e.c.c.LagDetector ] [master] hot threads from node [{node}{g3cCUaMDQJmQ2ZLtjr-3dg}{10.0.0.1:9300}] lagging at version [183619] despite commit of cluster state version [183620] (gzip compressed, base64-encoded, and split into 4 parts on preceding log lines)
  176. ----
  177. To reconstruct the output, base64-decode the data and decompress it using
  178. `gzip`. For instance, on Unix-like systems:
  179. [source,sh]
  180. ----
  181. cat lagdetector.log | sed -e 's/.*://' | base64 --decode | gzip --decompress
  182. ----
  183. [discrete]
  184. ===== Diagnosing `follower check retry count exceeded` nodes
  185. Nodes sometimes leave the cluster with reason `follower check retry count
  186. exceeded` when they shut down, but if they rejoin the cluster without
  187. restarting then there is some other problem.
  188. {es} needs every node to respond to network messages successfully and
  189. reasonably quickly. If a node rejects requests or does not respond at all then
  190. it can be harmful to the cluster. If enough consecutive checks fail then the
  191. master will remove the node with reason `follower check retry count exceeded`
  192. and will indicate in the `node-left` message how many of the consecutive
  193. unsuccessful checks failed and how many of them timed out. Refer to
  194. <<modules-discovery-settings>> for information about the settings which control
  195. this mechanism.
  196. Timeouts and failures may be due to network delays or performance problems on
  197. the affected nodes. Ensure that `net.ipv4.tcp_retries2` is
  198. <<system-config-tcpretries,configured properly>> to eliminate network delays as
  199. a possible cause for this kind of instability. Log messages containing
  200. `warn threshold` may give further clues about the cause of the instability.
  201. If the last check failed with an exception then the exception is reported, and
  202. typically indicates the problem that needs to be addressed. If any of the
  203. checks timed out then narrow down the problem as follows.
  204. include::../../troubleshooting/network-timeouts.asciidoc[tag=troubleshooting-network-timeouts-gc-vm]
  205. include::../../troubleshooting/network-timeouts.asciidoc[tag=troubleshooting-network-timeouts-packet-capture-fault-detection]
  206. include::../../troubleshooting/network-timeouts.asciidoc[tag=troubleshooting-network-timeouts-threads]
  207. By default the follower checks will time out after 30s, so if node departures
  208. are unpredictable then capture stack dumps every 15s to be sure that at least
  209. one stack dump was taken at the right time.
  210. [discrete]
  211. ===== Diagnosing `ShardLockObtainFailedException` failures
  212. If a node leaves and rejoins the cluster then {es} will usually shut down and
  213. re-initialize its shards. If the shards do not shut down quickly enough then
  214. {es} may fail to re-initialize them due to a `ShardLockObtainFailedException`.
  215. To gather more information about the reason for shards shutting down slowly,
  216. configure the following logger:
  217. [source,yaml]
  218. ----
  219. logger.org.elasticsearch.env.NodeEnvironment: DEBUG
  220. ----
  221. When this logger is enabled, {es} will attempt to run the
  222. <<cluster-nodes-hot-threads>> API whenever it encounters a
  223. `ShardLockObtainFailedException`. The results are compressed, encoded, and
  224. split into chunks to avoid truncation:
  225. [source,text]
  226. ----
  227. [DEBUG][o.e.e.NodeEnvironment ] [master] hot threads while failing to obtain shard lock for [index][0] [part 1]: H4sIAAAAAAAA/x...
  228. [DEBUG][o.e.e.NodeEnvironment ] [master] hot threads while failing to obtain shard lock for [index][0] [part 2]: p7x3w1hmOQVtuV...
  229. [DEBUG][o.e.e.NodeEnvironment ] [master] hot threads while failing to obtain shard lock for [index][0] [part 3]: v7uTboMGDbyOy+...
  230. [DEBUG][o.e.e.NodeEnvironment ] [master] hot threads while failing to obtain shard lock for [index][0] [part 4]: 4tse0RnPnLeDNN...
  231. [DEBUG][o.e.e.NodeEnvironment ] [master] hot threads while failing to obtain shard lock for [index][0] (gzip compressed, base64-encoded, and split into 4 parts on preceding log lines)
  232. ----
  233. To reconstruct the output, base64-decode the data and decompress it using
  234. `gzip`. For instance, on Unix-like systems:
  235. [source,sh]
  236. ----
  237. cat shardlock.log | sed -e 's/.*://' | base64 --decode | gzip --decompress
  238. ----
  239. //end::troubleshooting[]