Skip to content

Commit 30f1cb5

Browse files
committed
persistence: update topic
1 parent 8d930d9 commit 30f1cb5

File tree

13 files changed

+478
-131
lines changed

13 files changed

+478
-131
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/configuration.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ When the limit is reached, ``INSERT`` or ``UPDATE`` requests fail with :ref:`ER_
429429
Snapshots and write-ahead logs
430430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431431

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

435436
.. code-block:: yaml
@@ -450,6 +451,7 @@ To learn more about the persistence mechanism in Tarantool, see the :ref:`Persis
450451

451452
configuration/configuration_etcd
452453
configuration/configuration_code
454+
configuration/configuration_persistence
453455
configuration/configuration_connections
454456
configuration/configuration_authentication
455457
.. configuration/configuration_migrating
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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.

doc/concepts/data_model/persistence.rst

Lines changed: 1 addition & 1 deletion
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.

doc/dev_guide/internals/file_formats.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Data persistence and the WAL file format
1010

1111
To maintain data persistence, Tarantool writes each data change request (insert,
1212
update, delete, replace, upsert) into a write-ahead log (WAL) file in the
13-
:ref:`wal_dir <cfg_basic-wal_dir>` directory. A new WAL file is created
14-
when the current one reaches the :ref:`wal_max_size <cfg_binary_logging_snapshots-wal_max_size>` size.
13+
:ref:`wal_dir <cfg_basic-wal_dir>` directory.
1514
Each data change request gets assigned a continuously growing 64-bit log sequence
1615
number. The name of the WAL file is based on the log sequence number of the first
1716
record in the file, plus an extension ``.xlog``.
17+
A new WAL file is created
18+
when the current one reaches the :ref:`wal_max_size <cfg_binary_logging_snapshots-wal_max_size>` size.
1819

1920
Apart from a log sequence number and the data change request (formatted as in
2021
:ref:`Tarantool's binary protocol <internals-box_protocol>`),

doc/enterprise/flight_recorder.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ to :ref:`crashing <admin-disaster_recovery>` a Tarantool instance.
1717

1818
.. _enterprise-flight-recorder_enable:
1919

20-
Enabling the flight recorder
21-
----------------------------
20+
Enable the flight recorder
21+
--------------------------
2222

2323
The flight recorder is disabled by default and can be enabled and configured for
2424
a specific Tarantool instance.
@@ -33,7 +33,7 @@ configuration option to ``true``.
3333

3434

3535
After ``flightrec.enabled`` is set to ``true``, the flight recorder starts collecting data in the flight recording file ``current.ttfr``.
36-
This file is stored in the ``snapshot.dir`` directory.
36+
This file is stored in the :ref:`snapshot.dir <configuration_reference_snapshot_dir>` directory.
3737
By default, the directory is ``var/lib/{{ instance_name }}/<file_name>.ttfr``.
3838

3939
If the instance crashes and reboots, Tarantool rotates the flight recording:
@@ -49,8 +49,8 @@ Tarantool continues writing to the existing ``current.ttfr`` file after restart.
4949

5050
.. _enterprise-flight-recorder_configure:
5151

52-
Configuring a flight recorder
53-
-----------------------------
52+
Configure a flight recorder
53+
---------------------------
5454

5555
When the flight recorder is enabled, you can set the options related to :ref:`logging <cfg_logging-log>`,
5656
:ref:`metrics <metrics-reference>`, and storing the :ref:`request and response <internals-requests_responses>` data.

doc/enterprise/wal_extensions.rst

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _wal_extensions:
1+
.. _wal_extensions:
22

33
WAL extensions
44
==============
@@ -8,47 +8,49 @@ For example, you can enable storing an old and new tuple for each CRUD operation
88
This information might be helpful for implementing a CDC (Change Data Capture) utility
99
that transforms a data replication stream.
1010

11-
.. _wal_extensions_configuration:
11+
.. _wal_extensions_configuration:
1212

1313
Configuration
1414
-------------
1515

16-
To configure WAL extensions, use the ``wal.ext`` :ref:`configuration property <configuration_reference_wal>`.
17-
Inside the ``wal_ext`` block, you can enable storing old and new tuples as follows:
16+
WAL extensions are disabled by default.
17+
To configure them, use the :ref:`wal.ext.* <configuration_reference_wal_ext>` configuration options.
18+
Inside the ``wal.ext`` block, you can enable storing old and new tuples as follows:
1819

19-
* Set the ``old`` and ``new`` options to ``true`` to store old and new tuples in a write-ahead log for all spaces.
20+
* To store old and new tuples in a write-ahead log for all spaces, set the
21+
:ref:`wal.ext.old <configuration_reference_wal_ext_old>` and `wal.ext.new <configuration_reference_wal_ext_new>`
22+
options to ``true``:
2023

21-
.. code-block:: lua
24+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/persistence/config.yaml
25+
:language: yaml
26+
:start-at: wal:
27+
:end-at: old: true
28+
:dedent:
2229

23-
box.cfg {
24-
wal_ext = { old = true, new = true }
25-
}
30+
* To adjust these options for specific spaces, specify the :ref:`wal.ext.spaces <configuration_reference_wal_ext_spaces>` option:
2631

27-
* To adjust these options for specific spaces, use the ``spaces`` option.
32+
.. code-block:: yaml
2833
29-
.. code-block:: lua
34+
wal:
35+
ext:
36+
old: true
37+
new: true
38+
spaces:
39+
space1:
40+
old: false
41+
space2:
42+
new: false
3043
31-
box.cfg {
32-
wal_ext = {
33-
old = true, new = true,
34-
spaces = {
35-
space1 = { old = false },
36-
space2 = { new = false }
37-
}
38-
}
39-
}
40-
41-
42-
The configuration for specific spaces has priority over the global configuration,
43-
so only new tuples are added to the log for ``space1`` and only old tuples for ``space2``.
44+
The configuration for specific spaces has priority over the configuration in the ``wal.ext.new`` and ``wal.ext.old``
45+
options.
46+
It means that only new tuples are added to the log for ``space1`` and only old tuples for ``space2``.
4447

4548
Note that records with additional fields are :ref:`replicated <replication-architecture>` as follows:
4649

4750
* If a replica doesn't support the extended format configured on a master, auxiliary fields are skipped.
4851
* If a replica and master have different configurations for WAL records, a master's configuration is ignored.
4952

50-
51-
.. _wal_extensions_example:
53+
.. _wal_extensions_example:
5254

5355
Example
5456
-------

0 commit comments

Comments
 (0)