Skip to content

Commit f0695d1

Browse files
xuniqlenkis
andauthored
Add description for the age and confirm_lag fields in box.info.synchro.queue (#4559)
* Add description for the `age` and `confirm_lag` fields * Add code snippet Fixes #4284 Fixes #4400 --------- Co-authored-by: Elena Shebunyaeva <[email protected]>
1 parent f58bb6f commit f0695d1

File tree

4 files changed

+125
-42
lines changed

4 files changed

+125
-42
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Using box.info.synchro
2+
3+
A sample application demonstrating how to work with [box.info.synchro](https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_info/synchro/).
4+
5+
## Running
6+
7+
To start all instances, execute the following command in the [replication](../../../replication) directory:
8+
9+
```console
10+
$ tt start box_info_synchro
11+
```
12+
13+
To check the instance status, run:
14+
15+
```console
16+
$ tt status box_info_synchro
17+
```
18+
19+
To connect to the ``instance001`` instance, run:
20+
21+
```console
22+
$ tt connect box_info_synchro:instance001
23+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
credentials:
2+
users:
3+
replicator:
4+
password: 'topsecret'
5+
roles: [replication]
6+
7+
iproto:
8+
advertise:
9+
peer:
10+
login: replicator
11+
12+
groups:
13+
group001:
14+
replicasets:
15+
replicaset001:
16+
instances:
17+
instance001:
18+
database:
19+
mode: rw
20+
replication:
21+
synchro_quorum: 2
22+
synchro_timeout: 1000
23+
iproto:
24+
listen:
25+
- uri: '127.0.0.1:3301'
26+
instance002:
27+
database:
28+
mode: ro
29+
iproto:
30+
listen:
31+
- uri: '127.0.0.1:3302'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
instance001:
2+
instance002:
Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
.. _box_info_synchro:
22

3-
================================================================================
43
box.info.synchro
5-
================================================================================
4+
================
65

76
.. module:: box.info
87

@@ -26,9 +25,13 @@ box.info.synchro
2625
but they can't create any synchronous transactions.
2726
To claim or reclaim the queue, use :ref:`box.ctl.promote() <box_ctl-promote>` on the instance that you want
2827
to promote.
29-
With elections enabled, an instance runs ``box.ctl.promote()`` command automatically after winning the elections.
3028
To clear the ownership, call :ref:`box.ctl.demote() <box_ctl-demote>` on the synchronous queue owner.
3129

30+
When Raft election is enabled and :ref:`replication.election_mode <configuration_reference_replication_election_mode>`
31+
is set to ``candidate``, the new Raft leader claims the queue automatically after winning the elections.
32+
It means that the value of ``box.info.synchro.queue.owner`` becomes equal to :ref:`box.info.election.leader <box_info_election>`.
33+
When Raft is enabled, no manual intervention with ``box.ctl.promote()`` or ``box.ctl.demote()`` is required.
34+
3235
- ``term`` (since version :doc:`2.10.0 </release/2.10.0>`) -- current queue term.
3336
It contains the term of the last ``PROMOTE`` request.
3437
Usually, it is equal to :ref:`box.info.election.term <box_info_election>`.
@@ -43,102 +46,126 @@ box.info.synchro
4346
Until the request is complete, any other incoming synchronous transactions and system requests
4447
will be delayed.
4548

49+
- ``age`` (since version :doc:`3.2.0 </release/3.2.0>`) -- the time in seconds that the oldest entry currently
50+
present in the queue has spent waiting for the quorum to collect.
51+
52+
- ``confirm_lag`` (since version :doc:`3.2.0 </release/3.2.0>`) -- the time in seconds that the latest successfully
53+
confirmed entry waited for the quorum to collect.
54+
4655
* ``quorum`` -- the resulting value of the
47-
:ref:`replication_synchro_quorum <cfg_replication-replication_synchro_quorum>` configuration option.
56+
:ref:`replication.synchro_quorum <configuration_reference_replication_synchro_quorum>` configuration option.
4857
Since version :doc:`2.5.3 </release/2.5.3>`, the option can be set as a dynamic formula.
4958
In this case, the value of the ``quorum`` member depends on the current number of replicas.
5059

5160
**Example 1:**
5261

53-
In this example, the ``quorum`` field is equal to ``1``.
62+
In this example, the ``quorum`` field is equal to `1`.
5463
That is, synchronous transactions work like asynchronous ones.
5564
`1` means that a successful WAL writing to the master is enough to commit.
5665

5766
.. code-block:: tarantoolsession
5867
59-
tarantool> box.info.synchro
68+
box_info_synchro:instance001> box.info.synchro
6069
---
6170
- queue:
6271
owner: 1
72+
confirm_lag: 0
6373
term: 2
74+
age: 0
6475
len: 0
6576
busy: false
6677
quorum: 1
6778
...
6879
6980
**Example 2:**
7081

71-
First, set a quorum number and a timeout for synchronous replication using the following command:
82+
Example on GitHub: `box_info_synchro <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/replication/instances.enabled/box_info_synchro>`_
83+
84+
In this example, there are two instances:
85+
86+
- ``instance001`` is going to be the leader.
87+
- ``instance002`` is a follower instance.
88+
89+
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/box_info_synchro/config.yaml
90+
:language: yaml
91+
:start-at: groups
92+
:end-at: 3302
93+
:dedent:
94+
95+
On the **first** instance, grant the user with the ``super`` role:
7296

7397
.. code-block:: tarantoolsession
7498
75-
tarantool> box.cfg{
76-
> replication_synchro_quorum=2,
77-
> replication_synchro_timeout=1000
78-
> }
99+
box_info_synchro:instance001> box.schema.user.grant('guest', 'super')
79100
80-
Next, check the current state of synchronous replication:
101+
After that, use the ``box.ctl.promote()`` function to claim the queue:
81102

82103
.. code-block:: tarantoolsession
83104
84-
tarantool> box.info.synchro
105+
box_info_synchro:instance001> box.ctl.promote()
106+
107+
Create a space named ``sync`` and enable synchronous replication on this space:
108+
109+
.. code-block:: tarantoolsession
110+
111+
box_info_synchro:instance001> s = box.schema.space.create("sync", {is_sync=true})
112+
113+
Then, create an index:
114+
115+
.. code-block:: tarantoolsession
116+
117+
box_info_synchro:instance001> _ = s:create_index('pk')
118+
119+
Check the current state of synchronous replication:
120+
121+
.. code-block:: tarantoolsession
122+
123+
box_info_synchro:instance001> box.info.synchro
85124
---
86125
- queue:
87126
owner: 1
127+
confirm_lag: 0
88128
term: 2
129+
age: 0
89130
len: 0
90131
busy: false
91132
quorum: 2
92133
...
93134
94-
Create a space called ``sync`` and enable synchronous replication on this space.
95-
Then, create an index.
135+
On the **second** instance, simulate failure like if this instance would crash or go out of the network:
96136

97137
.. code-block:: tarantoolsession
98138
99-
tarantool> s = box.schema.space.create("sync", {is_sync=true})
100-
tarantool> _ = s:create_index('pk')
139+
box_info_synchro:instance002> os.exit(0)
140+
⨯ Connection was closed. Probably instance process isn't running anymore
101141
102-
After that, use ``box.ctl.promote()`` function to claim a queue:
142+
On the **first** instance, try to perform some synchronous transactions.
143+
The transactions would hang, because the :ref:`replication.synchro_quorum <configuration_reference_replication_synchro_quorum>`
144+
option is set to `2`, and the second instance is not available:
103145

104146
.. code-block:: tarantoolsession
105147
106-
tarantool> box.ctl.promote()
107-
108-
Next, perform data manipulations:
109-
110-
.. code-block:: tarantoolsession
111-
112-
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
113-
---
114-
- status: suspended
115-
name: lua
116-
id: 119
117-
...
118-
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
148+
box_info_synchro:instance001> fiber = require('fiber')
119149
---
120-
- status: suspended
121-
name: lua
122-
id: 120
123150
...
124-
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
151+
box_info_synchro:instance001> for i = 1, 3 do fiber.new(function() box.space.sync:replace{i} end) end
125152
---
126-
- status: suspended
127-
name: lua
128-
id: 121
129153
...
130154
131-
If you call the ``box.info.synchro`` command again,
132-
you will see that now there are 3 transactions waiting in the queue:
155+
Call the ``box.info.synchro`` command on the first instance again:
133156

134157
.. code-block:: tarantoolsession
135158
136-
tarantool> box.info.synchro
159+
box_info_synchro:instance001> box.info.synchro
137160
---
138161
- queue:
139162
owner: 1
163+
confirm_lag: 0
140164
term: 2
165+
age: 5.2658250015229
141166
len: 3
142167
busy: false
143168
quorum: 2
144-
...
169+
...
170+
171+
The ``len`` field is now equal to 3. It means that there are 3 transactions waiting in the queue.

0 commit comments

Comments
 (0)