Skip to content

Commit 27c688a

Browse files
committed
persistence: update topic
1 parent 0031251 commit 27c688a

File tree

17 files changed

+564
-230
lines changed

17 files changed

+564
-230
lines changed

doc/book/admin/backups.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ that are made after the last snapshot are incremental backups. Therefore taking
3737
a backup is a matter of copying the snapshot and WAL files.
3838

3939
1. Use ``tar`` to make a (possibly compressed) copy of the latest .snap and .xlog
40-
files on the :ref:`memtx_dir <cfg_basic-memtx_dir>` and
41-
:ref:`wal_dir <cfg_basic-wal_dir>` directories.
40+
files on the :ref:`snapshot.dir <configuration_reference_snapshot_dir>` and
41+
:ref:`wal.dir <configuration_reference_wal_dir>` directories.
4242

4343
2. If there is a security policy, encrypt the .tar file.
4444

4545
3. Copy the .tar file to a safe place.
4646

4747
Later, restoring the database is a matter of taking the .tar file and putting
48-
its contents back in the ``memtx_dir`` and ``wal_dir`` directories.
48+
its contents back in the ``snapshot.dir`` and ``wal.dir`` directories.
4949

5050
.. _admin-backups-hot_backup_vinyl_memtx:
5151

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
groups:
2+
group001:
3+
replicasets:
4+
replicaset001:
5+
instances:
6+
instance001:
7+
snapshot:
8+
dir: 'var/lib/{{ instance_name }}/snapshots'
9+
count: 10
10+
by:
11+
interval: 60
12+
iproto:
13+
listen:
14+
- uri: '127.0.0.1:3301'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
groups:
2+
group001:
3+
replicasets:
4+
replicaset001:
5+
instances:
6+
instance001:
7+
wal:
8+
mode: 'write'
9+
dir: 'var/lib/{{ instance_name }}/wals'
10+
dir_rescan_delay: 3
11+
cleanup_delay: 18000
12+
max_size: 268435456
13+
ext:
14+
new: true
15+
old: true
16+
spaces:
17+
bands:
18+
new: false
19+
iproto:
20+
listen:
21+
- uri: '127.0.0.1:3301'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:

doc/concepts/atomic/thread_model.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ There are also several supplementary threads that serve additional capabilities:
6969
Separate threads are required because each replica can point to a different position in the log and can run at different speeds.
7070

7171
* There is a thread pool for ad hoc asynchronous tasks,
72-
such as a DNS resolver or :ref:`fsync <cfg_binary_logging_snapshots-wal_mode>`.
72+
such as a DNS resolver or :ref:`fsync <configuration_reference_wal_mode>`.
7373

7474
* There are OpenMP threads used to parallelize sorting
7575
(hence, to parallelize building :ref:`indexes <concepts-data_model_indexes>`).

doc/concepts/configuration.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ When the limit is reached, ``INSERT`` or ``UPDATE`` requests fail with :ref:`ER_
426426
Snapshots and write-ahead logs
427427
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
428428

429-
The ``snapshot.dir`` and ``wal.dir`` options can be used to configure directories for storing snapshots and write-ahead logs.
429+
The :ref:`snapshot.dir <configuration_reference_snapshot_dir>` and :ref:`wal.dir <configuration_reference_wal_dir>`
430+
options can be used to configure directories for storing snapshots and write-ahead logs.
430431
For example, you can place snapshots and write-ahead logs on different hard drives for better reliability.
431432

432433
.. code-block:: yaml
@@ -438,6 +439,7 @@ For example, you can place snapshots and write-ahead logs on different hard driv
438439
dir: '/media/drive2/wals'
439440
440441
To learn more about the persistence mechanism in Tarantool, see the :ref:`Persistence <concepts-data_model-persistence>` section.
442+
Read more about snapshot and WAL configuration: :ref:`Persistence <configuration_persistence>`.
441443

442444

443445

@@ -447,6 +449,7 @@ To learn more about the persistence mechanism in Tarantool, see the :ref:`Persis
447449

