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
Copy file name to clipboardExpand all lines: doc/concepts/replication/repl_architecture.rst
+90-66Lines changed: 90 additions & 66 deletions
Original file line number
Diff line number
Diff line change
@@ -8,62 +8,88 @@ Replication architecture
8
8
Replication mechanism
9
9
---------------------
10
10
11
-
A pack of instances which operate on copies of the same databases make up a
12
-
**replica set**. Each instance in a replica set has a role, **master** or
13
-
**replica**.
11
+
.. _replication_overview:
12
+
13
+
Overview
14
+
~~~~~~~~
15
+
16
+
A pack of instances that operate on copies of the same databases makes up a **replica set**.
17
+
Each instance in a replica set has a role: **master** or **replica**.
14
18
15
19
A replica gets all updates from the master by continuously fetching and applying
16
-
its :ref:`writeahead log (WAL) <internals-wal>`. Each record in the WAL represents a single
20
+
its :ref:`write-ahead log (WAL) <internals-wal>`. Each record in the WAL represents a single
17
21
Tarantool data-change request such as :ref:`INSERT <box_space-insert>`,
18
-
:ref:`UPDATE <box_space-update>` or :ref:`DELETE <box_space-delete>`, and is assigned
22
+
:ref:`UPDATE <box_space-update>`, or :ref:`DELETE <box_space-delete>`, and is assigned
19
23
a monotonically growing log sequence number (**LSN**). In essence, Tarantool
20
24
replication is **row-based**: each data-change request is fully deterministic
21
25
and operates on a single :ref:`tuple <index-box_tuple>`. However, unlike a classical row-based log, which
22
26
contains entire copies of the changed rows, Tarantool's WAL contains copies of the requests.
23
27
For example, for UPDATE requests, Tarantool only stores the primary key of the row and
24
-
the update operations, to save space.
28
+
the update operations to save space.
29
+
30
+
.. NOTE::
31
+
32
+
`WAL extensions <https://www.tarantool.io/en/enterprise_doc/wal_extensions/>`_ available in Tarantool Enterprise enable you to add auxiliary information to each write-ahead log record.
33
+
This information might be helpful for implementing a CDC (Change Data Capture) utility that transforms a data replication stream.
25
34
26
-
Invocations of **stored programs** are not written to the WAL. Instead, records
27
-
of the actual **data-change requests, performed by the Lua code**, are
28
-
written to the WAL. This ensures that possible non-determinism of Lua does not
29
-
cause replication to go out of sync.
35
+
The following are specifics of adding different types of information to the WAL:
30
36
31
-
Data definition operations on **temporary spaces**, such as creating/dropping, adding
32
-
indexes, truncating, etc., are written to the WAL, since information about
33
-
temporary spaces is stored in non-temporary
34
-
system spaces, such as :ref:`box.space._space <box_space-space>`. Data change
35
-
operations on temporary spaces are not written to the WAL and are not replicated.
37
+
* Invocations of **stored programs** are not written to the WAL.
38
+
Instead, records of the actual **data-change requests, performed by the Lua code**, are written to the WAL.
39
+
This ensures that the possible non-determinism of Lua does not cause replication to go out of sync.
40
+
41
+
* Data definition operations on **temporary spaces** (:doc:`created </reference/reference_lua/box_schema/space_create>` with ``temporary = true``), such as creating/dropping, adding indexes, and truncating, are written to the WAL, since information about temporary spaces is stored in non-temporary system spaces, such as :ref:`box.space._space <box_space-space>`.
42
+
43
+
* Data change operations on temporary spaces are not written to the WAL and are not replicated.
36
44
37
45
.. _replication-local:
38
46
39
-
Data change operations on **replication-local** spaces
To create a valid initial state, to which WAL changes can be applied, every
45
-
instance of a replica set requires a start set of
46
-
:ref:`checkpoint files <index-box_persistence>`, such as .snap files for memtx
47
-
and .run files for vinyl. A replica joining an existing replica set, chooses an
48
-
existing master and automatically downloads the initial state from it. This is
49
-
called an **initial join**.
50
-
51
-
When an entire replica set is bootstrapped for the first time, there is no
52
-
master which could provide the initial checkpoint. In such a case, replicas
53
-
connect to each other and elect a master, which then creates the starting set of
54
-
checkpoint files, and distributes it to all the other replicas. This is called
55
-
an **automatic bootstrap** of a replica set.
56
-
57
-
When a replica contacts a master (there can be many masters) for the first time,
58
-
it becomes part of a replica set. On subsequent occasions, it should always
59
-
contact a master in the same replica set. Once connected to the master, the
60
-
replica requests all changes that happened after the latest local LSN (there
61
-
can be many LSNs -- each master has its own LSN).
62
-
63
-
Each replica set is identified by a globally unique identifier, called the
64
-
**replica set UUID**. The identifier is created by the master which creates the
65
-
very first checkpoint, and is part of the checkpoint file. It is stored in
66
-
system space :ref:`box.space._schema <box_space-schema>`. For example:
47
+
* Data change operations on **replication-local** spaces (:doc:`created </reference/reference_lua/box_schema/space_create>` with ``is_local = true``) are written to the WAL but are not replicated.
48
+
49
+
50
+
To learn how to enable replication, check the :ref:`Bootstrapping a replica set <replication-setup>` guide.
51
+
52
+
53
+
.. _replication_stages:
54
+
55
+
Replication stages
56
+
~~~~~~~~~~~~~~~~~~
57
+
58
+
To create a valid initial state, to which WAL changes can be applied, every instance of a replica set requires a start set of :ref:`checkpoint files <index-box_persistence>`, such as ``.snap`` files for memtx and ``.run`` files for vinyl.
59
+
A replica goes through the following stages:
60
+
61
+
62
+
1. **Bootstrap** (optional)
63
+
64
+
When an entire replica set is bootstrapped for the first time, there is no master that could provide the initial checkpoint.
65
+
In such a case, replicas connect to each other and elect a master.
66
+
The master creates the starting set of checkpoint files and distributes them to all the other replicas.
67
+
This is called an **automatic bootstrap** of a replica set.
68
+
69
+
2. **Join**
70
+
71
+
At this stage, a replica downloads the initial state from the master.
72
+
The master register this replica in the :ref:`box.space._cluster <box_space-cluster>` space.
73
+
If join fails with a non-critical :ref:`error <error_codes>`, for example, ``ER_READONLY``, ``ER_ACCESS_DENIED``, or a network-related issue, an instance tries to find a new master to join.
74
+
75
+
.. NOTE::
76
+
77
+
On subsequent connections, a replica downloads all changes happened after the latest local LSN (there can be many LSNs – each master has its own LSN).
78
+
79
+
3. **Follow**
80
+
81
+
At this stage, a replica fetches and applies updates from the master's write-ahead log.
82
+
83
+
You can use the :ref:`box.info.replication[n].upstream.status <box_info_replication>` property to monitor the status of a replica.
84
+
85
+
86
+
.. _replication_uuid:
87
+
88
+
Replica set and instance UUIDs
89
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
90
+
91
+
Each replica set is identified by a globally unique identifier, called the **replica set UUID**.
92
+
The identifier is created by the master, which creates the very first checkpoint and is part of the checkpoint file. It is stored in the :ref:`box.space._schema <box_space-schema>` system space, for example:
67
93
68
94
.. code-block:: tarantoolsession
69
95
@@ -79,14 +105,14 @@ joins the replica set. It is called an **instance UUID** and is a globally uniqu
79
105
identifier. The instance UUID is checked to ensure that instances do not join a different
80
106
replica set, e.g. because of a configuration error. A unique instance identifier
81
107
is also necessary to apply rows originating from different masters only once,
82
-
that is, to implement multi-master replication. This is why each row in the write
83
-
ahead log, in addition to its log sequence number, stores the instance identifier
108
+
that is, to implement multi-master replication. This is why each row in the write-ahead log,
109
+
in addition to its log sequence number, stores the instance identifier
84
110
of the instance on which it was created. But using a UUID as such an identifier
85
-
would take too much space in the writeahead log, thus a shorter integer number
111
+
would take too much space in the write-ahead log, thus a shorter integer number
86
112
is assigned to the instance when it joins a replica set. This number is then
87
-
used to refer to the instance in the writeahead log. It is called
88
-
**instance id**. All identifiers are stored in system space
89
-
:ref:`box.space._cluster <box_space-cluster>`. For example:
113
+
used to refer to the instance in the write-ahead log. It is called
114
+
**instance ID**. All identifiers are stored in the system space
115
+
:ref:`box.space._cluster <box_space-cluster>`, for example:
90
116
91
117
.. code-block:: tarantoolsession
92
118
@@ -110,14 +136,12 @@ describes the state of replication in regard to each connected peer.
110
136
...
111
137
112
138
Here ``vclock`` contains log sequence numbers (827 and 584) for instances with
113
-
instance IDs 1 and 2.
139
+
instance IDs ``1`` and ``2``.
140
+
141
+
If required, you can explicitly specify the instance and the replica set UUID values rather than letting Tarantool generate them.
142
+
To learn more, see the :ref:`replicaset_uuid <cfg_replication-replicaset_uuid>` configuration parameter description.
114
143
115
-
Starting in Tarantool 1.7.7, it is possible for administrators to assign
116
-
the instance UUID and the replica set UUID values, rather than let the system
0 commit comments