troubleshooting-unstable-cluster.asciidoc 16 KB

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