fix-common-cluster-issues.asciidoc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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-cpu-usage]]
  80. === High CPU usage
  81. {es} uses <<modules-threadpool,thread pools>> to manage CPU resources for
  82. concurrent operations. High CPU usage typically means one or more thread pools
  83. are running low.
  84. If a thread pool is depleted, {es} will <<rejected-requests,reject requests>>
  85. related to the thread pool. For example, if the `search` thread pool is
  86. depleted, {es} will reject search requests until more threads are available.
  87. [discrete]
  88. [[diagnose-high-cpu-usage]]
  89. ==== Diagnose high CPU usage
  90. **Check CPU usage**
  91. include::{es-repo-dir}/tab-widgets/cpu-usage-widget.asciidoc[]
  92. **Check hot threads**
  93. If a node has high CPU usage, use the <<cluster-nodes-hot-threads,nodes hot
  94. threads API>> to check for resource-intensive threads running on the node.
  95. [source,console]
  96. ----
  97. GET _nodes/my-node,my-other-node/hot_threads
  98. ----
  99. // TEST[s/\/my-node,my-other-node//]
  100. This API returns a breakdown of any hot threads in plain text.
  101. [discrete]
  102. [[reduce-cpu-usage]]
  103. ==== Reduce CPU usage
  104. The following tips outline the most common causes of high CPU usage and their
  105. solutions.
  106. **Scale your cluster**
  107. Heavy indexing and search loads can deplete smaller thread pools. To better
  108. handle heavy workloads, add more nodes to your cluster or upgrade your existing
  109. nodes to increase capacity.
  110. **Spread out bulk requests**
  111. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  112. or <<search-multi-search,multi-search>> requests still require CPU resources. If
  113. possible, submit smaller requests and allow more time between them.
  114. **Cancel long-running searches**
  115. Long-running searches can block threads in the `search` thread pool. To check
  116. for these searches, use the <<tasks,task management API>>.
  117. [source,console]
  118. ----
  119. GET _tasks?actions=*search&detailed
  120. ----
  121. The response's `description` contains the search request and its queries.
  122. `running_time_in_nanos` shows how long the search has been running.
  123. [source,console-result]
  124. ----
  125. {
  126. "nodes" : {
  127. "oTUltX4IQMOUUVeiohTt8A" : {
  128. "name" : "my-node",
  129. "transport_address" : "127.0.0.1:9300",
  130. "host" : "127.0.0.1",
  131. "ip" : "127.0.0.1:9300",
  132. "tasks" : {
  133. "oTUltX4IQMOUUVeiohTt8A:464" : {
  134. "node" : "oTUltX4IQMOUUVeiohTt8A",
  135. "id" : 464,
  136. "type" : "transport",
  137. "action" : "indices:data/read/search",
  138. "description" : "indices[my-index], search_type[QUERY_THEN_FETCH], source[{\"query\":...}]",
  139. "start_time_in_millis" : 4081771730000,
  140. "running_time_in_nanos" : 13991383,
  141. "cancellable" : true
  142. }
  143. }
  144. }
  145. }
  146. }
  147. ----
  148. // TESTRESPONSE[skip: no way to get tasks]
  149. To cancel a search and free up resources, use the API's `_cancel` endpoint.
  150. [source,console]
  151. ----
  152. POST _tasks/oTUltX4IQMOUUVeiohTt8A:464/_cancel
  153. ----
  154. For additional tips on how to track and avoid resource-intensive searches, see
  155. <<avoid-expensive-searches,Avoid expensive searches>>.
  156. [discrete]
  157. [[high-jvm-memory-pressure]]
  158. === High JVM memory pressure
  159. High JVM memory usage can degrade cluster performance and trigger
  160. <<circuit-breaker-errors,circuit breaker errors>>. To prevent this, we recommend
  161. taking steps to reduce memory pressure if a node's JVM memory usage consistently
  162. exceeds 85%.
  163. [discrete]
  164. [[diagnose-high-jvm-memory-pressure]]
  165. ==== Diagnose high JVM memory pressure
  166. **Check JVM memory pressure**
  167. include::{es-repo-dir}/tab-widgets/code.asciidoc[]
  168. include::{es-repo-dir}/tab-widgets/jvm-memory-pressure-widget.asciidoc[]
  169. **Check garbage collection logs**
  170. As memory usage increases, garbage collection becomes more frequent and takes
  171. longer. You can track the frequency and length of garbage collection events in
  172. <<logging,`elasticsearch.log`>>. For example, the following event states {es}
  173. spent more than 50% (21 seconds) of the last 40 seconds performing garbage
  174. collection.
  175. [source,log]
  176. ----
  177. [timestamp_short_interval_from_last][INFO ][o.e.m.j.JvmGcMonitorService] [node_id] [gc][number] overhead, spent [21s] collecting in the last [40s]
  178. ----
  179. [discrete]
  180. [[reduce-jvm-memory-pressure]]
  181. ==== Reduce JVM memory pressure
  182. **Reduce your shard count**
  183. Every shard uses memory. In most cases, a small set of large shards uses fewer
  184. resources than many small shards. For tips on reducing your shard count, see
  185. <<size-your-shards>>.
  186. [[avoid-expensive-searches]]
  187. **Avoid expensive searches**
  188. Expensive searches can use large amounts of memory. To better track expensive
  189. searches on your cluster, enable <<index-modules-slowlog,slow logs>>.
  190. Expensive searches may have a large <<paginate-search-results,`size` argument>>,
  191. use aggregations with a large number of buckets, or include
  192. <<query-dsl-allow-expensive-queries,expensive queries>>. To prevent expensive
  193. searches, consider the following setting changes:
  194. * Lower the `size` limit using the
  195. <<index-max-result-window,`index.max_result_window`>> index setting.
  196. * Decrease the maximum number of allowed aggregation buckets using the
  197. <<search-settings-max-buckets,search.max_buckets>> cluster setting.
  198. * Disable expensive queries using the
  199. <<query-dsl-allow-expensive-queries,`search.allow_expensive_queries`>> cluster
  200. setting.
  201. [source,console]
  202. ----
  203. PUT _settings
  204. {
  205. "index.max_result_window": 5000
  206. }
  207. PUT _cluster/settings
  208. {
  209. "persistent": {
  210. "search.max_buckets": 20000,
  211. "search.allow_expensive_queries": false
  212. }
  213. }
  214. ----
  215. // TEST[s/^/PUT my-index\n/]
  216. **Prevent mapping explosions**
  217. Defining too many fields or nesting fields too deeply can lead to
  218. <<mapping-limit-settings,mapping explosions>> that use large amounts of memory.
  219. To prevent mapping explosions, use the <<mapping-settings-limit,mapping limit
  220. settings>> to limit the number of field mappings.
  221. **Spread out bulk requests**
  222. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  223. or <<search-multi-search,multi-search>> requests can still create high JVM
  224. memory pressure. If possible, submit smaller requests and allow more time
  225. between them.
  226. **Upgrade node memory**
  227. Heavy indexing and search loads can cause high JVM memory pressure. To better
  228. handle heavy workloads, upgrade your nodes to increase their memory capacity.
  229. [discrete]
  230. [[red-yellow-cluster-status]]
  231. === Red or yellow cluster status
  232. A red or yellow cluster status indicates one or more shards are missing or
  233. unallocated. These unassigned shards increase your risk of data loss and can
  234. degrade cluster performance.
  235. [discrete]
  236. [[diagnose-cluster-status]]
  237. ==== Diagnose your cluster status
  238. **Check your cluster status**
  239. Use the <<cluster-health,cluster health API>>.
  240. [source,console]
  241. ----
  242. GET _cluster/health?filter_path=status,*_shards
  243. ----
  244. A healthy cluster has a green `status` and zero `unassigned_shards`. A yellow
  245. status means only replicas are unassigned. A red status means one or
  246. more primary shards are unassigned.
  247. **View unassigned shards**
  248. To view unassigned shards, use the <<cat-shards,cat shards API>>.
  249. [source,console]
  250. ----
  251. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
  252. ----
  253. Unassigned shards have a `state` of `UNASSIGNED`. The `prirep` value is `p` for
  254. primary shards and `r` for replicas. The `unassigned.reason` describes why the
  255. shard remains unassigned.
  256. To get a more in-depth explanation of an unassigned shard's allocation status,
  257. use the <<cluster-allocation-explain,cluster allocation explanation API>>. You
  258. can often use details in the response to resolve the issue.
  259. [source,console]
  260. ----
  261. GET _cluster/allocation/explain?filter_path=index,node_allocation_decisions.node_name,node_allocation_decisions.deciders.*
  262. {
  263. "index": "my-index",
  264. "shard": 0,
  265. "primary": false,
  266. "current_node": "my-node"
  267. }
  268. ----
  269. // TEST[s/^/PUT my-index\n/]
  270. // TEST[s/"primary": false,/"primary": false/]
  271. // TEST[s/"current_node": "my-node"//]
  272. [discrete]
  273. [[fix-red-yellow-cluster-status]]
  274. ==== Fix a red or yellow cluster status
  275. A shard can become unassigned for several reasons. The following tips outline the
  276. most common causes and their solutions.
  277. **Re-enable shard allocation**
  278. You typically disable allocation during a <<restart-cluster,restart>> or other
  279. cluster maintenance. If you forgot to re-enable allocation afterward, {es} will
  280. be unable to assign shards. To re-enable allocation, reset the
  281. `cluster.routing.allocation.enable` cluster setting.
  282. [source,console]
  283. ----
  284. PUT _cluster/settings
  285. {
  286. "persistent" : {
  287. "cluster.routing.allocation.enable" : null
  288. }
  289. }
  290. ----
  291. **Recover lost nodes**
  292. Shards often become unassigned when a data node leaves the cluster. This can
  293. occur for several reasons, ranging from connectivity issues to hardware failure.
  294. After you resolve the issue and recover the node, it will rejoin the cluster.
  295. {es} will then automatically allocate any unassigned shards.
  296. To avoid wasting resources on temporary issues, {es} <<delayed-allocation,delays
  297. allocation>> by one minute by default. If you've recovered a node and don’t want
  298. to wait for the delay period, you can call the <<cluster-reroute,cluster reroute
  299. API>> with no arguments to start the allocation process. The process runs
  300. asynchronously in the background.
  301. [source,console]
  302. ----
  303. POST _cluster/reroute
  304. ----
  305. **Fix allocation settings**
  306. Misconfigured allocation settings can result in an unassigned primary shard.
  307. These settings include:
  308. * <<shard-allocation-filtering,Shard allocation>> index settings
  309. * <<cluster-shard-allocation-filtering,Allocation filtering>> cluster settings
  310. * <<shard-allocation-awareness,Allocation awareness>> cluster settings
  311. To review your allocation settings, use the <<indices-get-settings,get index
  312. settings>> and <<cluster-get-settings,get cluster settings>> APIs.
  313. [source,console]
  314. ----
  315. GET my-index/_settings?flat_settings=true&include_defaults=true
  316. GET _cluster/settings?flat_settings=true&include_defaults=true
  317. ----
  318. // TEST[s/^/PUT my-index\n/]
  319. You can change the settings using the <<indices-update-settings,update index
  320. settings>> and <<cluster-update-settings,update cluster settings>> APIs.
  321. **Allocate or reduce replicas**
  322. To protect against hardware failure, {es} will not assign a replica to the same
  323. node as its primary shard. If no other data nodes are available to host the
  324. replica, it remains unassigned. To fix this, you can:
  325. * Add a data node to the same tier to host the replica.
  326. * Change the `index.number_of_replicas` index setting to reduce the number of
  327. replicas for each primary shard. We recommend keeping at least one replica per
  328. primary.
  329. [source,console]
  330. ----
  331. PUT _settings
  332. {
  333. "index.number_of_replicas": 1
  334. }
  335. ----
  336. // TEST[s/^/PUT my-index\n/]
  337. **Free up or increase disk space**
  338. {es} uses a <<disk-based-shard-allocation,low disk watermark>> to ensure data
  339. nodes have enough disk space for incoming shards. By default, {es} does not
  340. allocate shards to nodes using more than 85% of disk space.
  341. To check the current disk space of your nodes, use the <<cat-allocation,cat
  342. allocation API>>.
  343. [source,console]
  344. ----
  345. GET _cat/allocation?v=true&h=node,shards,disk.*
  346. ----
  347. If your nodes are running low on disk space, you have a few options:
  348. * Upgrade your nodes to increase disk space.
  349. * Delete unneeded indices to free up space. If you use {ilm-init}, you can
  350. update your lifecycle policy to use <<ilm-searchable-snapshot,searchable
  351. snapshots>> or add a delete phase. If you no longer need to search the data, you
  352. can use a <<snapshot-restore,snapshot>> to store it off-cluster.
  353. * If you no longer write to an index, use the <<indices-forcemerge,force merge
  354. API>> or {ilm-init}'s <<ilm-forcemerge,force merge action>> to merge its
  355. segments into larger ones.
  356. +
  357. [source,console]
  358. ----
  359. POST my-index/_forcemerge
  360. ----
  361. // TEST[s/^/PUT my-index\n/]
  362. * If an index is read-only, use the <<indices-shrink-index,shrink index API>> or
  363. {ilm-init}'s <<ilm-shrink,shrink action>> to reduce its primary shard count.
  364. +
  365. [source,console]
  366. ----
  367. POST my-index/_shrink/my-shrunken-index
  368. ----
  369. // TEST[s/^/PUT my-index\n{"settings":{"index.number_of_shards":2,"blocks.write":true}}\n/]
  370. * If your node has a large disk capacity, you can increase the low disk
  371. watermark or set it to an explicit byte value.
  372. +
  373. [source,console]
  374. ----
  375. PUT _cluster/settings
  376. {
  377. "persistent": {
  378. "cluster.routing.allocation.disk.watermark.low": "30gb"
  379. }
  380. }
  381. ----
  382. // TEST[s/"30gb"/null/]
  383. **Reduce JVM memory pressure**
  384. Shard allocation requires JVM heap memory. High JVM memory pressure can trigger
  385. <<circuit-breaker,circuit breakers>> that stop allocation and leave shards
  386. unassigned. See <<high-jvm-memory-pressure>>.
  387. **Recover data for a lost primary shard**
  388. If a node containing a primary shard is lost, {es} can typically replace it
  389. using a replica on another node. If you can't recover the node and replicas
  390. don't exist or are irrecoverable, you'll need to re-add the missing data from a
  391. <<snapshot-restore,snapshot>> or the original data source.
  392. WARNING: Only use this option if node recovery is no longer possible. This
  393. process allocates an empty primary shard. If the node later rejoins the cluster,
  394. {es} will overwrite its primary shard with data from this newer empty shard,
  395. resulting in data loss.
  396. Use the <<cluster-reroute,cluster reroute API>> to manually allocate the
  397. unassigned primary shard to another data node in the same tier. Set
  398. `accept_data_loss` to `true`.
  399. [source,console]
  400. ----
  401. POST _cluster/reroute
  402. {
  403. "commands": [
  404. {
  405. "allocate_empty_primary": {
  406. "index": "my-index",
  407. "shard": 0,
  408. "node": "my-node",
  409. "accept_data_loss": "true"
  410. }
  411. }
  412. ]
  413. }
  414. ----
  415. // TEST[s/^/PUT my-index\n/]
  416. // TEST[catch:bad_request]
  417. If you backed up the missing index data to a snapshot, use the
  418. <<restore-snapshot-api,restore snapshot API>> to restore the individual index.
  419. Alternatively, you can index the missing data from the original data source.
  420. [discrete]
  421. [[rejected-requests]]
  422. === Rejected requests
  423. When {es} rejects a request, it stops the operation and returns an error with a
  424. `429` response code. Rejected requests are commonly caused by:
  425. * A <<high-cpu-usage,depleted thread pool>>. A depleted `search` or `write`
  426. thread pool returns a `TOO_MANY_REQUESTS` error message.
  427. * A <<circuit-breaker-errors,circuit breaker error>>.
  428. * High <<index-modules-indexing-pressure,indexing pressure>> that exceeds the
  429. <<memory-limits,`indexing_pressure.memory.limit`>>.
  430. [discrete]
  431. [[check-rejected-tasks]]
  432. ==== Check rejected tasks
  433. To check the number of rejected tasks for each thread pool, use the
  434. <<cat-thread-pool,cat thread pool API>>. A high ratio of `rejected` to
  435. `completed` tasks, particularly in the `search` and `write` thread pools, means
  436. {es} regularly rejects requests.
  437. [source,console]
  438. ----
  439. GET /_cat/thread_pool?v=true&h=id,name,active,rejected,completed
  440. ----
  441. [discrete]
  442. [[prevent-rejected-requests]]
  443. ==== Prevent rejected requests
  444. **Fix high CPU and memory usage**
  445. If {es} regularly rejects requests and other tasks, your cluster likely has high
  446. CPU usage or high JVM memory pressure. For tips, see <<high-cpu-usage>> and
  447. <<high-jvm-memory-pressure>>.
  448. **Prevent circuit breaker errors**
  449. If you regularly trigger circuit breaker errors, see <<circuit-breaker-errors>>
  450. for tips on diagnosing and preventing them.