fix-common-cluster-issues.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. [[fix-common-cluster-issues]]
  2. == Fix common cluster issues
  3. This guide describes how to fix common problems with {es} clusters.
  4. [discrete]
  5. [[circuit-breaker-errors]]
  6. === Circuit breaker errors
  7. {es} uses <<circuit-breaker,circuit breakers>> to prevent nodes from running out
  8. of JVM heap memory. If Elasticsearch estimates an operation would exceed a
  9. circuit breaker, it stops the operation and returns an error.
  10. By default, the <<parent-circuit-breaker,parent circuit breaker>> triggers at
  11. 95% JVM memory usage. To prevent errors, we recommend taking steps to reduce
  12. memory pressure if usage consistently exceeds 85%.
  13. [discrete]
  14. [[diagnose-circuit-breaker-errors]]
  15. ==== Diagnose circuit breaker errors
  16. **Error messages**
  17. If a request triggers a circuit breaker, {es} returns an error with a `429` HTTP
  18. status code.
  19. [source,js]
  20. ----
  21. {
  22. 'error': {
  23. 'type': 'circuit_breaking_exception',
  24. 'reason': '[parent] Data too large, data for [<http_request>] would be [123848638/118.1mb], which is larger than the limit of [123273216/117.5mb], real usage: [120182112/114.6mb], new bytes reserved: [3666526/3.4mb]',
  25. 'bytes_wanted': 123848638,
  26. 'bytes_limit': 123273216,
  27. 'durability': 'TRANSIENT'
  28. },
  29. 'status': 429
  30. }
  31. ----
  32. // NOTCONSOLE
  33. {es} also writes circuit breaker errors to <<logging,`elasticsearch.log`>>. This
  34. is helpful when automated processes, such as allocation, trigger a circuit
  35. breaker.
  36. [source,txt]
  37. ----
  38. Caused by: org.elasticsearch.common.breaker.CircuitBreakingException: [parent] Data too large, data for [<transport_request>] would be [num/numGB], which is larger than the limit of [num/numGB], usages [request=0/0b, fielddata=num/numKB, in_flight_requests=num/numGB, accounting=num/numGB]
  39. ----
  40. **Check JVM memory usage**
  41. If you've enabled Stack Monitoring, you can view JVM memory usage in {kib}. In
  42. the main menu, click **Stack Monitoring**. On the Stack Monitoring **Overview**
  43. page, click **Nodes**. The **JVM Heap** column lists the current memory usage
  44. for each node.
  45. You can also use the <<cat-nodes,cat nodes API>> to get the current
  46. `heap.percent` for each node.
  47. [source,console]
  48. ----
  49. GET _cat/nodes?v=true&h=name,node*,heap*
  50. ----
  51. To get the JVM memory usage for each circuit breaker, use the
  52. <<cluster-nodes-stats,node stats API>>.
  53. [source,console]
  54. ----
  55. GET _nodes/stats/breaker
  56. ----
  57. [discrete]
  58. [[prevent-circuit-breaker-errors]]
  59. ==== Prevent circuit breaker errors
  60. **Reduce JVM memory pressure**
  61. High JVM memory pressure often causes circuit breaker errors. See
  62. <<high-jvm-memory-pressure>>.
  63. **Avoid using fielddata on `text` fields**
  64. For high-cardinality `text` fields, fielddata can use a large amount of JVM
  65. memory. To avoid this, {es} disables fielddata on `text` fields by default. If
  66. you've enabled fielddata and triggered the <<fielddata-circuit-breaker,fielddata
  67. circuit breaker>>, consider disabling it and using a `keyword` field instead.
  68. See <<fielddata>>.
  69. **Clear the fieldata cache**
  70. If you've triggered the fielddata circuit breaker and can't disable fielddata,
  71. use the <<indices-clearcache,clear cache API>> to clear the fielddata cache.
  72. This may disrupt any in-flight searches that use fielddata.
  73. [source,console]
  74. ----
  75. POST _cache/clear?fielddata=true
  76. ----
  77. // TEST[s/^/PUT my-index\n/]
  78. [discrete]
  79. [[high-jvm-memory-pressure]]
  80. === High JVM memory pressure
  81. High JVM memory usage can degrade cluster performance and trigger
  82. <<circuit-breaker-errors,circuit breaker errors>>. To prevent this, we recommend
  83. taking steps to reduce memory pressure if a node's JVM memory usage consistently
  84. exceeds 85%.
  85. [discrete]
  86. [[diagnose-high-jvm-memory-pressure]]
  87. ==== Diagnose high JVM memory pressure
  88. **Check JVM memory pressure**
  89. include::{es-repo-dir}/tab-widgets/code.asciidoc[]
  90. include::{es-repo-dir}/tab-widgets/jvm-memory-pressure-widget.asciidoc[]
  91. **Check garbage collection logs**
  92. As memory usage increases, garbage collection becomes more frequent and takes
  93. longer. You can track the frequency and length of garbage collection events in
  94. <<logging,`elasticsearch.log`>>. For example, the following event states {es}
  95. spent more than 50% (21 seconds) of the last 40 seconds performing garbage
  96. collection.
  97. [source,log]
  98. ----
  99. [timestamp_short_interval_from_last][INFO ][o.e.m.j.JvmGcMonitorService] [node_id] [gc][number] overhead, spent [21s] collecting in the last [40s]
  100. ----
  101. [discrete]
  102. [[reduce-jvm-memory-pressure]]
  103. ==== Reduce JVM memory pressure
  104. **Reduce your shard count**
  105. Every shard uses memory. In most cases, a small set of large shards uses fewer
  106. resources than many small shards. For tips on reducing your shard count, see
  107. <<size-your-shards>>.
  108. **Avoid expensive searches**
  109. Expensive searches can use large amounts of memory. To better track expensive
  110. searches on your cluster, enable <<index-modules-slowlog,slow logs>>.
  111. Expensive searches may have a large <<paginate-search-results,`size` argument>>,
  112. use aggregations with a large number of buckets, or include
  113. <<query-dsl-allow-expensive-queries,expensive queries>>. To prevent expensive
  114. searches, consider the following setting changes:
  115. * Lower the `size` limit using the
  116. <<index-max-result-window,`index.max_result_window`>> index setting.
  117. * Decrease the maximum number of allowed aggregation buckets using the
  118. <<search-settings-max-buckets,search.max_buckets>> cluster setting.
  119. * Disable expensive queries using the
  120. <<query-dsl-allow-expensive-queries,`search.allow_expensive_queries`>> cluster
  121. setting.
  122. [source,console]
  123. ----
  124. PUT _settings
  125. {
  126. "index.max_result_window": 5000
  127. }
  128. PUT _cluster/settings
  129. {
  130. "persistent": {
  131. "search.max_buckets": 20000,
  132. "search.allow_expensive_queries": false
  133. }
  134. }
  135. ----
  136. // TEST[s/^/PUT my-index\n/]
  137. **Prevent mapping explosions**
  138. Defining too many fields or nesting fields too deeply can lead to
  139. <<mapping-limit-settings,mapping explosions>> that use large amounts of memory.
  140. To prevent mapping explosions, use the <<mapping-settings-limit,mapping limit
  141. settings>> to limit the number of field mappings.
  142. **Spread out bulk requests**
  143. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  144. or <<search-multi-search,multi-search>> requests can still create high JVM
  145. memory pressure. If possible, submit smaller requests and allow more time
  146. between them.
  147. **Upgrade node memory**
  148. Heavy indexing and search loads can cause high JVM memory pressure. To better
  149. handle heavy workloads, upgrade your nodes to increase their memory capacity.
  150. [discrete]
  151. [[red-yellow-cluster-status]]
  152. === Red or yellow cluster status
  153. A red or yellow cluster status indicates one or more shards are missing or
  154. unallocated. These unassigned shards increase your risk of data loss and can
  155. degrade cluster performance.
  156. [discrete]
  157. [[diagnose-cluster-status]]
  158. ==== Diagnose your cluster status
  159. **Check your cluster status**
  160. Use the <<cluster-health,cluster health API>>.
  161. [source,console]
  162. ----
  163. GET _cluster/health?filter_path=status,*_shards
  164. ----
  165. A healthy cluster has a green `status` and zero `unassigned_shards`. A yellow
  166. status means only replicas are unassigned. A red status means one or
  167. more primary shards are unassigned.
  168. **View unassigned shards**
  169. To view unassigned shards, use the <<cat-shards,cat shards API>>.
  170. [source,console]
  171. ----
  172. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
  173. ----
  174. Unassigned shards have a `state` of `UNASSIGNED`. The `prirep` value is `p` for
  175. primary shards and `r` for replicas. The `unassigned.reason` describes why the
  176. shard remains unassigned.
  177. To get a more in-depth explanation of an unassigned shard's allocation status,
  178. use the <<cluster-allocation-explain,cluster allocation explanation API>>. You
  179. can often use details in the response to resolve the issue.
  180. [source,console]
  181. ----
  182. GET _cluster/allocation/explain?filter_path=index,node_allocation_decisions.node_name,node_allocation_decisions.deciders.*
  183. {
  184. "index": "my-index",
  185. "shard": 0,
  186. "primary": false,
  187. "current_node": "my-node"
  188. }
  189. ----
  190. // TEST[s/^/PUT my-index\n/]
  191. // TEST[s/"primary": false,/"primary": false/]
  192. // TEST[s/"current_node": "my-node"//]
  193. [discrete]
  194. [[fix-red-yellow-cluster-status]]
  195. ==== Fix a red or yellow cluster status
  196. A shard can become unassigned for several reasons. The following tips outline the
  197. most common causes and their solutions.
  198. **Re-enable shard allocation**
  199. You typically disable allocation during a <<restart-cluster,restart>> or other
  200. cluster maintenance. If you forgot to re-enable allocation afterward, {es} will
  201. be unable to assign shards. To re-enable allocation, reset the
  202. `cluster.routing.allocation.enable` cluster setting.
  203. [source,console]
  204. ----
  205. PUT _cluster/settings
  206. {
  207. "persistent" : {
  208. "cluster.routing.allocation.enable" : null
  209. }
  210. }
  211. ----
  212. **Recover lost nodes**
  213. Shards often become unassigned when a data node leaves the cluster. This can
  214. occur for several reasons, ranging from connectivity issues to hardware failure.
  215. After you resolve the issue and recover the node, it will rejoin the cluster.
  216. {es} will then automatically allocate any unassigned shards.
  217. To avoid wasting resources on temporary issues, {es} <<delayed-allocation,delays
  218. allocation>> by one minute by default. If you've recovered a node and don’t want
  219. to wait for the delay period, you can call the <<cluster-reroute,cluster reroute
  220. API>> with no arguments to start the allocation process. The process runs
  221. asynchronously in the background.
  222. [source,console]
  223. ----
  224. POST _cluster/reroute
  225. ----
  226. **Fix allocation settings**
  227. Misconfigured allocation settings can result in an unassigned primary shard.
  228. These settings include:
  229. * <<shard-allocation-filtering,Shard allocation>> index settings
  230. * <<cluster-shard-allocation-filtering,Allocation filtering>> cluster settings
  231. * <<shard-allocation-awareness,Allocation awareness>> cluster settings
  232. To review your allocation settings, use the <<indices-get-settings,get index
  233. settings>> and <<cluster-get-settings,get cluster settings>> APIs.
  234. [source,console]
  235. ----
  236. GET my-index/_settings?flat_settings=true&include_defaults=true
  237. GET _cluster/settings?flat_settings=true&include_defaults=true
  238. ----
  239. // TEST[s/^/PUT my-index\n/]
  240. You can change the settings using the <<indices-update-settings,update index
  241. settings>> and <<cluster-update-settings,update cluster settings>> APIs.
  242. **Allocate or reduce replicas**
  243. To protect against hardware failure, {es} will not assign a replica to the same
  244. node as its primary shard. If no other data nodes are available to host the
  245. replica, it remains unassigned. To fix this, you can:
  246. * Add a data node to the same tier to host the replica.
  247. * Change the `index.number_of_replicas` index setting to reduce the number of
  248. replicas for each primary shard. We recommend keeping at least one replica per
  249. primary.
  250. [source,console]
  251. ----
  252. PUT _settings
  253. {
  254. "index.number_of_replicas": 1
  255. }
  256. ----
  257. // TEST[s/^/PUT my-index\n/]
  258. **Free up or increase disk space**
  259. {es} uses a <<disk-based-shard-allocation,low disk watermark>> to ensure data
  260. nodes have enough disk space for incoming shards. By default, {es} does not
  261. allocate shards to nodes using more than 85% of disk space.
  262. To check the current disk space of your nodes, use the <<cat-allocation,cat
  263. allocation API>>.
  264. [source,console]
  265. ----
  266. GET _cat/allocation?v=true&h=node,shards,disk.*
  267. ----
  268. If your nodes are running low on disk space, you have a few options:
  269. * Upgrade your nodes to increase disk space.
  270. * Delete unneeded indices to free up space. If you use {ilm-init}, you can
  271. update your lifecycle policy to use <<ilm-searchable-snapshot,searchable
  272. snapshots>> or add a delete phase. If you no longer need to search the data, you
  273. can use a <<snapshot-restore,snapshot>> to store it off-cluster.
  274. * If you no longer write to an index, use the <<indices-forcemerge,force merge
  275. API>> or {ilm-init}'s <<ilm-forcemerge,force merge action>> to merge its
  276. segments into larger ones.
  277. +
  278. [source,console]
  279. ----
  280. POST my-index/_forcemerge
  281. ----
  282. // TEST[s/^/PUT my-index\n/]
  283. * If an index is read-only, use the <<indices-shrink-index,shrink index API>> or
  284. {ilm-init}'s <<ilm-shrink,shrink action>> to reduce its primary shard count.
  285. +
  286. [source,console]
  287. ----
  288. POST my-index/_shrink/my-shrunken-index
  289. ----
  290. // TEST[s/^/PUT my-index\n{"settings":{"index.number_of_shards":2,"blocks.write":true}}\n/]
  291. * If your node has a large disk capacity, you can increase the low disk
  292. watermark or set it to an explicit byte value.
  293. +
  294. [source,console]
  295. ----
  296. PUT _cluster/settings
  297. {
  298. "persistent": {
  299. "cluster.routing.allocation.disk.watermark.low": "30gb"
  300. }
  301. }
  302. ----
  303. // TEST[s/"30gb"/null/]
  304. **Reduce JVM memory pressure**
  305. Shard allocation requires JVM heap memory. High JVM memory pressure can trigger
  306. <<circuit-breaker,circuit breakers>> that stop allocation and leave shards
  307. unassigned. See <<high-jvm-memory-pressure>>.
  308. **Recover data for a lost primary shard**
  309. If a node containing a primary shard is lost, {es} can typically replace it
  310. using a replica on another node. If you can't recover the node and replicas
  311. don't exist or are irrecoverable, you'll need to re-add the missing data from a
  312. <<snapshot-restore,snapshot>> or the original data source.
  313. WARNING: Only use this option if node recovery is no longer possible. This
  314. process allocates an empty primary shard. If the node later rejoins the cluster,
  315. {es} will overwrite its primary shard with data from this newer empty shard,
  316. resulting in data loss.
  317. Use the <<cluster-reroute,cluster reroute API>> to manually allocate the
  318. unassigned primary shard to another data node in the same tier. Set
  319. `accept_data_loss` to `true`.
  320. [source,console]
  321. ----
  322. POST _cluster/reroute
  323. {
  324. "commands": [
  325. {
  326. "allocate_empty_primary": {
  327. "index": "my-index",
  328. "shard": 0,
  329. "node": "my-node",
  330. "accept_data_loss": "true"
  331. }
  332. }
  333. ]
  334. }
  335. ----
  336. // TEST[s/^/PUT my-index\n/]
  337. // TEST[catch:bad_request]
  338. If you backed up the missing index data to a snapshot, use the
  339. <<restore-snapshot-api,restore snapshot API>> to restore the individual index.
  340. Alternatively, you can index the missing data from the original data source.