Skip to content

Commit 51bca07

Browse files
committed
Update after the review
1 parent 2cc293b commit 51bca07

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

doc/reference/reference_lua/box.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ with ``box``, with no arguments. The ``box`` module contains:
3838

3939
box_txn_management
4040
box_sql
41+
box_events
4142
box_once
4243
box_snapshot
4344

doc/reference/reference_lua/box_watchers.rst renamed to doc/reference/reference_lua/box_events.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
.. _box-watchers:
22

33
--------------------------------------------------------------------------------
4-
Functions for watchers
4+
Event watchers
55
--------------------------------------------------------------------------------
66

77
The ``box`` module contains some functions related to event subscriptions, also known as watchers.
88
The subscriptions are used to inform a client about server-side events.
9-
To see the list of the built-in events in Tarantool,
10-
check the :doc:`pub/sub </reference/reference_lua/pub-sub>` section.
9+
To read more about the built-in events in Tarantool,
10+
check the :doc:`pub/sub </reference/reference_lua/box_events/pub-sub>` section.
1111

1212
.. glossary::
1313

1414
Watcher
1515
A watcher is a :doc:`callback </book/box/triggers>` that is invoked when a state change occurs.
1616
To register a local watcher, use the ``box.watch()`` function.
1717
To create a remote watcher, user the ``conn:watch()`` function.
18+
Note that it is possible to register more than one watcher for the same key.
1819

1920
State
2021
A state is an internally stored key-value pair.
2122
The key is a string.
2223
The value is an arbitrary type that can be encoded as MsgPack.
2324
To update a state, use the ``box.broadcast()`` function.
2425

25-
First, a watcher callback is invoked unconditionally after the watcher registration.
26-
Note that it is possible to register more than one watcher for the same key.
26+
First, a watcher callback is invoked after the watcher registration.
27+
In this case, the callback is triggered whether or not the key has already been broadcast.
2728
After that, :doc:`box.broadcast() </reference/reference_lua/box_watchers/broadcast>` called on the remote host
2829
triggers all subsequent invocations.
30+
If a watcher is subscribed for a key that has not been broadcast yet, the callback is triggered only once,
31+
after the registration of the watcher.
2932

3033
A watcher callback is passed the name of the key for which it was registered and the current key data.
3134
A watcher callback is always invoked in a new fiber. It means that is is okay to yield in it.
@@ -41,7 +44,7 @@ value as soon as it returns.
4144
In this case, the watcher remains registered.
4245
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.
4346

44-
Below is a list of all functions related to watchers.
47+
Below is a list of all functions and members related to watchers or events.
4548

4649
.. container:: table
4750

@@ -64,8 +67,12 @@ Below is a list of all functions related to watchers.
6467
* - :doc:`./box_watchers/broadcast`
6568
- Update a state.
6669

70+
* - :ref:`˜Built-in events <pubsub>`
71+
- Pub/sub system and predefined events
72+
6773
.. toctree::
6874
:hidden:
6975

70-
box_watchers/watch
71-
box_watchers/broadcast
76+
box_events/watch
77+
box_events/broadcast
78+
box_events/pub-sub

doc/reference/reference_lua/pub-sub.rst renamed to doc/reference/reference_lua/box_events/pub-sub.rst

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ In Tarantool, :term:`pub/sub <publisher/subscriber>` is a :term:`notification` s
3030

3131
The pub/sub pattern is associated with subscriptions.
3232
Each subscription is defined by the certain key.
33-
The main feature of the subscriptions is a one-time action.
34-
It means that if the server generates too many events and a client is too slow,
35-
the server will not allocate additional memory.
3633

3734
Built-in events for pub/sub
3835
---------------------------
3936

40-
Built-in events have a special naming schema -- theirs names always start with the ``box.`` prefix.
41-
This prefix is reserved for the built-in events. It means that you cannot create new events with it.
37+
Predefined events have a special naming schema -- theirs names always start with the reserved ``box.`` prefix.
38+
It means that you cannot create new events with it.
4239

4340
The system processes the following events:
4441

@@ -47,23 +44,34 @@ The system processes the following events:
4744
* ``box.election``
4845
* ``box.schema``
4946

50-
In response to each event, the server sends back certain IPROTO fields.
47+
In response to each event, the server sends back certain ``IPROTO`` fields.
48+
49+
The events are available from the beginning as non-:ref:`MP_NIL <box_protocol-notation>`.
50+
If the events are broadcast before :doc:`box.cfg{} </reference/reference_lua/box_cfg>`,
51+
then the events values are empty:
52+
53+
.. code-block:: lua
54+
55+
box.id = {}
56+
box.schema = {}
57+
box.status = {}
58+
box.election = {}
5159
5260
box.id
5361
~~~~~~
5462

