|
| 1 | +.. _configuration_persistence: |
| 2 | + |
| 3 | +Persistence |
| 4 | +=========== |
| 5 | + |
| 6 | +**Example on GitHub**: `persistence <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/persistence>`_ |
| 7 | + |
| 8 | +To ensure data persistence, Tarantool provides the abilities to: |
| 9 | + |
| 10 | +* record each data change request into a write-ahead log (WAL) file (``.xlog`` files) |
| 11 | +* take snapshots that contain on-disk copy of the entire data set for a given moment (``.snap`` files) |
| 12 | + |
| 13 | +During the recovery process, Tarantool can load the latest snapshot file and then read the requests from the WAL files, |
| 14 | +produced after this snapshot was made. |
| 15 | + |
| 16 | +To learn more about the persistence mechanism in Tarantool, see the :ref:`Persistence <concepts-data_model-persistence>` section. |
| 17 | +The formats of WAL and snapshot files are described in detail in the :ref:`File formats <internals-data_persistence>` section. |
| 18 | + |
| 19 | +.. _configuration_persistence_snapshot: |
| 20 | + |
| 21 | +Configure the snapshots |
| 22 | +----------------------- |
| 23 | + |
| 24 | +This section describes how to define snapshot settings in the :ref:`snapshot <configuration_reference_snapshot>` section of a YAML configuration. |
| 25 | + |
| 26 | +.. _configuration_persistence_snapshot_dir: |
| 27 | + |
| 28 | +Specify a directory for snapshot files |
| 29 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 30 | + |
| 31 | +To configure a directory where the snapshot files are stored, use the :ref:`snapshot.dir <configuration_reference_snapshot_dir>` |
| 32 | +configuration option. |
| 33 | +The example below shows how to specify a snapshot directory for ``instance001`` explicitly: |
| 34 | + |
| 35 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/snapshot/config.yaml |
| 36 | + :language: yaml |
| 37 | + :start-at: snapshot: |
| 38 | + :end-at: 'var/lib/{{ instance_name }}/snapshots' |
| 39 | + :dedent: |
| 40 | + |
| 41 | +By default, WAL files and snapshot files are stored in the same directory ``var/lib/{{ instance_name }}``. |
| 42 | +However, you can specify different directories for them. |
| 43 | +For example, you can place snapshots and write-ahead logs on different hard drives for better reliability: |
| 44 | + |
| 45 | +.. code-block:: yaml |
| 46 | +
|
| 47 | + instance001: |
| 48 | + snapshot: |
| 49 | + dir: '/media/drive1/snapshots' |
| 50 | + wal: |
| 51 | + dir: '/media/drive2/wals' |
| 52 | +
|
| 53 | +.. _configuration_persistence_chackpoint_daemon: |
| 54 | + |
| 55 | +Configure the checkpoint daemon |
| 56 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 57 | + |
| 58 | +In Tarantool, the :ref:`checkpoint daemon <configuration_reference_checkpoint_daemon>` (snapshot daemon) is a constantly |
| 59 | +running :ref:`fiber <app-fibers>`. The checkpoint daemon |
| 60 | +takes new snapshots every :ref:`snapshot.by.interval seconds. |
| 61 | +After the number of snapshots reaches the :ref:`snapshot.count <configuration_reference_snapshot_count>` size, |
| 62 | +the daemon activates Tarantool garbage collection that deletes the old snapshots files. |
| 63 | +The :ref:`snapshot.by.wal_size <configuration_reference_snapshot_by_wal_size>` option defines the maximum size in bytes |
| 64 | +for of all WAL files created since the last snapshot taken. Once this size is exceeded, the garbage collector deletes the old WALl files. |
| 65 | + |
| 66 | +The configuration of the checkpoint daemon might look as follows: |
| 67 | + |
| 68 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/snapshot/config.yaml |
| 69 | + :language: yaml |
| 70 | + :start-at: count: |
| 71 | + :end-at: 60 |
| 72 | + :dedent: |
| 73 | + |
| 74 | +If the ``snapshot.by.interval`` option is set to zero, the checkpoint daemon is disabled. |
| 75 | + |
| 76 | +.. _configuration_persistence_wal: |
| 77 | + |
| 78 | +Configure the write-ahead log |
| 79 | +----------------------------- |
| 80 | + |
| 81 | +This section describes how to define WAL settings in the :ref:`wal <configuration_reference_wal>` section of a YAML configuration. |
| 82 | + |
| 83 | +.. _configuration_persistence_wal_mode: |
| 84 | + |
| 85 | +Set the WAL mode |
| 86 | +~~~~~~~~~~~~~~~~ |
| 87 | + |
| 88 | +To be able to recover data in case of a possible instance restart, enable recording to the write-ahead log. |
| 89 | +To do it, set the :ref:`wal.mode <configuration_reference_wal_mode>` configuration option to ``write`` or ``fsync``. |
| 90 | +The example below shows how to specify the ``write`` WAL mode for ``instance001``: |
| 91 | + |
| 92 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/wal/config.yaml |
| 93 | + :language: yaml |
| 94 | + :start-at: instance001 |
| 95 | + :end-at: 'write' |
| 96 | + :dedent: |
| 97 | + |
| 98 | +The ``write`` mode |
| 99 | +The ``fsync`` mode |
| 100 | + |
| 101 | +An exclusion from this is when the instance is processing data that can be freely rejected. |
| 102 | +For example, when Tarantool is used for caching, WAL can be disabled to reduce i/o load. |
| 103 | + |
| 104 | +To turn the WAL writer off, set the ``wal.mode`` option to ``none``. |
| 105 | + |
| 106 | +.. _configuration_persistence_wal_dir: |
| 107 | + |
| 108 | +Specify a directory for WAL files |
| 109 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 110 | + |
| 111 | +To configure a directory where the WAL files are stored, use the :ref:`wal.dir <configuration_reference_wal_dir>` configuration option. |
| 112 | +The example below shows how to specify a directory for ``instance001`` explicitly: |
| 113 | + |
| 114 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/wal/config.yaml |
| 115 | + :language: yaml |
| 116 | + :start-at: wal: |
| 117 | + :end-at: 'var/lib/{{ instance_name }}/wals' |
| 118 | + :dedent: |
| 119 | + |
| 120 | + |
| 121 | +.. _configuration_persistence_wal_rescan: |
| 122 | + |
| 123 | +Set an interval between scans |
| 124 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 125 | + |
| 126 | +If case of :ref:`replication <replication>` or :ref:`hot standby <index-hot_standby>` mode, |
| 127 | +Tarantool checks for changes in the WAL files every :ref:`wal.dir_rescan_delay <configuration_reference_wal_dir_rescan_delay>` |
| 128 | +seconds. The example below shows how to specify the interval between scans: |
| 129 | + |
| 130 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/wal/config.yaml |
| 131 | + :language: yaml |
| 132 | + :start-at: dir_rescan_delay |
| 133 | + :end-before: cleanup_delay |
| 134 | + :dedent: |
| 135 | + |
| 136 | +.. _configuration_persistence_wal_maxsize: |
| 137 | + |
| 138 | +Set a maximum size for the WAL file |
| 139 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 140 | + |
| 141 | +A new WAL file is created when the current one reaches the :ref:`wal.max_size <configuration_reference_wal_max_size>` |
| 142 | +size. The configuration for this option might look as follows: |
| 143 | + |
| 144 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/wal/config.yaml |
| 145 | + :language: yaml |
| 146 | + :start-at: max_size |
| 147 | + :end-at: 268435456 |
| 148 | + :dedent: |
| 149 | + |
| 150 | +.. _configuration_persistence_wal_rescan: |
| 151 | + |
| 152 | +Set a delay for the garbage collector |
| 153 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 154 | + |
| 155 | +In Tarantool, the :ref:`checkpoint daemon <configuration_reference_checkpoint_daemon>` (snapshot daemon) |
| 156 | +takes new snapshots at the given interval (see :ref:`snapshot.by.interval <configuration_reference_snapshot_by_interval>`). |
| 157 | +After an instance restart, the daemon activates the Tarantool garbage collector that deletes the old WAL files. |
| 158 | + |
| 159 | +To delay the immediate deletion of WAL files, use the :ref:`wal.cleanup_delay <configuration_reference_wal_cleanup_delay>` |
| 160 | +configuration option. The delay eliminates possible erroneous situations when the master deletes WALs |
| 161 | +needed by :ref:`replicas <replication-roles>` after restart. |
| 162 | +As a consequence, replicas sync with the master faster after its restart and |
| 163 | +don't need to download all the data again. |
| 164 | + |
| 165 | +In the example, the delay is set to 5 hours (18000 seconds): |
| 166 | + |
| 167 | +.. literalinclude:: /code_snippets/snippets/config/instances.enabled/wal/config.yaml |
| 168 | + :language: yaml |
| 169 | + :start-at: cleanup_delay |
| 170 | + :end-at: 18000 |
| 171 | + :dedent: |
| 172 | + |
| 173 | +.. _configuration_persistence_wal_ext: |
| 174 | + |
| 175 | +Specify the WAL extensions |
| 176 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 177 | + |
| 178 | +In Tarantool Enterprise, you can store an old and new tuple for each crud operation performed. |
| 179 | +The detailed description and examples of the WAl extensions are provided in the :ref:`WAL extensions <wal_extensions>` section. |
| 180 | + |
| 181 | +See also: :ref:`wal.ext.* <configuration_reference_wal_ext>` configuration options. |
0 commit comments