fix-common-cluster-issues.asciidoc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. [[fix-common-cluster-issues]]
  2. == Fix common cluster issues
  3. This guide describes how to fix common errors and problems with {es} clusters.
  4. [discrete]
  5. === Error: disk usage exceeded flood-stage watermark, index has read-only-allow-delete block
  6. This error indicates a data node is critically low on disk space and has reached
  7. the <<cluster-routing-flood-stage,flood-stage disk usage watermark>>. To prevent
  8. a full disk, when a node reaches this watermark, {es} blocks writes to any index
  9. with a shard on the node. If the block affects related system indices, {kib} and
  10. other {stack} features may become unavailable.
  11. {es} will automatically remove the write block when the affected node's disk
  12. usage goes below the <<cluster-routing-watermark-high,high disk watermark>>. To
  13. achieve this, {es} automatically moves some of the affected node's shards to
  14. other nodes in the same data tier.
  15. To verify that shards are moving off the affected node, use the <<cat-shards,cat
  16. shards API>>.
  17. [source,console]
  18. ----
  19. GET _cat/shards?v=true
  20. ----
  21. If shards remain on the node, use the <<cluster-allocation-explain,cluster
  22. allocation explanation API>> to get an explanation for their allocation status.
  23. [source,console]
  24. ----
  25. GET _cluster/allocation/explain
  26. {
  27. "index": "my-index",
  28. "shard": 0,
  29. "primary": false,
  30. "current_node": "my-node"
  31. }
  32. ----
  33. // TEST[s/^/PUT my-index\n/]
  34. // TEST[s/"primary": false,/"primary": false/]
  35. // TEST[s/"current_node": "my-node"//]
  36. To immediately restore write operations, you can temporarily increase the disk
  37. watermarks and remove the write block.
  38. [source,console]
  39. ----
  40. PUT _cluster/settings
  41. {
  42. "persistent": {
  43. "cluster.routing.allocation.disk.watermark.low": "90%",
  44. "cluster.routing.allocation.disk.watermark.low.max_headroom": "100GB",
  45. "cluster.routing.allocation.disk.watermark.high": "95%",
  46. "cluster.routing.allocation.disk.watermark.high.max_headroom": "20GB",
  47. "cluster.routing.allocation.disk.watermark.flood_stage": "97%",
  48. "cluster.routing.allocation.disk.watermark.flood_stage.max_headroom": "5GB",
  49. "cluster.routing.allocation.disk.watermark.flood_stage.frozen": "97%",
  50. "cluster.routing.allocation.disk.watermark.flood_stage.frozen.max_headroom": "5GB"
  51. }
  52. }
  53. PUT */_settings?expand_wildcards=all
  54. {
  55. "index.blocks.read_only_allow_delete": null
  56. }
  57. ----
  58. // TEST[s/^/PUT my-index\n/]
  59. As a long-term solution, we recommend you add nodes to the affected data tiers
  60. or upgrade existing nodes to increase disk space. To free up additional disk
  61. space, you can delete unneeded indices using the <<indices-delete-index,delete
  62. index API>>.
  63. [source,console]
  64. ----
  65. DELETE my-index
  66. ----
  67. // TEST[s/^/PUT my-index\n/]
  68. When a long-term solution is in place, reset or reconfigure the disk watermarks.
  69. [source,console]
  70. ----
  71. PUT _cluster/settings
  72. {
  73. "persistent": {
  74. "cluster.routing.allocation.disk.watermark.low": null,
  75. "cluster.routing.allocation.disk.watermark.low.max_headroom": null,
  76. "cluster.routing.allocation.disk.watermark.high": null,
  77. "cluster.routing.allocation.disk.watermark.high.max_headroom": null,
  78. "cluster.routing.allocation.disk.watermark.flood_stage": null,
  79. "cluster.routing.allocation.disk.watermark.flood_stage.max_headroom": null,
  80. "cluster.routing.allocation.disk.watermark.flood_stage.frozen": null,
  81. "cluster.routing.allocation.disk.watermark.flood_stage.frozen.max_headroom": null
  82. }
  83. }
  84. ----
  85. [discrete]
  86. [[circuit-breaker-errors]]
  87. === Circuit breaker errors
  88. {es} uses <<circuit-breaker,circuit breakers>> to prevent nodes from running out
  89. of JVM heap memory. If Elasticsearch estimates an operation would exceed a
  90. circuit breaker, it stops the operation and returns an error.
  91. By default, the <<parent-circuit-breaker,parent circuit breaker>> triggers at
  92. 95% JVM memory usage. To prevent errors, we recommend taking steps to reduce
  93. memory pressure if usage consistently exceeds 85%.
  94. [discrete]
  95. [[diagnose-circuit-breaker-errors]]
  96. ==== Diagnose circuit breaker errors
  97. **Error messages**
  98. If a request triggers a circuit breaker, {es} returns an error with a `429` HTTP
  99. status code.
  100. [source,js]
  101. ----
  102. {
  103. 'error': {
  104. 'type': 'circuit_breaking_exception',
  105. '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]',
  106. 'bytes_wanted': 123848638,
  107. 'bytes_limit': 123273216,
  108. 'durability': 'TRANSIENT'
  109. },
  110. 'status': 429
  111. }
  112. ----
  113. // NOTCONSOLE
  114. {es} also writes circuit breaker errors to <<logging,`elasticsearch.log`>>. This
  115. is helpful when automated processes, such as allocation, trigger a circuit
  116. breaker.
  117. [source,txt]
  118. ----
  119. 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]
  120. ----
  121. **Check JVM memory usage**
  122. If you've enabled Stack Monitoring, you can view JVM memory usage in {kib}. In
  123. the main menu, click **Stack Monitoring**. On the Stack Monitoring **Overview**
  124. page, click **Nodes**. The **JVM Heap** column lists the current memory usage
  125. for each node.
  126. You can also use the <<cat-nodes,cat nodes API>> to get the current
  127. `heap.percent` for each node.
  128. [source,console]
  129. ----
  130. GET _cat/nodes?v=true&h=name,node*,heap*
  131. ----
  132. To get the JVM memory usage for each circuit breaker, use the
  133. <<cluster-nodes-stats,node stats API>>.
  134. [source,console]
  135. ----
  136. GET _nodes/stats/breaker
  137. ----
  138. [discrete]
  139. [[prevent-circuit-breaker-errors]]
  140. ==== Prevent circuit breaker errors
  141. **Reduce JVM memory pressure**
  142. High JVM memory pressure often causes circuit breaker errors. See
  143. <<high-jvm-memory-pressure>>.
  144. **Avoid using fielddata on `text` fields**
  145. For high-cardinality `text` fields, fielddata can use a large amount of JVM
  146. memory. To avoid this, {es} disables fielddata on `text` fields by default. If
  147. you've enabled fielddata and triggered the <<fielddata-circuit-breaker,fielddata
  148. circuit breaker>>, consider disabling it and using a `keyword` field instead.
  149. See <<fielddata>>.
  150. **Clear the fieldata cache**
  151. If you've triggered the fielddata circuit breaker and can't disable fielddata,
  152. use the <<indices-clearcache,clear cache API>> to clear the fielddata cache.
  153. This may disrupt any in-flight searches that use fielddata.
  154. [source,console]
  155. ----
  156. POST _cache/clear?fielddata=true
  157. ----
  158. // TEST[s/^/PUT my-index\n/]
  159. [discrete]
  160. [[high-cpu-usage]]
  161. === High CPU usage
  162. {es} uses <<modules-threadpool,thread pools>> to manage CPU resources for
  163. concurrent operations. High CPU usage typically means one or more thread pools
  164. are running low.
  165. If a thread pool is depleted, {es} will <<rejected-requests,reject requests>>
  166. related to the thread pool. For example, if the `search` thread pool is
  167. depleted, {es} will reject search requests until more threads are available.
  168. [discrete]
  169. [[diagnose-high-cpu-usage]]
  170. ==== Diagnose high CPU usage
  171. **Check CPU usage**
  172. include::{es-repo-dir}/tab-widgets/cpu-usage-widget.asciidoc[]
  173. **Check hot threads**
  174. If a node has high CPU usage, use the <<cluster-nodes-hot-threads,nodes hot
  175. threads API>> to check for resource-intensive threads running on the node.
  176. [source,console]
  177. ----
  178. GET _nodes/my-node,my-other-node/hot_threads
  179. ----
  180. // TEST[s/\/my-node,my-other-node//]
  181. This API returns a breakdown of any hot threads in plain text.
  182. [discrete]
  183. [[reduce-cpu-usage]]
  184. ==== Reduce CPU usage
  185. The following tips outline the most common causes of high CPU usage and their
  186. solutions.
  187. **Scale your cluster**
  188. Heavy indexing and search loads can deplete smaller thread pools. To better
  189. handle heavy workloads, add more nodes to your cluster or upgrade your existing
  190. nodes to increase capacity.
  191. **Spread out bulk requests**
  192. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  193. or <<search-multi-search,multi-search>> requests still require CPU resources. If
  194. possible, submit smaller requests and allow more time between them.
  195. **Cancel long-running searches**
  196. Long-running searches can block threads in the `search` thread pool. To check
  197. for these searches, use the <<tasks,task management API>>.
  198. [source,console]
  199. ----
  200. GET _tasks?actions=*search&detailed
  201. ----
  202. The response's `description` contains the search request and its queries.
  203. `running_time_in_nanos` shows how long the search has been running.
  204. [source,console-result]
  205. ----
  206. {
  207. "nodes" : {
  208. "oTUltX4IQMOUUVeiohTt8A" : {
  209. "name" : "my-node",
  210. "transport_address" : "127.0.0.1:9300",
  211. "host" : "127.0.0.1",
  212. "ip" : "127.0.0.1:9300",
  213. "tasks" : {
  214. "oTUltX4IQMOUUVeiohTt8A:464" : {
  215. "node" : "oTUltX4IQMOUUVeiohTt8A",
  216. "id" : 464,
  217. "type" : "transport",
  218. "action" : "indices:data/read/search",
  219. "description" : "indices[my-index], search_type[QUERY_THEN_FETCH], source[{\"query\":...}]",
  220. "start_time_in_millis" : 4081771730000,
  221. "running_time_in_nanos" : 13991383,
  222. "cancellable" : true
  223. }
  224. }
  225. }
  226. }
  227. }
  228. ----
  229. // TESTRESPONSE[skip: no way to get tasks]
  230. To cancel a search and free up resources, use the API's `_cancel` endpoint.
  231. [source,console]
  232. ----
  233. POST _tasks/oTUltX4IQMOUUVeiohTt8A:464/_cancel
  234. ----
  235. For additional tips on how to track and avoid resource-intensive searches, see
  236. <<avoid-expensive-searches,Avoid expensive searches>>.
  237. [discrete]
  238. [[high-jvm-memory-pressure]]
  239. === High JVM memory pressure
  240. High JVM memory usage can degrade cluster performance and trigger
  241. <<circuit-breaker-errors,circuit breaker errors>>. To prevent this, we recommend
  242. taking steps to reduce memory pressure if a node's JVM memory usage consistently
  243. exceeds 85%.
  244. [discrete]
  245. [[diagnose-high-jvm-memory-pressure]]
  246. ==== Diagnose high JVM memory pressure
  247. **Check JVM memory pressure**
  248. include::{es-repo-dir}/tab-widgets/jvm-memory-pressure-widget.asciidoc[]
  249. **Check garbage collection logs**
  250. As memory usage increases, garbage collection becomes more frequent and takes
  251. longer. You can track the frequency and length of garbage collection events in
  252. <<logging,`elasticsearch.log`>>. For example, the following event states {es}
  253. spent more than 50% (21 seconds) of the last 40 seconds performing garbage
  254. collection.
  255. [source,log]
  256. ----
  257. [timestamp_short_interval_from_last][INFO ][o.e.m.j.JvmGcMonitorService] [node_id] [gc][number] overhead, spent [21s] collecting in the last [40s]
  258. ----
  259. [discrete]
  260. [[reduce-jvm-memory-pressure]]
  261. ==== Reduce JVM memory pressure
  262. **Reduce your shard count**
  263. Every shard uses memory. In most cases, a small set of large shards uses fewer
  264. resources than many small shards. For tips on reducing your shard count, see
  265. <<size-your-shards>>.
  266. [[avoid-expensive-searches]]
  267. **Avoid expensive searches**
  268. Expensive searches can use large amounts of memory. To better track expensive
  269. searches on your cluster, enable <<index-modules-slowlog,slow logs>>.
  270. Expensive searches may have a large <<paginate-search-results,`size` argument>>,
  271. use aggregations with a large number of buckets, or include
  272. <<query-dsl-allow-expensive-queries,expensive queries>>. To prevent expensive
  273. searches, consider the following setting changes:
  274. * Lower the `size` limit using the
  275. <<index-max-result-window,`index.max_result_window`>> index setting.
  276. * Decrease the maximum number of allowed aggregation buckets using the
  277. <<search-settings-max-buckets,search.max_buckets>> cluster setting.
  278. * Disable expensive queries using the
  279. <<query-dsl-allow-expensive-queries,`search.allow_expensive_queries`>> cluster
  280. setting.
  281. [source,console]
  282. ----
  283. PUT _settings
  284. {
  285. "index.max_result_window": 5000
  286. }
  287. PUT _cluster/settings
  288. {
  289. "persistent": {
  290. "search.max_buckets": 20000,
  291. "search.allow_expensive_queries": false
  292. }
  293. }
  294. ----
  295. // TEST[s/^/PUT my-index\n/]
  296. **Prevent mapping explosions**
  297. Defining too many fields or nesting fields too deeply can lead to
  298. <<mapping-limit-settings,mapping explosions>> that use large amounts of memory.
  299. To prevent mapping explosions, use the <<mapping-settings-limit,mapping limit
  300. settings>> to limit the number of field mappings.
  301. **Spread out bulk requests**
  302. While more efficient than individual requests, large <<docs-bulk,bulk indexing>>
  303. or <<search-multi-search,multi-search>> requests can still create high JVM
  304. memory pressure. If possible, submit smaller requests and allow more time
  305. between them.
  306. **Upgrade node memory**
  307. Heavy indexing and search loads can cause high JVM memory pressure. To better
  308. handle heavy workloads, upgrade your nodes to increase their memory capacity.
  309. [discrete]
  310. [[red-yellow-cluster-status]]
  311. === Red or yellow cluster status
  312. A red or yellow cluster status indicates one or more shards are missing or
  313. unallocated. These unassigned shards increase your risk of data loss and can
  314. degrade cluster performance.
  315. [discrete]
  316. [[diagnose-cluster-status]]
  317. ==== Diagnose your cluster status
  318. **Check your cluster status**
  319. Use the <<cluster-health,cluster health API>>.
  320. [source,console]
  321. ----
  322. GET _cluster/health?filter_path=status,*_shards
  323. ----
  324. A healthy cluster has a green `status` and zero `unassigned_shards`. A yellow
  325. status means only replicas are unassigned. A red status means one or
  326. more primary shards are unassigned.
  327. **View unassigned shards**
  328. To view unassigned shards, use the <<cat-shards,cat shards API>>.
  329. [source,console]
  330. ----
  331. GET _cat/shards?v=true&h=index,shard,prirep,state,node,unassigned.reason&s=state
  332. ----
  333. Unassigned shards have a `state` of `UNASSIGNED`. The `prirep` value is `p` for
  334. primary shards and `r` for replicas.
  335. To understand why an unassigned shard is not being assigned and what action
  336. you must take to allow {es} to assign it, use the
  337. <<cluster-allocation-explain,cluster allocation explanation API>>.
  338. [source,console]
  339. ----
  340. GET _cluster/allocation/explain?filter_path=index,node_allocation_decisions.node_name,node_allocation_decisions.deciders.*
  341. {
  342. "index": "my-index",
  343. "shard": 0,
  344. "primary": false,
  345. "current_node": "my-node"
  346. }
  347. ----
  348. // TEST[s/^/PUT my-index\n/]
  349. // TEST[s/"primary": false,/"primary": false/]
  350. // TEST[s/"current_node": "my-node"//]
  351. [discrete]
  352. [[fix-red-yellow-cluster-status]]
  353. ==== Fix a red or yellow cluster status
  354. A shard can become unassigned for several reasons. The following tips outline the
  355. most common causes and their solutions.
  356. **Re-enable shard allocation**
  357. You typically disable allocation during a <<restart-cluster,restart>> or other
  358. cluster maintenance. If you forgot to re-enable allocation afterward, {es} will
  359. be unable to assign shards. To re-enable allocation, reset the
  360. `cluster.routing.allocation.enable` cluster setting.
  361. [source,console]
  362. ----
  363. PUT _cluster/settings
  364. {
  365. "persistent" : {
  366. "cluster.routing.allocation.enable" : null
  367. }
  368. }
  369. ----
  370. **Recover lost nodes**
  371. Shards often become unassigned when a data node leaves the cluster. This can
  372. occur for several reasons, ranging from connectivity issues to hardware failure.
  373. After you resolve the issue and recover the node, it will rejoin the cluster.
  374. {es} will then automatically allocate any unassigned shards.
  375. To avoid wasting resources on temporary issues, {es} <<delayed-allocation,delays
  376. allocation>> by one minute by default. If you've recovered a node and don’t want
  377. to wait for the delay period, you can call the <<cluster-reroute,cluster reroute
  378. API>> with no arguments to start the allocation process. The process runs
  379. asynchronously in the background.
  380. [source,console]
  381. ----
  382. POST _cluster/reroute?metric=none
  383. ----
  384. **Fix allocation settings**
  385. Misconfigured allocation settings can result in an unassigned primary shard.
  386. These settings include:
  387. * <<shard-allocation-filtering,Shard allocation>> index settings
  388. * <<cluster-shard-allocation-filtering,Allocation filtering>> cluster settings
  389. * <<shard-allocation-awareness,Allocation awareness>> cluster settings
  390. To review your allocation settings, use the <<indices-get-settings,get index
  391. settings>> and <<cluster-get-settings,cluster get settings>> APIs.
  392. [source,console]
  393. ----
  394. GET my-index/_settings?flat_settings=true&include_defaults=true
  395. GET _cluster/settings?flat_settings=true&include_defaults=true
  396. ----
  397. // TEST[s/^/PUT my-index\n/]
  398. You can change the settings using the <<indices-update-settings,update index
  399. settings>> and <<cluster-update-settings,cluster update settings>> APIs.
  400. **Allocate or reduce replicas**
  401. To protect against hardware failure, {es} will not assign a replica to the same
  402. node as its primary shard. If no other data nodes are available to host the
  403. replica, it remains unassigned. To fix this, you can:
  404. * Add a data node to the same tier to host the replica.
  405. * Change the `index.number_of_replicas` index setting to reduce the number of
  406. replicas for each primary shard. We recommend keeping at least one replica per
  407. primary.
  408. [source,console]
  409. ----
  410. PUT _settings
  411. {
  412. "index.number_of_replicas": 1
  413. }
  414. ----
  415. // TEST[s/^/PUT my-index\n/]
  416. **Free up or increase disk space**
  417. {es} uses a <<disk-based-shard-allocation,low disk watermark>> to ensure data
  418. nodes have enough disk space for incoming shards. By default, {es} does not
  419. allocate shards to nodes using more than 85% of disk space.
  420. To check the current disk space of your nodes, use the <<cat-allocation,cat
  421. allocation API>>.
  422. [source,console]
  423. ----
  424. GET _cat/allocation?v=true&h=node,shards,disk.*
  425. ----
  426. If your nodes are running low on disk space, you have a few options:
  427. * Upgrade your nodes to increase disk space.
  428. * Delete unneeded indices to free up space. If you use {ilm-init}, you can
  429. update your lifecycle policy to use <<ilm-searchable-snapshot,searchable
  430. snapshots>> or add a delete phase. If you no longer need to search the data, you
  431. can use a <<snapshot-restore,snapshot>> to store it off-cluster.
  432. * If you no longer write to an index, use the <<indices-forcemerge,force merge
  433. API>> or {ilm-init}'s <<ilm-forcemerge,force merge action>> to merge its
  434. segments into larger ones.
  435. +
  436. [source,console]
  437. ----
  438. POST my-index/_forcemerge
  439. ----
  440. // TEST[s/^/PUT my-index\n/]
  441. * If an index is read-only, use the <<indices-shrink-index,shrink index API>> or
  442. {ilm-init}'s <<ilm-shrink,shrink action>> to reduce its primary shard count.
  443. +
  444. [source,console]
  445. ----
  446. POST my-index/_shrink/my-shrunken-index
  447. ----
  448. // TEST[s/^/PUT my-index\n{"settings":{"index.number_of_shards":2,"blocks.write":true}}\n/]
  449. * If your node has a large disk capacity, you can increase the low disk
  450. watermark or set it to an explicit byte value.
  451. +
  452. [source,console]
  453. ----
  454. PUT _cluster/settings
  455. {
  456. "persistent": {
  457. "cluster.routing.allocation.disk.watermark.low": "30gb"
  458. }
  459. }
  460. ----
  461. // TEST[s/"30gb"/null/]
  462. **Reduce JVM memory pressure**
  463. Shard allocation requires JVM heap memory. High JVM memory pressure can trigger
  464. <<circuit-breaker,circuit breakers>> that stop allocation and leave shards
  465. unassigned. See <<high-jvm-memory-pressure>>.
  466. **Recover data for a lost primary shard**
  467. If a node containing a primary shard is lost, {es} can typically replace it
  468. using a replica on another node. If you can't recover the node and replicas
  469. don't exist or are irrecoverable, you'll need to re-add the missing data from a
  470. <<snapshot-restore,snapshot>> or the original data source.
  471. WARNING: Only use this option if node recovery is no longer possible. This
  472. process allocates an empty primary shard. If the node later rejoins the cluster,
  473. {es} will overwrite its primary shard with data from this newer empty shard,
  474. resulting in data loss.
  475. Use the <<cluster-reroute,cluster reroute API>> to manually allocate the
  476. unassigned primary shard to another data node in the same tier. Set
  477. `accept_data_loss` to `true`.
  478. [source,console]
  479. ----
  480. POST _cluster/reroute?metric=none
  481. {
  482. "commands": [
  483. {
  484. "allocate_empty_primary": {
  485. "index": "my-index",
  486. "shard": 0,
  487. "node": "my-node",
  488. "accept_data_loss": "true"
  489. }
  490. }
  491. ]
  492. }
  493. ----
  494. // TEST[s/^/PUT my-index\n/]
  495. // TEST[catch:bad_request]
  496. If you backed up the missing index data to a snapshot, use the
  497. <<restore-snapshot-api,restore snapshot API>> to restore the individual index.
  498. Alternatively, you can index the missing data from the original data source.
  499. [discrete]
  500. [[rejected-requests]]
  501. === Rejected requests
  502. When {es} rejects a request, it stops the operation and returns an error with a
  503. `429` response code. Rejected requests are commonly caused by:
  504. * A <<high-cpu-usage,depleted thread pool>>. A depleted `search` or `write`
  505. thread pool returns a `TOO_MANY_REQUESTS` error message.
  506. * A <<circuit-breaker-errors,circuit breaker error>>.
  507. * High <<index-modules-indexing-pressure,indexing pressure>> that exceeds the
  508. <<memory-limits,`indexing_pressure.memory.limit`>>.
  509. [discrete]
  510. [[check-rejected-tasks]]
  511. ==== Check rejected tasks
  512. To check the number of rejected tasks for each thread pool, use the
  513. <<cat-thread-pool,cat thread pool API>>. A high ratio of `rejected` to
  514. `completed` tasks, particularly in the `search` and `write` thread pools, means
  515. {es} regularly rejects requests.
  516. [source,console]
  517. ----
  518. GET /_cat/thread_pool?v=true&h=id,name,active,rejected,completed
  519. ----
  520. [discrete]
  521. [[prevent-rejected-requests]]
  522. ==== Prevent rejected requests
  523. **Fix high CPU and memory usage**
  524. If {es} regularly rejects requests and other tasks, your cluster likely has high
  525. CPU usage or high JVM memory pressure. For tips, see <<high-cpu-usage>> and
  526. <<high-jvm-memory-pressure>>.
  527. **Prevent circuit breaker errors**
  528. If you regularly trigger circuit breaker errors, see <<circuit-breaker-errors>>
  529. for tips on diagnosing and preventing them.
  530. [discrete]
  531. [[task-queue-backlog]]
  532. === Task queue backlog
  533. A backlogged task queue can prevent tasks from completing and
  534. put the cluster into an unhealthy state.
  535. Resource constraints, a large number of tasks being triggered at once,
  536. and long running tasks can all contribute to a backlogged task queue.
  537. [discrete]
  538. [[diagnose-task-queue-backlog]]
  539. ==== Diagnose a task queue backlog
  540. **Check the thread pool status**
  541. A <<high-cpu-usage,depleted thread pool>> can result in <<rejected-requests,rejected requests>>.
  542. You can use the <<cat-thread-pool,cat thread pool API>> to
  543. see the number of active threads in each thread pool and
  544. how many tasks are queued, how many have been rejected, and how many have completed.
  545. [source,console]
  546. ----
  547. GET /_cat/thread_pool?v&s=t,n&h=type,name,node_name,active,queue,rejected,completed
  548. ----
  549. **Inspect the hot threads on each node**
  550. If a particular thread pool queue is backed up,
  551. you can periodically poll the <<cluster-nodes-hot-threads,Nodes hot threads>> API
  552. to determine if the thread has sufficient
  553. resources to progress and gauge how quickly it is progressing.
  554. [source,console]
  555. ----
  556. GET /_nodes/hot_threads
  557. ----
  558. **Look for long running tasks**
  559. Long-running tasks can also cause a backlog.
  560. You can use the <<tasks,task management>> API to get information about the tasks that are running.
  561. Check the `running_time_in_nanos` to identify tasks that are taking an excessive amount of time to complete.
  562. [source,console]
  563. ----
  564. GET /_tasks?filter_path=nodes.*.tasks
  565. ----
  566. [discrete]
  567. [[resolve-task-queue-backlog]]
  568. ==== Resolve a task queue backlog
  569. **Increase available resources**
  570. If tasks are progressing slowly and the queue is backing up,
  571. you might need to take steps to <<reduce-cpu-usage>>.
  572. In some cases, increasing the thread pool size might help.
  573. For example, the `force_merge` thread pool defaults to a single thread.
  574. Increasing the size to 2 might help reduce a backlog of force merge requests.
  575. **Cancel stuck tasks**
  576. If you find the active task's hot thread isn't progressing and there's a backlog,
  577. consider canceling the task.