synced-flush.asciidoc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. [[indices-synced-flush-api]]
  2. === Synced flush API
  3. ++++
  4. <titleabbrev>Synced flush</titleabbrev>
  5. ++++
  6. Performs a synced flush on one or more indices.
  7. [source,console]
  8. --------------------------------------------------
  9. POST /twitter/_flush/synced
  10. --------------------------------------------------
  11. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  12. [[synced-flush-api-request]]
  13. ==== {api-request-title}
  14. `POST /<index>/flush/synced`
  15. `GET /<index>/flush/synced`
  16. `POST /flush/synced`
  17. `GET /flush/synced`
  18. [[synced-flush-api-desc]]
  19. ==== {api-description-title}
  20. [[synced-flush-using-api]]
  21. ===== Use the synced flush API
  22. Use the synced flush API to manually initiate a synced flush.
  23. This can be useful for a planned cluster restart where
  24. you can stop indexing but don't want to wait for 5 minutes until all indices
  25. are marked as inactive and automatically sync-flushed.
  26. You can request a synced flush even if there is ongoing indexing activity, and
  27. {es} will perform the synced flush on a "best-effort" basis: shards that do not
  28. have any ongoing indexing activity will be successfully sync-flushed, and other
  29. shards will fail to sync-flush. The successfully sync-flushed shards will have
  30. faster recovery times as long as the `sync_id` marker is not removed by a
  31. subsequent flush.
  32. [[synced-flush-overview]]
  33. ===== Synced flush overview
  34. {es} keeps track of which shards have received indexing activity recently, and
  35. considers shards that have not received any indexing operations for 5 minutes to
  36. be inactive.
  37. When a shard becomes inactive {es} performs a special kind of flush
  38. known as a *synced flush*. A synced flush performs a normal
  39. <<indices-flush,flush>> on each replica of the shard, and then adds a marker known
  40. as the `sync_id` to each replica to indicate that these copies have identical
  41. Lucene indices. Comparing the `sync_id` markers of the two copies is a very
  42. efficient way to check whether they have identical contents.
  43. When allocating shard replicas, {es} must ensure that each replica contains the
  44. same data as the primary. If the shard copies have been synced-flushed and the
  45. replica shares a `sync_id` with the primary then {es} knows that the two copies
  46. have identical contents. This means there is no need to copy any segment files
  47. from the primary to the replica, which saves a good deal of time during
  48. recoveries and restarts.
  49. This is particularly useful for clusters having lots of indices which are very
  50. rarely updated, such as with time-based indices. Without the synced flush
  51. marker, recovery of this kind of cluster would be much slower.
  52. [[synced-flush-sync-id-markers]]
  53. ===== Check for `sync_id` markers
  54. To check whether a shard has a `sync_id` marker or not, look for the `commit`
  55. section of the shard stats returned by the <<indices-stats,indices stats>> API:
  56. [source,console]
  57. --------------------------------------------------
  58. GET /twitter/_stats?filter_path=**.commit&level=shards <1>
  59. --------------------------------------------------
  60. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  61. <1> `filter_path` is used to reduce the verbosity of the response, but is entirely optional
  62. The API returns the following response:
  63. [source,console-result]
  64. --------------------------------------------------
  65. {
  66. "indices": {
  67. "twitter": {
  68. "shards": {
  69. "0": [
  70. {
  71. "commit" : {
  72. "id" : "3M3zkw2GHMo2Y4h4/KFKCg==",
  73. "generation" : 3,
  74. "user_data" : {
  75. "translog_uuid" : "hnOG3xFcTDeoI_kvvvOdNA",
  76. "history_uuid" : "XP7KDJGiS1a2fHYiFL5TXQ",
  77. "local_checkpoint" : "-1",
  78. "translog_generation" : "2",
  79. "max_seq_no" : "-1",
  80. "sync_id" : "AVvFY-071siAOuFGEO9P", <1>
  81. "max_unsafe_auto_id_timestamp" : "-1",
  82. "min_retained_seq_no" : "0"
  83. },
  84. "num_docs" : 0
  85. }
  86. }
  87. ]
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------
  93. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  94. <1> the `sync id` marker
  95. NOTE: The `sync_id` marker is removed as soon as the shard is flushed again, and
  96. {es} may trigger an automatic flush of a shard at any time if there are
  97. unflushed operations in the shard's translog. In practice this means that one
  98. should consider any indexing operation on an index as having removed its
  99. `sync_id` markers.
  100. [[synced-flush-api-path-params]]
  101. ==== {api-path-parms-title}
  102. include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
  103. +
  104. To sync-flush all indices,
  105. omit this parameter
  106. or use a value of `_all` or `*`.
  107. [[synced-flush-api-query-params]]
  108. ==== {api-query-parms-title}
  109. include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
  110. include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
  111. +
  112. Defaults to `open`.
  113. include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
  114. [[synced-flush-api-response-codes]]
  115. ==== {api-response-codes-title}
  116. `200`::
  117. All shards successfully sync-flushed.
  118. `409`::
  119. A replica shard failed to sync-flush.
  120. [[synced-flush-api-example]]
  121. ==== {api-examples-title}
  122. [[synced-flush-api-specific-ex]]
  123. ===== Sync-flush a specific index
  124. [source,console]
  125. ----
  126. POST /kimchy/_flush/synced
  127. ----
  128. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  129. [[synced-flush-api-multi-ex]]
  130. ===== Synch-flush several indices
  131. [source,console]
  132. --------------------------------------------------
  133. POST /kimchy,elasticsearch/_flush/synced
  134. --------------------------------------------------
  135. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  136. [[synced-flush-api-all-ex]]
  137. ===== Sync-flush all indices
  138. [source,console]
  139. --------------------------------------------------
  140. POST /_flush/synced
  141. --------------------------------------------------
  142. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  143. The response contains details about how many shards were successfully
  144. sync-flushed and information about any failure.
  145. The following response indicates two shards
  146. and one replica shard
  147. successfully sync-flushed:
  148. [source,console-result]
  149. --------------------------------------------------
  150. {
  151. "_shards": {
  152. "total": 2,
  153. "successful": 2,
  154. "failed": 0
  155. },
  156. "twitter": {
  157. "total": 2,
  158. "successful": 2,
  159. "failed": 0
  160. }
  161. }
  162. --------------------------------------------------
  163. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  164. The following response indicates one shard group failed
  165. due to pending operations:
  166. [source,console-result]
  167. --------------------------------------------------
  168. {
  169. "_shards": {
  170. "total": 4,
  171. "successful": 2,
  172. "failed": 2
  173. },
  174. "twitter": {
  175. "total": 4,
  176. "successful": 2,
  177. "failed": 2,
  178. "failures": [
  179. {
  180. "shard": 1,
  181. "reason": "[2] ongoing operations on primary"
  182. }
  183. ]
  184. }
  185. }
  186. --------------------------------------------------
  187. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]
  188. Sometimes the failures are specific to a shard replica. The copies that failed
  189. will not be eligible for fast recovery but those that succeeded still will be.
  190. This case is reported as follows:
  191. [source,console-result]
  192. --------------------------------------------------
  193. {
  194. "_shards": {
  195. "total": 4,
  196. "successful": 1,
  197. "failed": 1
  198. },
  199. "twitter": {
  200. "total": 4,
  201. "successful": 3,
  202. "failed": 1,
  203. "failures": [
  204. {
  205. "shard": 1,
  206. "reason": "unexpected error",
  207. "routing": {
  208. "state": "STARTED",
  209. "primary": false,
  210. "node": "SZNr2J_ORxKTLUCydGX4zA",
  211. "relocating_node": null,
  212. "shard": 1,
  213. "index": "twitter"
  214. }
  215. }
  216. ]
  217. }
  218. }
  219. --------------------------------------------------
  220. // TEST[skip: Synced flush can conflict with scheduled flushes in doc tests]