Skip to content

Commit 4860379

Browse files
committed
3.0 configuration: replication administration
1 parent 8aedebc commit 4860379

File tree

12 files changed

+220
-277
lines changed

12 files changed

+220
-277
lines changed

doc/book/admin/disaster_recovery.rst

Lines changed: 109 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,164 @@
11
.. _admin-disaster_recovery:
22

3-
================================================================================
43
Disaster recovery
5-
================================================================================
4+
=================
65

76
The minimal fault-tolerant Tarantool configuration would be a
8-
:ref:`replication cluster<replication-topologies>`
7+
:ref:`replica set <replication-architecture>`
98
that includes a master and a replica, or two masters.
109

11-
The basic recommendation is to configure all Tarantool instances in a cluster to
10+
The basic recommendation is to configure all Tarantool instances in a replica set to
1211
create :ref:`snapshot files <index-box_persistence>` at a regular basis.
1312

1413
Here follow action plans for typical crash scenarios.
1514

1615
.. _admin-disaster_recovery-master_replica:
1716

18-
--------------------------------------------------------------------------------
1917
Master-replica
20-
--------------------------------------------------------------------------------
18+
--------------
2119

22-
Configuration: One master and one replica.
20+
.. _admin-disaster_recovery-master_replica_manual_failover:
2321

24-
Problem: The master has crashed.
22+
Master crash: manual failover
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2524

26-
Your actions:
25+
**Configuration:** master-replica (:ref:`manual failover <replication-master_replica_bootstrap>`).
2726

28-
1. Ensure the master is stopped for good. For example, log in to the master
29-
machine and use ``systemctl stop tarantool@<instance_name>``.
27+
**Problem:** The master has crashed.
3028

31-
2. Switch the replica to master mode by setting
32-
:ref:`box.cfg.read_only <cfg_basic-read_only>` parameter to *false* and let
33-
the load be handled by the replica (effective master).
29+
**Actions:**
3430

35-
3. Set up a replacement for the crashed master on a spare host, with
36-
:ref:`replication <cfg_replication-replication>` parameter set to replica
37-
(effective master), so it begins to catch up with the new master’s state.
38-
The new instance should have :ref:`box.cfg.read_only <cfg_basic-read_only>`
39-
parameter set to *true*.
31+
1. Ensure the master is stopped.
32+
For example, log in to the master machine and use ``tt stop``.
4033

41-
You lose the few transactions in the master
42-
:ref:`write ahead log file <index-box_persistence>`, which it may have not
43-
transferred to the replica before crash. If you were able to salvage the master
44-
.xlog file, you may be able to recover these. In order to do it:
34+
2. Configure a new replica set leader using the :ref:`<replicaset_name>.leader <configuration_reference_replicasets_name_leader>` option.
35+
36+
3. Reload configuration on all instances using :ref:`config:reload() <config-module>`.
37+
38+
4. Make sure that a new replica set leader is a master using :ref:`box.info.ro <box_introspection-box_info>`.
39+
40+
5. Remove a crashed master from a replica set as described in :ref:`Removing instances <replication-remove_instances>`.
41+
42+
6. Set up a replacement for the crashed master on a spare host as described in :ref:`Adding instances <replication-add_instances>`.
43+
44+
See also: :ref:`Performing manual failover <replication-controlled_failover>`.
45+
46+
47+
.. _admin-disaster_recovery-master_replica_auto_failover:
48+
49+
Master crash: automated failover
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
**Configuration:** master-replica (:ref:`automated failover <replication-bootstrap-auto>`).
53+
54+
**Problem:** The master has crashed.
55+
56+
**Actions:**
57+
58+
1. Use ``box.info.election`` to make sure a new master is elected automatically.
59+
60+
2. Remove a crashed master from a replica set.
4561

46-
1. Find out the position of the crashed master, as reflected on the new master.
62+
3. Set up a replacement for the crashed master on a spare host.
63+
Learn more from :ref:`Adding and removing instances <replication-automated-failover-add-remove-instances>`.
4764

48-
a. Find out instance UUID from the crashed master :ref:`xlog <internals-wal>`:
65+
See also: :ref:`Testing automated failover <replication-automated-failover-testing>`.
4966

50-
.. code-block:: console
5167

52-
$ head -5 *.xlog | grep Instance
53-
Instance: ed607cad-8b6d-48d8-ba0b-dae371b79155
68+
.. _admin-disaster_recovery-master_replica_data_loss:
5469

