flush.asciidoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. [[indices-flush]]
  2. == Flush
  3. The flush API allows to flush one or more indices through an API. The
  4. flush process of an index basically frees memory from the index by
  5. flushing data to the index storage and clearing the internal
  6. <<index-modules-translog,transaction log>>. By
  7. default, Elasticsearch uses memory heuristics in order to automatically
  8. trigger flush operations as required in order to clear memory.
  9. [source,js]
  10. --------------------------------------------------
  11. POST /twitter/_flush
  12. --------------------------------------------------
  13. // AUTOSENSE
  14. [float]
  15. [[flush-parameters]]
  16. === Request Parameters
  17. The flush API accepts the following request parameters:
  18. [horizontal]
  19. `wait_if_ongoing`:: If set to `true` the flush operation will block until the
  20. flush can be executed if another flush operation is already executing.
  21. The default is `false` and will cause an exception to be thrown on
  22. the shard level if another flush operation is already running.
  23. `force`:: Whether a flush should be forced even if it is not necessarily needed ie.
  24. if no changes will be committed to the index. This is useful if transaction log IDs
  25. should be incremented even if no uncommitted changes are present.
  26. (This setting can be considered as internal)
  27. [float]
  28. [[flush-multi-index]]
  29. === Multi Index
  30. The flush API can be applied to more than one index with a single call,
  31. or even on `_all` the indices.
  32. [source,js]
  33. --------------------------------------------------
  34. POST /kimchy,elasticsearch/_flush
  35. POST /_flush
  36. --------------------------------------------------
  37. // AUTOSENSE
  38. [[indices-synced-flush]]
  39. === Synced Flush
  40. Elasticsearch tracks the indexing activity of each shards. Shards that have not
  41. received any indexing operations for, by default, 30m are automatically marked as inactive. This presents
  42. an opportunity for Elasticsearch to reduce shard resources and also perform
  43. a special kind of flush, called `synced flush`. A synced flush performs normal
  44. flushing and adds a special uniquely generated marker (`sync_id`) to all shards.
  45. Since the sync id marker was added when there were no ongoing indexing operations, it can
  46. be used as a quick way to check if two shards indices are identical. This quick sync id
  47. comparison (if present) is used during recovery or restarts to skip the first and
  48. most costly phase of the process. In that case, no segment files need to be copied and
  49. the transaction log replay phase of the recovery can start immediately. Note that since the sync id
  50. marker was applied together with a flush, it is highly likely that the transaction log will be empty,
  51. speeding up recoveries even more.
  52. This is particularly useful for use cases having lots of indices which are
  53. never or very rarely updated, such as time based data. This use case typically generates lots of indices whose
  54. recovery without the synced flush marker would take a long time.
  55. To check whether a shard has a marker or not, one can use the `commit` section of shard stats returned by
  56. the <<indices-stats,indices stats>> API:
  57. [source,bash]
  58. --------------------------------------------------
  59. GET /twitter/_stats/commit?level=shards
  60. --------------------------------------------------
  61. // AUTOSENSE
  62. [float]
  63. === Synced Flush API
  64. The Synced Flush API allows an administrator to initiate a synced flush manually. This can particularly useful for
  65. a planned (rolling) cluster restart where one can stop indexing and doesn't want to wait for the default 30m to pass
  66. when the synced flush will be performed automatically.
  67. While handy, there are a couple of caveats for this API:
  68. 1. Synced flush is a best effort operation. Any ongoing indexing operations will cause
  69. the synced flush to fail. This means that some shards may be synced flushed while others aren't. See below for more.
  70. 2. The `sync_id` marker is removed as soon as the shard is flushed again. Uncommitted
  71. operations in the transaction log do not remove the marker. That is because the marker is store as part
  72. of a low level lucene commit, representing a point in time snapshot of the segments. In practice, one should consider
  73. any indexing operation on an index as removing the marker.
  74. [source,bash]
  75. --------------------------------------------------
  76. POST /twitter/_flush/synced
  77. --------------------------------------------------
  78. // AUTOSENSE
  79. The response contains details about how many shards were successfully synced-flushed and information about any failure.
  80. Here is what it looks like when all shards of a two shards and one replica index successfully
  81. sync-flushed:
  82. [source,js]
  83. --------------------------------------------------
  84. {
  85. "_shards": {
  86. "total": 4,
  87. "successful": 4,
  88. "failed": 0
  89. },
  90. "twitter": {
  91. "total": 4,
  92. "successful": 4,
  93. "failed": 0
  94. }
  95. }
  96. --------------------------------------------------
  97. Here is what it looks like when one shard group failed due to pending operations:
  98. [source,js]
  99. --------------------------------------------------
  100. {
  101. "_shards": {
  102. "total": 4,
  103. "successful": 2,
  104. "failed": 2
  105. },
  106. "twitter": {
  107. "total": 4,
  108. "successful": 2,
  109. "failed": 2,
  110. "failures": [
  111. {
  112. "shard": 1,
  113. "reason": "[2] ongoing operations on primary"
  114. }
  115. ]
  116. }
  117. }
  118. --------------------------------------------------
  119. Sometimes the failures are specific to a shard copy, in which case they will be reported as follows:
  120. [source,js]
  121. --------------------------------------------------
  122. {
  123. "_shards": {
  124. "total": 4,
  125. "successful": 1,
  126. "failed": 1
  127. },
  128. "twitter": {
  129. "total": 4,
  130. "successful": 3,
  131. "failed": 1,
  132. "failures": [
  133. {
  134. "shard": 1,
  135. "reason": "unexpected error",
  136. "routing": {
  137. "state": "STARTED",
  138. "primary": false,
  139. "node": "SZNr2J_ORxKTLUCydGX4zA",
  140. "relocating_node": null,
  141. "shard": 1,
  142. "index": "twitter"
  143. }
  144. }
  145. ]
  146. }
  147. }
  148. --------------------------------------------------
  149. The synced flush API can be applied to more than one index with a single call,
  150. or even on `_all` the indices.
  151. [source,js]
  152. --------------------------------------------------
  153. POST /kimchy,elasticsearch/_flush/synced
  154. POST /_flush/synced
  155. --------------------------------------------------
  156. // AUTOSENSE