Skip to content

Commit 0635702

Browse files
committed
3.0 config: replication administration
1 parent 3eab90f commit 0635702

File tree

12 files changed

+225
-284
lines changed

12 files changed

+225
-284
lines changed

doc/book/admin/disaster_recovery.rst

Lines changed: 110 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,162 @@
11
.. _admin-disaster_recovery:
22

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

7-
The minimal fault-tolerant Tarantool configuration would be a
8-
:ref:`replication cluster<replication-topologies>`
6+
The minimal fault-tolerant Tarantool configuration would be a :ref:`replica set <replication-architecture>`
97
that includes a master and a replica, or two masters.
8+
The basic recommendation is to configure all Tarantool instances in a replica set to create :ref:`snapshot files <index-box_persistence>` on a regular basis.
109

11-
The basic recommendation is to configure all Tarantool instances in a cluster to
12-
create :ref:`snapshot files <index-box_persistence>` at a regular basis.
10+
Here are action plans for typical crash scenarios.
1311

14-
Here follow action plans for typical crash scenarios.
1512

1613
.. _admin-disaster_recovery-master_replica:
1714

18-
--------------------------------------------------------------------------------
1915
Master-replica
20-
--------------------------------------------------------------------------------
16+
--------------
2117

22-
Configuration: One master and one replica.
18+
.. _admin-disaster_recovery-master_replica_manual_failover:
2319

24-
Problem: The master has crashed.
20+
Master crash: manual failover
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2522

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

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>``.
25+
**Problem:** The master has crashed.
3026

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).
27+
**Actions:**
3428

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*.
29+
1. Ensure the master is stopped.
30+
For example, log in to the master machine and use ``tt stop``.
4031

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:
32+
2. Configure a new replica set leader using the :ref:`<replicaset_name>.leader <configuration_reference_replicasets_name_leader>` option.
4533

46-
1. Find out the position of the crashed master, as reflected on the new master.
34+
3. Reload configuration on all instances using :ref:`config:reload() <config-module>`.
4735

48-
a. Find out instance UUID from the crashed master :ref:`xlog <internals-wal>`:
36+
4. Make sure that a new replica set leader is a master using :ref:`box.info.ro <box_introspection-box_info>`.
4937

50-
.. code-block:: console
38+
5. Remove a crashed master from a replica set as described in :ref:`Removing instances <replication-remove_instances>`.
5139

52-
$ head -5 *.xlog | grep Instance
53-
Instance: ed607cad-8b6d-48d8-ba0b-dae371b79155
40+
6. Set up a replacement for the crashed master on a spare host as described in :ref:`Adding instances <replication-add_instances>`.
5441

55-
b. On the new master, use the UUID to find the position:
42+
See also: :ref:`Performing manual failover <replication-controlled_failover>`.
5643

57-
.. code-block:: tarantoolsession
5844

59-
tarantool> box.info.vclock[box.space._cluster.index.uuid:select{'ed607cad-8b6d-48d8-ba0b-dae371b79155'}[1][1]]
60-
---
61-
- 23425
62-
<...>
45+
.. _admin-disaster_recovery-master_replica_auto_failover:
6346

64-
2. Play the records from the crashed .xlog to the new master, starting from the
65-
new master position:
47+
Master crash: automated failover
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6649

67-
a. Issue this request locally at the new master's machine to find out
68-
instance ID of the new master:
50+
**Configuration:** master-replica (:ref:`automated failover <replication-bootstrap-auto>`).
6951

70-
.. code-block:: tarantoolsession
52+
**Problem:** The master has crashed.
7153

72-
tarantool> box.space._cluster:select{}
73-
---
74-
- - [1, '88580b5c-4474-43ab-bd2b-2409a9af80d2']
75-
...
54+
**Actions:**
7655

77-
b. Play the records to the new master:
56+
1. Use ``box.info.election`` to make sure a new master is elected automatically.
7857

79-
.. code-block:: console
58+
2. Remove a crashed master from a replica set.
59+
60+
3. Set up a replacement for the crashed master on a spare host.
61+
Learn more from :ref:`Adding and removing instances <replication-automated-failover-add-remove-instances>`.
62+
63+
See also: :ref:`Testing automated failover <replication-automated-failover-testing>`.
64+
65+
66+
.. _admin-disaster_recovery-master_replica_data_loss:
67+
68+
Data loss
69+
~~~~~~~~~
70+
71+
**Configuration:** master-replica.
72+
73+
**Problem:** Some transactions are missing on a replica after the master has crashed.
74+
75+
**Actions:**
76+
77+
You lose a few transactions in the master
78+
:ref:`write-ahead log file <index-box_persistence>`, which may have not
79+
transferred to the replica before the crash. If you were able to salvage the master
80+
``.xlog`` file, you may be able to recover these.
81+
82+
1. Find out instance UUID from the crashed master :ref:`xlog <internals-wal>`:
83+
84+
.. code-block:: console
85+
86+
$ head -5 var/lib/instance001/*.xlog | grep Instance
87+
Instance: 9bb111c2-3ff5-36a7-00f4-2b9a573ea660
88+
89+
2. On the new master, use the UUID to find the position:
90+
91+
.. code-block:: tarantoolsession
92+
93+
app:instance002> box.info.vclock[box.space._cluster.index.uuid:select{'9bb111c2-3ff5-36a7-00f4-2b9a573ea660'}[1][1]]
94+
---
95+
- 999
96+
...
97+
98+
3. :ref:`Play the records <tt-play>` from the crashed ``.xlog`` to the new master, starting from the
99+
new master position:
100+
101+
.. code-block:: console
102+
103+
$ tt play 127.0.0.1:3302 var/lib/instance001/00000000000000000000.xlog \
104+
--from 1000 \
105+
--replica 1 \
106+
--username admin --password secret
80107
81-
$ tt play <new_master_uri> <xlog_file> --from 23425 --replica 1
82108
83109
.. _admin-disaster_recovery-master_master:
84110

85-
--------------------------------------------------------------------------------
86111
Master-master
87-
--------------------------------------------------------------------------------
112+
-------------
113+
114+
**Configuration:** :ref:`master-master <replication-bootstrap-master-master>`.
88115

89-
Configuration: Two masters.
116+
**Problem:** one master has crashed.
90117

91-
Problem: Master#1 has crashed.
118+
**Actions:**
92119

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

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

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.
100127

101128
.. _admin-disaster_recovery-data_loss:
102129

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

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

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

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

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.
155+
4. Start a new instance and use :ref:`tt play <tt-play>` command to
156+
play to it the contents of ``.snap`` and ``.xlog`` files up to the calculated LSN.
119157

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.
158+
5. Bootstrap a new replica from the recovered master.
122159

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.
160+
.. NOTE::
125161

126-
4. Bootstrap a new replica from the recovered master (instance#1).
162+
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: 22 additions & 48 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 the 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 if ``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 are given in regard to the instance on which ``box.info.replication`` is executed.
5029

5130
The primary indicators of replication health are:
5231

@@ -68,15 +47,10 @@ The primary indicators of replication health are:
6847
* :ref:`lag <box_info_replication_upstream_lag>`: the time difference between
6948
the local time at the instance, recorded when the event was received, and the
7049
local time at another master recorded when the event was written to the
71-
:ref:`write ahead log <internals-wal>` on that master.
50+
:ref:`write-ahead log <internals-wal>` on that master.
7251

7352
Since the ``lag`` calculation uses the operating system clocks from two different
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)