448450
configuration/configuration_etcd
449451
configuration/configuration_code
452+
configuration/configuration_persistence
450453
configuration/configuration_connections
451454
configuration/configuration_credentials
452455
configuration/configuration_authentication
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
.. _configuration_persistence:
2+
3+
Persistence
4+
===========
5+
6+
To ensure data persistence, Tarantool provides the abilities to:
7+
8+
* record each data change request into a :ref:`write-ahead log <internals-wal>` (WAL) file (``.xlog`` files)
9+
* take :ref:`snapshots <internals-snapshot>` that contain on-disk copy of the entire data set for a given moment (``.snap`` files)
10+
11+
During the recovery process, Tarantool can load the latest snapshot file and then read the requests from the WAL files,
12+
produced after this snapshot was made.
13+
14+
To learn more about the persistence mechanism in Tarantool, see the :ref:`Persistence <concepts-data_model-persistence>` section.
15+
The formats of WAL and snapshot files are described in detail in the :ref:`File formats <internals-data_persistence>` section.
16+
17+
.. _configuration_persistence_snapshot:
18+
19+
Configure the snapshots
20+
-----------------------
21+
22+
**Example on GitHub**: `snapshot <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/persistence_snapshot>`_
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/persistence_snapshot/config.yaml
36+
:language: yaml
37+
:start-at: instance001:
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_checkpoint_daemon:
54+
55+
Configure the automatic snapshot creation
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
58+
In Tarantool, it is possible to set automatic :ref:`snapshot creation </reference/reference_lua/box_snapshot>`.
59+
To enable it, the :ref:`snapshot.by.interval <configuration_reference_snapshot_by_interval>` option is used.
60+
The option sets up the :ref:`checkpoint daemon <configuration_reference_checkpoint_daemon>` (snapshot daemon), which is
61+
a constantly running :ref:`fiber <app-fibers>`.
62+
The checkpoint daemon takes new snapshots every ``snapshot.by.interval`` seconds.
63+
When the number of snapshots reaches the limit of :ref:`snapshot.count <configuration_reference_snapshot_count>` size,
64+
the daemon activates Tarantool garbage collector after the new snapshot is taken.
65+
Tarantool garbage collector deletes the oldest snapshot file and any associated WAL files.
66+
67+
The :ref:`snapshot.by.wal_size <configuration_reference_snapshot_by_wal_size>` option defines the maximum size in bytes
68+
for of all WAL files created since the last snapshot taken.
69+
Once this size is exceeded, the checkpoint daemon takes a snapshot and deletes the old WAL files.
70+
71+
The configuration of the checkpoint daemon might look as follows:
72+
73+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_snapshot/config.yaml
74+
:language: yaml
75+
:start-at: count:
76+
:end-at: 60
77+
:dedent:
78+
79+
If the ``snapshot.by.interval`` option is set to zero, the checkpoint daemon is disabled.
80+
If the ``snapshot.count`` option is set to zero, the checkpoint daemon does not delete old snapshots.
81+
82+
.. _configuration_persistence_wal:
83+
84+
Configure the write-ahead log
85+
-----------------------------
86+
87+
**Example on GitHub**: `wal <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/persistence_wal>`_
88+
89+
This section describes how to define WAL settings in the :ref:`wal <configuration_reference_wal>` section of a YAML configuration.
90+
91+
.. _configuration_persistence_wal_mode:
92+
93+
Set the WAL mode
94+
~~~~~~~~~~~~~~~~
95+
96+
To be able to recover data in case of a possible instance restart, enable recording to the write-ahead log.
97+
To do it, set the :ref:`wal.mode <configuration_reference_wal_mode>` configuration option to ``write`` or ``fsync``.
98+
The example below shows how to specify the ``write`` WAL mode for ``instance001``:
99+
100+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
101+
:language: yaml
102+
:start-at: instance001
103+
:end-at: 'write'
104+
:dedent:
105+
106+
The ``write`` mode enables WAL and writes the data without waiting the data to be flushed to the storage device.
107+
The ``fsync`` mode enables WAL and ensures that the record is written to the storage device.
108+
109+
To turn the WAL writer off, set the ``wal.mode`` option to ``none``.
110+
111+
.. _configuration_persistence_wal_dir:
112+
113+
Specify a directory for WAL files
114+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115+
116+
To configure a directory where the WAL files are stored, use the :ref:`wal.dir <configuration_reference_wal_dir>` configuration option.
117+
The example below shows how to specify a directory for ``instance001`` explicitly:
118+
119+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
120+
:language: yaml
121+
:start-at: wal:
122+
:end-at: 'var/lib/{{ instance_name }}/wals'
123+
:dedent:
124+
125+
126+
.. _configuration_persistence_wal_rescan:
127+
128+
Set an interval between scans
129+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
131+
If case of :ref:`replication <replication>` or :ref:`hot standby <index-hot_standby>` mode,
132+
Tarantool scans for changes in the WAL files every :ref:`wal.dir_rescan_delay <configuration_reference_wal_dir_rescan_delay>`
133+
seconds. The example below shows how to specify the interval between scans:
134+
135+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
136+
:language: yaml
137+
:start-at: dir_rescan_delay
138+
:end-before: cleanup_delay
139+
:dedent:
140+
141+
.. _configuration_persistence_wal_maxsize:
142+
143+
Set a maximum size for the WAL file
144+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145+
146+
A new WAL file is created when the current one reaches the :ref:`wal.max_size <configuration_reference_wal_max_size>`
147+
size. The configuration for this option might look as follows:
148+
149+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
150+
:language: yaml
151+
:start-at: max_size
152+
:end-at: 268435456
153+
:dedent:
154+
155+
.. _configuration_persistence_wal_rescan:
156+
157+
Set a delay for the garbage collector
158+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159+
160+
In Tarantool, the :ref:`checkpoint daemon <configuration_reference_checkpoint_daemon>` (snapshot daemon)
161+
takes new snapshots at the given interval (see :ref:`snapshot.by.interval <configuration_reference_snapshot_by_interval>`).
162+
After an instance restart, the daemon activates the Tarantool garbage collector that deletes the old WAL files.
163+
164+
To delay the immediate deletion of WAL files, use the :ref:`wal.cleanup_delay <configuration_reference_wal_cleanup_delay>`
165+
configuration option. The delay eliminates possible erroneous situations when the master deletes WALs
166+
needed by :ref:`replicas <replication-roles>` after restart.
167+
As a consequence, replicas sync with the master faster after its restart and
168+
don't need to download all the data again.
169+
170+
In the example, the delay is set to 5 hours (18000 seconds):
171+
172+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence_wal/config.yaml
173+
:language: yaml
174+
:start-at: cleanup_delay
175+
:end-at: 18000
176+
:dedent:
177+
178+
.. _configuration_persistence_wal_ext:
179+
180+
Specify the WAL extensions
181+
~~~~~~~~~~~~~~~~~~~~~~~~~~
182+
183+
In Tarantool Enterprise, you can store an old and new tuple for each crud operation performed.
184+
The detailed description and examples of the WAL extensions are provided in the :ref:`WAL extensions <wal_extensions>` section.
185+
186+
See also: :ref:`wal.ext.* <configuration_reference_wal_ext>` configuration options.