55-
b. On the new master, use the UUID to find the position:
70+
Data loss
71+
~~~~~~~~~
72+
73+
**Configuration:** master-replica.
74+
75+
**Problem:** Some transaction are missing on a replica after the master has crashed.
76+
77+
**Actions:**
78+
79+
You lose the few transactions in the master
80+
:ref:`write ahead log file <index-box_persistence>`, which it may have not
81+
transferred to the replica before crash. If you were able to salvage the master
82+
``.xlog`` file, you may be able to recover these.
5683

57-
.. code-block:: tarantoolsession
84+
1. Find out instance UUID from the crashed master :ref:`xlog <internals-wal>`:
5885

59-
tarantool> box.info.vclock[box.space._cluster.index.uuid:select{'ed607cad-8b6d-48d8-ba0b-dae371b79155'}[1][1]]
60-
---
61-
- 23425
62-
<...>
86+
.. code-block:: console
6387
64-
2. Play the records from the crashed .xlog to the new master, starting from the
65-
new master position:
88+
$ head -5 var/lib/instance001/*.xlog | grep Instance
89+
Instance: 9bb111c2-3ff5-36a7-00f4-2b9a573ea660
6690
67-
a. Issue this request locally at the new master's machine to find out
68-
instance ID of the new master:
91+
2. On the new master, use the UUID to find the position:
6992

70-
.. code-block:: tarantoolsession
93+
.. code-block:: tarantoolsession
7194
72-
tarantool> box.space._cluster:select{}
73-
---
74-
- - [1, '88580b5c-4474-43ab-bd2b-2409a9af80d2']
75-
...
95+
app:instance002> box.info.vclock[box.space._cluster.index.uuid:select{'9bb111c2-3ff5-36a7-00f4-2b9a573ea660'}[1][1]]
96+
---
97+
- 999
98+
...
7699
77-
b. Play the records to the new master:
100+
3. :ref:`Play the records <tt-play>` from the crashed ``.xlog`` to the new master, starting from the
101+
new master position:
78102

79-
.. code-block:: console
103+
.. code-block:: console
104+
105+
$ tt play 127.0.0.1:3302 var/lib/instance001/00000000000000000000.xlog \
106+
--from 1000 \
107+
--replica 1 \
108+
--username admin --password secret
80109
81-
$ tt play <new_master_uri> <xlog_file> --from 23425 --replica 1
82110
83111
.. _admin-disaster_recovery-master_master:
84112

85-
--------------------------------------------------------------------------------
86113
Master-master
87-
--------------------------------------------------------------------------------
114+
-------------
115+
116+
**Configuration:** :ref:`master-master <replication-bootstrap-master-master>`.
88117

89-
Configuration: Two masters.
118+
**Problem:** one master has crashed.
90119

91-
Problem: Master#1 has crashed.
120+
**Actions:**
92121

93-
Your actions:
122+
1. Let the load be handled by another master alone.
94123

95-
1. Let the load be handled by master#2 (effective master) alone.
124+
2. Remove a crashed master from a replica set.
125+
126+
3. Set up a replacement for the crashed master on a spare host.
127+
Learn more from :ref:`Adding and removing instances <replication-master-master-add-remove-instances>`.
96128

97-
2. Follow the same steps as in the
98-
:ref:`master-replica <admin-disaster_recovery-master_replica>` recovery scenario
99-
to create a new master and salvage lost data.
100129

101130
.. _admin-disaster_recovery-data_loss:
102131

103-
--------------------------------------------------------------------------------
104132
Data loss
105-
--------------------------------------------------------------------------------
133+
---------
134+
135+
**Configuration:** master-replica or master-master.
136+
137+
**Problem:** Data was deleted at one master and this data loss was propagated to the other node (master or replica).
138+
139+
**Actions:**
140+
141+
1. Put all nodes in read-only mode.
142+
Depending on the used :ref:`replication.failover <configuration_reference_replication_failover>` mode, this can be done as follows:
143+
144+
- ``manual``: change a replica set leader to ``null``.
145+
- ``election``: switch from the ``election`` failover mode to ``manual`` and change a replica set leader to ``null``.
146+
- ``off``: set ``database.mode`` to ``ro``.
106147

107-
Configuration: Master-master or master-replica.
148+
Reload configurations on all instances using the ``reload()`` function provided by the :ref:`config <config-module>` module.
108149

109-
Problem: Data was deleted at one master and this data loss was propagated to the
110-
other node (master or replica).
150+
2. Turn off deletion of expired checkpoints with :doc:`/reference/reference_lua/box_backup/start`.
151+
This prevents the Tarantool garbage collector from removing files
152+
made with older checkpoints until :doc:`/reference/reference_lua/box_backup/stop` is called.
111153

112-
The following steps are applicable only to data in memtx storage engine.
113-
Your actions:
154+
3. Get the latest valid :ref:`.snap file <internals-snapshot>` and
155+
use ``tt cat`` command to calculate at which LSN the data loss occurred.
114156

115-
1. Put all nodes in :ref:`read-only mode <cfg_basic-read_only>` and disable
116-
deletion of expired checkpoints with :doc:`/reference/reference_lua/box_backup/start`.
117-
This will prevent the Tarantool garbage collector from removing files
118-
made with older checkpoints until :doc:`/reference/reference_lua/box_backup/stop` is called.
157+
4. Start a new instance and use :ref:`tt play <tt-play>` command to
158+
play to it the contents of ``.snap`` and ``.xlog`` files up to the calculated LSN.
119159

120-
2. Get the latest valid :ref:`.snap file <internals-snapshot>` and
121-
use ``tt cat`` command to calculate at which lsn the data loss occurred.
160+
5. Bootstrap a new replica from the recovered master.
122161

123-
3. Start a new instance (instance#1) and use ``tt play`` command to
124-
play to it the contents of .snap/.xlog files up to the calculated lsn.
162+
.. NOTE::
125163

126-
4. Bootstrap a new replica from the recovered master (instance#1).
164+
The steps above are applicable only to data in the memtx storage engine.
Loading
Loading

doc/book/admin/replication/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Replication administration
22
==========================
33

44
.. toctree::
5-
:maxdepth: 2
5+
:maxdepth: 1
66

77
repl_monitoring
88
repl_recover

doc/book/admin/replication/repl_monitoring.rst

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,28 @@ Monitoring a replica set
44
========================
55

66
To learn what instances belong to the replica set and obtain statistics for all
7-
these instances, issue a :doc:`/reference/reference_lua/box_info/replication` request:
8-
9-
.. code-block:: tarantoolsession
10-
11-
tarantool> box.info.replication
12-
---
13-
replication:
14-
1:
15-
id: 1
16-
uuid: b8a7db60-745f-41b3-bf68-5fcce7a1e019
17-
lsn: 88
18-
2:
19-
id: 2
20-
uuid: cd3c7da2-a638-4c5d-ae63-e7767c3a6896
21-
lsn: 31
22-
upstream:
23-
status: follow
24-
idle: 43.187747001648
25-
peer: [email protected]:3301
26-
lag: 0
27-
downstream:
28-
vclock: {1: 31}
29-
3:
30-
id: 3
31-
uuid: e38ef895-5804-43b9-81ac-9f2cd872b9c4
32-
lsn: 54
33-
upstream:
34-
status: follow
35-
idle: 43.187621831894
36-
peer: [email protected]:3301
37-
lag: 2
38-
downstream:
39-
vclock: {1: 54}
40-
...
41-
42-
This report is for a master-master replica set of three instances, each having
43-
its own instance id, UUID and log sequence number.
44-
45-
.. image:: /concepts/replication/images/mm-3m-mesh.svg
7+
these instances, execute a :ref:`box.info.replication <box_info_replication>` request.
8+
The output below shows replication status for a replica set containing one :ref:`master and two replicas <replication-master_replica_bootstrap>`:
9+
10+
.. include:: /how-to/replication/repl_bootstrap.rst
11+
:start-after: box_info_replication_manual_leader_start
12+
:end-before: box_info_replication_manual_leader_end
13+
14+
The following diagram illustrates the ``upstream`` and ``downstream`` connections for the ``box.info.replication`` executed at the master instance (``instance001``):
15+
16+
.. image:: _images/box_info_replication_instance001.png
17+
:width: 600
18+
:align: center
19+
:alt: replication status on master
20+
21+
If ``box.info.replication`` is executed on ``instance002``, the ``upstream`` and ``downstream`` connections look as follows:
22+
23+
.. image:: _images/box_info_replication_instance002.png
24+
:width: 600
4625
:align: center
26+
:alt: replication status on replica
4727

48-
The request was issued at master #1, and the reply includes statistics for the
49-
other two masters, given in regard to master #1.
28+
This means that statistics for replicas is given in regard to the instance on which ``box.info.replication`` is executed.
5029

5130
The primary indicators of replication health are:
5231

@@ -74,9 +53,4 @@ The primary indicators of replication health are:
7453
machines, do not be surprised if it’s negative: a time drift may lead to the
7554
remote master clock being consistently behind the local instance's clock.
7655

77-
For multi-master configurations, ``lag`` is the maximal lag.
78-
79-
For better understanding, see the following diagram illustrating the ``upstream`` and ``downstream`` connections within the replica set of three instances:
80-
81-
.. image:: /concepts/replication/images/replication.svg
82-
:align: left
56+
For a :ref:`master-master <replication-bootstrap-master-master>` configuration, ``lag`` is the maximal lag.

0 commit comments

Comments
 (0)