55-
Contains identification of the instance.
56-
Changes are particularly rare.
57-
Some values never change or change only once.
63+
Contains :ref:`identification <box_info_info>` of the instance.
64+
Value changes are rare.
5865

59-
The numeric instance ID is known only after registration.
60-
For anonymous replicas, the value is ``0`` until they are officially registered.
66+
* ``id``: the numeric instance ID is unknown before the registration.
67+
For anonymous replicas, the value is ``0`` until they are officially registered.
6168

62-
The UUID of the instance never changes after the first :doc:`box.cfg </reference/reference_lua/box_cfg>`.
63-
The value is unknown before the ``box.cfg`` call.
69+
* ``instance_uuid``: the UUID of the instance never changes after the first
70+
:doc:`box.cfg </reference/reference_lua/box_cfg>`.
71+
The value is unknown before the ``box.cfg`` call.
6472

65-
The replicaset UUID is unknown until the instance joins a replicaset or boots a new one.
66-
The events are supposed to start working before that -- right with the start of the listen.
73+
* ``replicaset_uuid``: the value is unknown until the instance joins a replicaset or boots a new one.
74+
The events start working before that -- right with the start of the listen.
6775

6876
.. code-block:: lua
6977
@@ -78,8 +86,10 @@ box.status
7886
~~~~~~~~~~
7987

8088
Contains generic blob about the instance status.
81-
There are the most frequently used and not frequently changed
82-
:doc:`config options </reference/reference_lua/box_cfg>` and :doc:`box.info </reference/reference_lua/box_info>` fields.
89+
90+
* ``is_ro``: :ref:`indicates the read-only mode <box_introspection-box_info>` or the ``orphan`` status.
91+
* ``is_ro_cfg``: indicates the :ref:`read_only <cfg_basic-read_only>` mode for the instance.
92+
* ``status``: shows the status of an instance.
8393

8494
.. code-block:: lua
8595
@@ -92,8 +102,13 @@ There are the most frequently used and not frequently changed
92102
box.election
93103
~~~~~~~~~~~~
94104

95-
Contains all the required parts of :doc:`box.info.election </reference/reference_lua/box_info/election>`
96-
that are necessary to find out who is the most recent writable leader.
105+
Contains fields of the :doc:`box.info.election </reference/reference_lua/box_info/election>`
106+
that are necessary to find out the most recent writable leader.
107+
108+
* ``term``: shows the current election term.
109+
* ``role``: indicates the election state of the node -- ``leader``, ``follower``, or ``candidate``.
110+
* ``is_ro``: :ref:`indicates the read-only mode <box_introspection-box_info>` or the ``orphan`` status.
111+
* ``leader``: shows the leader node ID in the current term.
97112

98113
.. code-block:: lua
99114
@@ -108,31 +123,15 @@ box.schema
108123
~~~~~~~~~~
109124

110125
Contains schema-related data.
111-
Currently, it contains only the version.
126+
127+
* ``version``: shows the schema version.
112128

113129
.. code-block:: lua
114130
115131
{
116132
MP_STR “version”: MP_UINT schema_version,
117133
}
118134
119-
The events are available from the beginning as non-:ref:`MP_NIL <box_protocol-notation>`.
120-
It is necessary for supported local subscriptions.
121-
Otherwise, there is no way to detect whether an event is supported at all by this Tarantool version.
122-
If the events are broadcast before :doc:`box.cfg{} </reference/reference_lua/box_cfg>`,
123-
then the following values are available:
124-
125-
.. code-block:: lua
126-
127-
box.id = {}
128-
box.schema = {}
129-
box.status = {}
130-
box.election = {}
131-
132-
This way, users can distinguish if an event being not supported
133-
at all or if ``box.cfg{}`` has not been called yet.
134-
Otherwise, they would need to parse the ``_TARANTOOL`` version string locally and the ``peer_version`` in ``net.box``.
135-
136135
Usage example
137136
-------------
138137

doc/reference/reference_lua/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ This reference covers Tarantool's built-in Lua modules.
5555
uri
5656
xlog
5757
yaml
58-
pub-sub
5958
other
6059
errcodes
6160
debug_facilities

0 commit comments

Comments
 (0)