translog.asciidoc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. [[index-modules-translog]]
  2. == Translog
  3. Changes to Lucene are only persisted to disk during a Lucene commit,
  4. which is a relatively heavy operation and so cannot be performed after every
  5. index or delete operation. Changes that happen after one commit and before another
  6. will be lost in the event of process exit or HW failure.
  7. To prevent this data loss, each shard has a _transaction log_ or write ahead
  8. log associated with it. Any index or delete operation is written to the
  9. translog after being processed by the internal Lucene index.
  10. In the event of a crash, recent transactions can be replayed from the
  11. transaction log when the shard recovers.
  12. An Elasticsearch flush is the process of performing a Lucene commit and
  13. starting a new translog. It is done automatically in the background in order
  14. to make sure the transaction log doesn't grow too large, which would make
  15. replaying its operations take a considerable amount of time during recovery.
  16. It is also exposed through an API, though its rarely needed to be performed
  17. manually.
  18. [float]
  19. === Translog settings
  20. The data in the transaction log is only persisted to disk when the translog is
  21. ++fsync++ed and committed. In the event of hardware failure, any data written
  22. since the previous translog commit will be lost.
  23. By default, Elasticsearch ++fsync++s and commits the translog every 5 seconds if `index.translog.durability` is set
  24. to `async` or if set to `request` (default) at the end of every <<docs-index_,index>>, <<docs-delete,delete>>,
  25. <<docs-update,update>>, or <<docs-bulk,bulk>> request. In fact, Elasticsearch
  26. will only report success of an index, delete, update, or bulk request to the
  27. client after the transaction log has been successfully ++fsync++ed and committed
  28. on the primary and on every allocated replica.
  29. The following <<indices-update-settings,dynamically updatable>> per-index settings
  30. control the behaviour of the transaction log:
  31. `index.translog.sync_interval`::
  32. How often the translog is ++fsync++ed to disk and committed, regardless of
  33. write operations. Defaults to `5s`. Values less than `100ms` are not allowed.
  34. `index.translog.durability`::
  35. +
  36. --
  37. Whether or not to `fsync` and commit the translog after every index, delete,
  38. update, or bulk request. This setting accepts the following parameters:
  39. `request`::
  40. (default) `fsync` and commit after every request. In the event
  41. of hardware failure, all acknowledged writes will already have been
  42. committed to disk.
  43. `async`::
  44. `fsync` and commit in the background every `sync_interval`. In
  45. the event of hardware failure, all acknowledged writes since the last
  46. automatic commit will be discarded.
  47. --
  48. `index.translog.flush_threshold_size`::
  49. The translog stores all operations that are not yet safely persisted in Lucene (i.e., are
  50. not part of a lucene commit point). Although these operations are available for reads, they will
  51. need to be reindexed if the shard was to shutdown and has to be recovered. This settings controls
  52. the maximum total size of these operations, to prevent recoveries from taking too long. Once the
  53. maximum size has been reached a flush will happen, generating a new Lucene commit. Defaults to `512mb`.
  54. `index.translog.retention.size`::
  55. The total size of translog files to keep. Keeping more translog files increases the chance of performing
  56. an operation based sync when recovering replicas. If the translog files are not sufficient, replica recovery
  57. will fall back to a file based sync. Defaults to `512mb`
  58. `index.translog.retention.age`::
  59. The maximum duration for which translog files will be kept. Defaults to `12h`.
  60. [float]
  61. [[corrupt-translog-truncation]]
  62. === What to do if the translog becomes corrupted?
  63. In some cases (a bad drive, user error) the translog can become corrupted. When
  64. this corruption is detected by Elasticsearch due to mismatching checksums,
  65. Elasticsearch will fail the shard and refuse to allocate that copy of the data
  66. to the node, recovering from a replica if available.
  67. If there is no copy of the data from which Elasticsearch can recover
  68. successfully, a user may want to recover the data that is part of the shard at
  69. the cost of losing the data that is currently contained in the translog. We
  70. provide a command-line tool for this, `elasticsearch-translog`.
  71. [WARNING]
  72. The `elasticsearch-translog` tool should *not* be run while Elasticsearch is
  73. running, and you will permanently lose the documents that were contained only in
  74. the translog!
  75. In order to run the `elasticsearch-translog` tool, specify the `truncate`
  76. subcommand as well as the directory for the corrupted translog with the `-d`
  77. option:
  78. [source,txt]
  79. --------------------------------------------------
  80. $ bin/elasticsearch-translog truncate -d /var/lib/elasticsearchdata/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/
  81. Checking existing translog files
  82. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  83. ! WARNING: Elasticsearch MUST be stopped before running this tool !
  84. ! !
  85. ! WARNING: Documents inside of translog files will be lost !
  86. ! !
  87. ! WARNING: The following files will be DELETED! !
  88. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  89. --> data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-41.ckp
  90. --> data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-6.ckp
  91. --> data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-37.ckp
  92. --> data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-24.ckp
  93. --> data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-11.ckp
  94. Continue and DELETE files? [y/N] y
  95. Reading translog UUID information from Lucene commit from shard at [data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/index]
  96. Translog Generation: 3
  97. Translog UUID : AxqC4rocTC6e0fwsljAh-Q
  98. Removing existing translog files
  99. Creating new empty checkpoint at [data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog.ckp]
  100. Creating new empty translog at [data/nodes/0/indices/P45vf_YQRhqjfwLMUvSqDw/0/translog/translog-3.tlog]
  101. Done.
  102. --------------------------------------------------
  103. You can also use the `-h` option to get a list of all options and parameters
  104. that the `elasticsearch-translog` tool supports.