You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add `memtx` section in the Configuration reference
- Add `memtx_sort_threads` option to the box.cfg reference and updated box.cfg reference
- Add `In-memory storage` topic to the Configuration section
- Update `Supplementary threads` topic and added a note about OpenMP threads deprecation
- Fix some build warnings
Fixes#4012Fixes#3509
Copy file name to clipboardExpand all lines: doc/concepts/engines/memtx.rst
+22-17Lines changed: 22 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,22 @@
3
3
Storing data with memtx
4
4
=======================
5
5
6
-
The ``memtx`` storage engine is used in Tarantool by default. It keeps all data in random-access memory (RAM), and therefore has very low read latency.
6
+
The ``memtx`` storage engine is used in Tarantool by default.
7
+
The engine keeps all data in random-access memory (RAM), and therefore has a low read latency.
7
8
8
-
The obvious question here is:
9
-
if all the data is stored in memory, how can you prevent the data loss in case of emergency such as outage or Tarantool instance failure?
9
+
Tarantool prevents the data loss in case of emergency, such as outage or Tarantool instance failure, in the following ways:
10
10
11
-
First of all, Tarantool persists all data changes by writing requests to the write-ahead log (WAL) that is stored on disk.
12
-
Read more about that in the :ref:`memtx-persist` section.
13
-
In case of a distributed application, there is an option of synchronous replication that ensures keeping the data consistent on a quorum of replicas.
14
-
Although replication is not directly a storage engine topic, it is a part of the answer regarding data safety. Read more in the :ref:`memtx-replication` section.
11
+
* Tarantool persists all data changes by writing requests to the :ref:`write-ahead log <internals-wal>` (WAL)
12
+
that is stored on disk. Also, Tarantool periodically takes the entire
13
+
:doc:`database snapshot </reference/reference_lua/box_snapshot>` and saves it on disk.
In this chapter, the following topics are discussed in brief with the references to other chapters that explain the subject matter in details.
16
+
* In case of a distributed application, a synchronous replication is used to ensure keeping the data consistent on a quorum of replicas.
17
+
Although replication is not directly a storage engine topic, it is a part of the answer regarding data safety.
18
+
Learn more: :ref:`Replicating data <memtx-replication>`.
19
+
20
+
In this section, the following topics are discussed in brief with the references to other sections that explain the
21
+
subject matter in details.
17
22
18
23
.. contents::
19
24
:local:
@@ -43,7 +48,7 @@ Within the TX thread, there is a memory area allocated for Tarantool to store da
43
48
44
49
.. image:: memtx/arena2.svg
45
50
46
-
Data is stored in :term:`spaces <space>`. Spaces contain database records—:term:`tuples <tuple>`.
51
+
Data is stored in :term:`spaces <space>`. Spaces contain database records -- :term:`tuples <tuple>`.
47
52
To access and manipulate the data stored in spaces and tuples, Tarantool builds :doc:`indexes </concepts/data_model/indexes>`.
48
53
49
54
Special `allocators <https://github.com/tarantool/small>`__ manage memory allocations for spaces, tuples, and indexes within the Arena.
@@ -52,43 +57,43 @@ Tarantool has a built-in module called ``box.slab`` which provides the slab allo
52
57
that can be used to monitor the total memory usage and memory fragmentation.
53
58
For more details, see the ``box.slab`` module :doc:`reference </reference/reference_lua/box_slab>`.
54
59
55
-
.. image:: memtx/spaces_indexes.svg
60
+
.. image:: memtx/spaces_indexes.svg
56
61
57
62
Also inside the TX thread, there is an event loop. Within the event loop, there are a number of :ref:`fibers <fiber-fibers>`.
58
63
Fibers are cooperative primitives that allow interaction with spaces, that is, reading and writing the data.
59
64
Fibers can interact with the event loop and between each other directly or by using special primitives called channels.
60
65
Due to the usage of fibers and :ref:`cooperative multitasking <app-cooperative_multitasking>`, the ``memtx`` engine is lock-free in typical situations.
61
66
62
-
.. image:: memtx/fibers-channels.svg
67
+
.. image:: memtx/fibers-channels.svg
63
68
64
69
To interact with external users, there is a separate :ref:`network thread <thread_model>` also called the **iproto thread**.
65
70
The iproto thread receives a request from the network, parses and checks the statement,
66
71
and transforms it into a special structure—a message containing an executable statement and its options.
67
72
Then the iproto thread ships this message to the TX thread and runs the user's request in a separate fiber.
68
73
69
-
.. image:: memtx/iproto.svg
74
+
.. image:: memtx/iproto.svg
70
75
71
76
.. _memtx-persist:
72
77
73
78
Data persistence
74
79
----------------
75
80
76
-
To ensure:ref:`data persistence <index-box_persistence>`, Tarantool does two things.
81
+
Tarantool ensures:ref:`data persistence <index-box_persistence>` as follows:
77
82
78
83
* After executing data change requests in memory, Tarantool writes each such request to the :ref:`write-ahead log (WAL) <internals-wal>` files (``.xlog``)
79
84
that are stored on disk. Tarantool does this via a separate thread called the **WAL thread**.
80
85
81
-
.. image:: memtx/wal.svg
86
+
.. image:: memtx/wal.svg
82
87
83
88
* Tarantool periodically takes the entire :doc:`database snapshot </reference/reference_lua/box_snapshot>` and saves it on disk.
84
89
It is necessary for accelerating instance's restart because when there are too many WAL files, it can be difficult for Tarantool to restart quickly.
85
90
86
-
To save a snapshot, there is a special fiber called the **snapshot daemon**.
91
+
To save a snapshot, there is a special fiber called the :ref:`snapshot daemon<configuration_persistence_checkpoint_daemon>`.
87
92
It reads the consistent content of the entire Arena and writes it on disk into a snapshot file (``.snap``).
88
93
Due of the cooperative multitasking, Tarantool cannot write directly on disk because it is a locking operation.
89
94
That is why Tarantool interacts with disk via a separate pool of threads from the :doc:`fio </reference/reference_lua/fio>` library.
90
95
91
-
.. image:: memtx/snapshot03.svg
96
+
.. image:: memtx/snapshot03.svg
92
97
93
98
So, even in emergency situations such as an outage or a Tarantool instance failure,
94
99
when the in-memory database is lost, the data can be restored fully during Tarantool restart.
@@ -150,7 +155,7 @@ For more information on replication, refer to the :ref:`corresponding chapter <r
150
155
.. _memtx-summary:
151
156
152
157
Summary
153
-
--------
158
+
-------
154
159
155
160
The main key points describing how the in-memory storage engine works can be summarized in the following way:
0 commit comments