fault-detection.asciidoc 15 KB

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