doc/concepts/data_model/operations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ resource usage of each function.
150150
important than the others.
151151
* - WAL settings
152152
- The important setting for the write-ahead log is
153-
:ref:`wal_mode <cfg_binary_logging_snapshots-wal_mode>`.
153+
:ref:`wal.mode <configuration_reference_wal_mode>`.
154154
If the setting causes no writing or
155155
delayed writing, this factor is unimportant. If the
156156
setting causes every data-change request to wait

doc/concepts/data_model/persistence.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In such case, Tarantool restores the data from WAL files
1212
by reading them and redoing the requests.
1313
This is called the "recovery process".
1414
You can change the timing of the WAL writer or turn it off by setting
15-
the :ref:`wal_mode <cfg_binary_logging_snapshots-wal_mode>`.
15+
the :ref:`wal.mode <configuration_reference_wal_mode>`.
1616

1717
Tarantool also maintains a set of :ref:`snapshot files <internals-snapshot>`.
1818
These files contain an on-disk copy of the entire data set for a given moment.
@@ -24,19 +24,20 @@ After creating a new snapshot, the earlier WAL files can be removed to free up s
2424
To force immediate creation of a snapshot file, use the
2525
:doc:`box.snapshot() </reference/reference_lua/box_snapshot>` function.
2626
To enable the automatic creation of snapshot files, use Tarantool's
27-
:ref:`checkpoint daemon <book_cfg_checkpoint_daemon>`.
28-
The checkpoint daemon sets intervals for forced checkpoints. It makes sure that the states
27+
:ref:`checkpoint daemon <configuration_persistence_checkpoint_daemon>`.
28+
The checkpoint daemon sets intervals for forced snapshots. It makes sure that the states
2929
of both memtx and vinyl storage engines are synchronized and saved to disk,
3030
and automatically removes earlier WAL files.
3131

3232
Snapshot files can be created even if there is no WAL file.
3333

3434
.. NOTE::
3535

36-
The memtx engine makes only regular checkpoints with the interval set in
37-
:ref:`checkpoint daemon <book_cfg_checkpoint_daemon>` configuration.
36+
The memtx engine takes only regular snapshots with the interval set in
37+
the checkpoint daemon configuration.
3838

3939
The vinyl engine runs checkpointing in the background at all times.
4040

4141
See the :ref:`Internals <internals-data_persistence>` section for more details
4242
about the WAL writer and the recovery process.
43+
To learn more about the configuration of the checkpoint daemon and WAL, check the :ref:`Persistence <configuration_persistence>` page.

0 commit comments

Comments
 (0)