troubleshooting-unstable-cluster.asciidoc 15 KB

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