history-retention.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. [[index-modules-history-retention]]
  2. == History retention
  3. {es} sometimes needs to replay some of the operations that were performed on a
  4. shard. For instance, if a replica is briefly offline then it may be much more
  5. efficient to replay the few operations it missed while it was offline than to
  6. rebuild it from scratch. Similarly, {ccr} works by performing operations on the
  7. leader cluster and then replaying those operations on the follower cluster.
  8. At the Lucene level there are really only two write operations that {es}
  9. performs on an index: a new document may be indexed, or an existing document may
  10. be deleted. Updates are implemented by atomically deleting the old document and
  11. then indexing the new document. A document indexed into Lucene already contains
  12. all the information needed to replay that indexing operation, but this is not
  13. true of document deletions. To solve this, {es} uses a feature called _soft
  14. deletes_ to preserve recent deletions in the Lucene index so that they can be
  15. replayed.
  16. {es} only preserves certain recently-deleted documents in the index because a
  17. soft-deleted document still takes up some space. Eventually {es} will fully
  18. discard these soft-deleted documents to free up that space so that the index
  19. does not grow larger and larger over time. Fortunately {es} does not need to be
  20. able to replay every operation that has ever been performed on a shard, because
  21. it is always possible to make a full copy of a shard on a remote node. However,
  22. copying the whole shard may take much longer than replaying a few missing
  23. operations, so {es} tries to retain all of the operations it expects to need to
  24. replay in future.
  25. {es} keeps track of the operations it expects to need to replay in future using
  26. a mechanism called _shard history retention leases_. Each shard copy that might
  27. need operations to be replayed must first create a shard history retention lease
  28. for itself. For example, this shard copy might be a replica of a shard or it
  29. might be a shard of a follower index when using {ccr}. Each retention lease
  30. keeps track of the sequence number of the first operation that the corresponding
  31. shard copy has not received. As the shard copy receives new operations, it
  32. increases the sequence number contained in its retention lease to indicate that
  33. it will not need to replay those operations in future. {es} discards
  34. soft-deleted operations once they are not being held by any retention lease.
  35. If a shard copy fails then it stops updating its shard history retention lease,
  36. which means that {es} will preserve all new operations so they can be replayed
  37. when the failed shard copy recovers. However, retention leases only last for a
  38. limited amount of time. If the shard copy does not recover quickly enough then
  39. its retention lease may expire. This protects {es} from retaining history
  40. forever if a shard copy fails permanently, because once a retention lease has
  41. expired {es} can start to discard history again. If a shard copy recovers after
  42. its retention lease has expired then {es} will fall back to copying the whole
  43. index since it can no longer simply replay the missing history. The expiry time
  44. of a retention lease defaults to `12h` which should be long enough for most
  45. reasonable recovery scenarios.
  46. [discrete]
  47. === History retention settings
  48. include::{es-ref-dir}/index-modules.asciidoc[tag=ccr-index-soft-deletes-tag]
  49. include::{es-ref-dir}/index-modules.asciidoc[tag=ccr-index-soft-deletes-retention-tag]