Skip to content

Commit 2a425df

Browse files
committed
Add examples
1 parent 7a9e817 commit 2a425df

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

doc/reference/reference_lua/box_info/synchro.rst

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ box.info.synchro
2020
* ``queue``:
2121

2222
- ``owner`` -- ID of the replica that owns the synchronous transaction queue.
23-
Once the owner instance appears, all other instances become read-only.
23+
Once an owner instance appears, all other instances become read-only.
2424
If the ``owner`` field is ``0``, then every instance is writeable,
25-
but it can't create any synchronous transactions.
26-
To claim or re-claim the queue, use :ref:`box.ctl.promote() <box_ctl-promote>` on the instance that you want
25+
but they can't create any synchronous transactions.
26+
To claim or reclaim the queue, use :ref:`box.ctl.promote() <box_ctl-promote>` on the instance that you want
2727
to promote.
28+
With elections enabled, the instance runs ``box.ctl.promote()`` automatically after winning the elections.
2829
Since version :doc:`2.10.0 </release/2.10.0>`.
2930

3031
- ``term`` -- current queue term.
3132
It contains the term of the last ``PROMOTE``.
3233
Usually it is equal to :ref:`box.info.election.term <box_info_election>`.
33-
However, the queue term value may be less than the corresponding one in election term.
34+
However, the queue term value may be less than the corresponding one in the election term.
3435
It can happen when a new round of elections started, but no one has promoted yet.
3536
Since version :doc:`2.10.0 </release/2.10.0>`.
3637

@@ -45,13 +46,97 @@ box.info.synchro
4546
Since version :doc:`2.5.3 </release/2.5.3>`, the option can be set as a dynamic formula.
4647
In this case, the value in the ``quorum`` member depends on the current number of replicas.
4748

48-
**Example:**
49+
**Example 1:**
50+
51+
In this example, the ``quorum`` field is equal to ``1``.
52+
This means that the synchronous transactions work like asynchronous.
53+
`1` means that successful WAL write to the master is enough to commit.
4954

5055
.. code-block:: tarantoolsession
5156
5257
tarantool> box.info.synchro
5358
---
5459
- queue:
60+
owner: 1
61+
term: 2
5562
len: 0
63+
busy: false
5664
quorum: 1
65+
...
66+
67+
**Example 2:**
68+
69+
First, set a quorum number and a timeout for synchronous replication using the following command:
70+
71+
.. code-block:: tarantoolsession
72+
73+
tarantool> box.cfg{
74+
> replication_synchro_quorum=2,
75+
> replication_synchro_timeout=1000
76+
> }
77+
78+
Next, check the current state of synchronous replication:
79+
80+
.. code-block:: tarantoolsession
81+
82+
tarantool> box.info.synchro
83+
---
84+
- queue:
85+
owner: 1
86+
term: 2
87+
len: 0
88+
busy: false
89+
quorum: 2
90+
...
91+
92+
Create a space called ``sync`` and enable synchronous replication on this space.
93+
Then, create an index.
94+
95+
.. code-block:: tarantoolsession
96+
97+
tarantool> s = box.schema.space.create("sync", {is_sync=true})
98+
tarantool> _ = s:create_index('pk')
99+
100+
After that, use ``box.ctl.promote`` function to claim the queue:
101+
102+
.. code-block:: tarantoolsession
103+
104+
tarantool> box.ctl.promote()
105+
106+
Next, use the ``replace`` command:
107+
108+
.. code-block:: tarantoolsession
109+
110+
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
111+
---
112+
- status: suspended
113+
name: lua
114+
id: 119
115+
...
116+
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
117+
---
118+
- status: suspended
119+
name: lua
120+
id: 120
121+
...
122+
tarantool> require('fiber').new(function() box.space.sync:replace{1} end)
123+
---
124+
- status: suspended
125+
name: lua
126+
id: 121
127+
...
128+
129+
If you use the ``box.info.synchro`` command again,
130+
you will see that now there are 3 transactions waiting in the queue:
131+
132+
.. code-block:: tarantoolsession
133+
134+
tarantool> box.info.synchro
135+
---
136+
- queue:
137+
owner: 1
138+
term: 2
139+
len: 3
140+
busy: false
141+
quorum: 2
57142
...

0 commit comments

Comments
 (0)