Skip to content

Commit 149218e

Browse files
committed
Update text after review, add code snippet
1 parent 5b8a237 commit 149218e

File tree

4 files changed

+113
-52
lines changed

4 files changed

+113
-52
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:

doc/reference/reference_lua/box_info/synchro.rst

Lines changed: 57 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ box.info.synchro
5353
confirmed entry waited for the quorum to collect.
5454

5555
* ``quorum`` -- the resulting value of the
56-
:ref:`replication_synchro_quorum <cfg_replication-replication_synchro_quorum>` configuration option.
56+
:ref:`replication.synchro_quorum <configuration_reference_replication_synchro_quorum>` configuration option.
5757
Since version :doc:`2.5.3 </release/2.5.3>`, the option can be set as a dynamic formula.
5858
In this case, the value of the ``quorum`` member depends on the current number of replicas.
5959

@@ -63,9 +63,9 @@ box.info.synchro
6363
That is, synchronous transactions work like asynchronous ones.
6464
`1` means that a successful WAL writing to the master is enough to commit.
6565

66-
.. code-block:: console
66+
.. code-block:: tarantoolsession
6767
68-
instance001> box.info.synchro
68+
box_info_synchro:instance001> box.info.synchro
6969
---
7070
- queue:
7171
owner: 1
@@ -79,19 +79,48 @@ box.info.synchro
7979
8080
**Example 2:**
8181

82-
First, set a quorum number and a timeout for synchronous replication in the configuration file (``config.yaml``):
82+
Example on GitHub: `box_info_synchro <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/replication/instances.enabled/box_info_synchro>`_
8383

84-
.. code-block:: yaml
84+
In this example, there are two instances:
8585

86-
replication:
87-
synchro_quorum: 2
88-
synchro_timeout: 1000
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:
96+
97+
.. code-block:: tarantoolsession
98+
99+
box_info_synchro:instance001> box.schema.user.grant('guest', 'super')
100+
101+
After that, use ``box.ctl.promote()`` function to claim the queue:
102+
103+
.. code-block:: tarantoolsession
104+
105+
box_info_synchro:instance001> box.ctl.promote()
106+
107+
Create a space called ``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')
89118
90119
Check the current state of synchronous replication:
91120

92-
.. code-block:: console
121+
.. code-block:: tarantoolsession
93122
94-
app:instance001> box.info.synchro
123+
box_info_synchro:instance001> box.info.synchro
95124
---
96125
- queue:
97126
owner: 1
@@ -103,64 +132,40 @@ box.info.synchro
103132
quorum: 2
104133
...
105134
106-
Create a space called ``sync`` and enable synchronous replication on this space:
135+
On the **second** instance, simulate failure like if this instance would crash or go out of the network:
107136

108-
.. code-block:: console
137+
.. code-block:: tarantoolsession
109138
110-
app:instance001> s = box.schema.space.create("sync", {is_sync=true})
111-
---
112-
...
113-
114-
Then, create an index:
115-
116-
.. code-block:: console
117-
118-
app:instance001> _ = s:create_index('pk')
119-
---
120-
...
121-
122-
After that, use ``box.ctl.promote()`` function to claim a queue:
139+
box_info_synchro:instance002> os.exit(0)
140+
⨯ Connection was closed. Probably instance process isn't running anymore
123141
124-
.. code-block:: console
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:
125145

126-
app:instance001> box.ctl.promote()
146+
.. code-block:: tarantoolsession
127147
128-
Next, perform data manipulations:
129-
130-
.. code-block:: console
131-
132-
app:instance001> require('fiber').new(function() box.space.sync:replace{1} end)
133-
---
134-
- status: suspended
135-
name: lua
136-
id: 130
137-
...
138-
app:instance001> require('fiber').new(function() box.space.sync:replace{1} end)
148+
box_info_synchro:instance001> fiber = require('fiber')
139149
---
140-
- status: suspended
141-
name: lua
142-
id: 131
143150
...
144-
app:instance001> require('fiber').new(function() box.space.sync:replace{1} end)
145-
---
146-
- status: suspended
147-
name: lua
148-
id: 132
151+
box_info_synchro:instance001> for i = 1, 3 do fiber.new(function() box.space.sync:replace{i} end) end
152+
--- end
149153
...
150154
151-
If you call the ``box.info.synchro`` command again,
152-
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:
153156

154-
.. code-block:: console
157+
.. code-block:: tarantoolsession
155158
156-
app:instance001> box.info.synchro
159+
box_info_synchro:instance001> box.info.synchro
157160
---
158161
- queue:
159162
owner: 1
160163
confirm_lag: 0
161164
term: 2
162-
age: 0
163-
len: 0
165+
age: 5.2658250015229
166+
len: 3
164167
busy: false
165168
quorum: 2
166169
...
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)