Skip to content

Commit 117d601

Browse files
authored
iproto: document box.iproto module (#3766)
Lua API: * Add `box.iproto module` page * Add `box.iproto.send()` * Add `box.iproto.override()` * Updated description of `box.info.schema_version` * Added exported IPROTO constants (`type`, `ballot`, `key`, `metadata`, `raft`, `flag`) and features (`protocol_features`, `protocol_version`, `feature`) - each constant type is placed in the corresponding box.iproto page. * Updated description of `box.session.id()` C API: * Add `box_iproto_send()` * Add `box_iproto_override()` * Add `box_schema_version()` * Updated description of `box_session_id()` Binary protocol: * Document IPROTO_UNKNOWN constant in the binary protocol section Fixes #3241 Fixes #3288 Fixes #3278
1 parent b5b805b commit 117d601

23 files changed

+778
-37
lines changed

doc/dev_guide/internals/box_protocol.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ The binary protocol provides complete access to Tarantool functionality, includi
2020
asynchronously via the same connection
2121
* response format that supports zero-copy writes
2222

23+
.. note::
24+
25+
Since version :doc:`2.11.0 </release/2.11.0>`, you can use the :ref:`box.iproto <box_iproto>` submodule to access
26+
IPROTO constants and features from Lua. The submodule enables to :ref:`send arbitrary IPROTO packets <reference_lua-box_iproto_send>`
27+
over the session's socket and :ref:`override the behavior <reference_lua-box_iproto_override>` for all IPROTO
28+
request types. Also, :ref:`IPROTO_UNKNOWN <box_iproto-unknown>` constant is introduced. The constant is used for the
29+
:ref:`box.iproto.override() <reference_lua-box_iproto_override>` API, which allows setting a handler for incoming requests with an unknown type.
30+
2331
.. toctree::
2432
:maxdepth: 1
2533

doc/dev_guide/internals/iproto/format.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The header is an MP_MAP. It may contain, in any order:
3535
.. raw:: html
3636
:file: images/header.svg
3737

38-
* Both the request and response make use of the :ref:`IPROTO_REQUEST_TYPE <internals-iproto-keys-request_type>` key.
38+
* Both the request and response use the :ref:`IPROTO_REQUEST_TYPE <internals-iproto-keys-request_type>` key.
3939
It denotes the type of the packet.
4040

4141
* The request and the matching response have the same sync number (:ref:`IPROTO_SYNC <internals-iproto-keys-sync>`).
@@ -61,22 +61,24 @@ To see how Tarantool decodes the header, have a look at file
6161
function ``netbox_decode_data``.
6262

6363
For example, in a successful response to ``box.space:select()``,
64-
the IPROTO_REQUEST_TYPE value will be 0 = ``IPROTO_OK`` and the
65-
array will have all the tuples of the result.
64+
the IPROTO_REQUEST_TYPE value is 0 = ``IPROTO_OK`` and the
65+
array has all the tuples of the result.
6666

6767
Read the source code file `net_box.c <https://github.com/tarantool/tarantool/blob/master/src/box/lua/net_box.c>`__
6868
where the function ``decode_metadata_optional`` is an example of how Tarantool
6969
itself decodes extra items.
7070

71+
.. _box_protocol-body:
72+
7173
Body
7274
----
7375

7476
The body is an MP_MAP. Maximal iproto package body length is 2 GiB.
7577

7678
The body has the details of the request or response. In a request, it can also
77-
be absent or be an empty map. Both these states will be interpreted equally.
78-
Responses will contain the body anyway even for an
79-
:ref:`IPROTO_PING <box_protocol-ping>` request, where it will be an empty MP_MAP.
79+
be absent or be an empty map. Both these states are interpreted equally.
80+
Responses contain the body anyway even for an
81+
:ref:`IPROTO_PING <box_protocol-ping>` request, where it is an empty MP_MAP.
8082

8183
A lot of responses contain the IPROTO_DATA map:
8284

doc/dev_guide/internals/iproto/keys.rst

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ The keys are Tarantool constants that are either defined or mentioned in the
1010

1111
While the keys themselves are unsigned 8-bit integers, their values can have different types.
1212

13+
.. _internals-iproto-keys-basic:
14+
1315
Basic description
1416
-----------------
1517

@@ -132,6 +134,8 @@ General
132134
- If ``IPROTO_FETCH_POSITION`` is **true**, returns a base64-encoded string representing
133135
the position of the last selected tuple
134136

137+
.. _internals-iproto-keys-streams:
138+
135139
Streams
136140
~~~~~~~
137141

@@ -192,8 +196,7 @@ General replication
192196

193197
* - IPROTO_REPLICASET_UUID
194198
- 0x25 |br| MP_STR
195-
- UUID of the replica set.
196-
Prior to Tarantool version 2.11, IPROTO_REPLICASET_UUID was called IPROTO_CLUSTER_UUID.
199+
- Before Tarantool version 2.11, IPROTO_REPLICASET_UUID was called IPROTO_CLUSTER_UUID.
197200

198201
* - IPROTO_LSN
199202
- 0x03 |br| MP_UINT
@@ -271,7 +274,7 @@ General replication
271274
followed by an array of ids of instances whose rows won't be relayed to the replica.
272275
Since v. :doc:`2.10.0 </release/2.10.0>`
273276

274-
.. _internals-iproto-keys-syncro-replication:
277+
.. _internals-iproto-keys-synchro-replication:
275278

276279
Synchronous replication
277280
~~~~~~~~~~~~~~~~~~~~~~~
@@ -319,6 +322,8 @@ Synchronous replication
319322

320323
All ``IPROTO_RAFT_*`` keys are used only in ``IPROTO_RAFT*`` requests.
321324

325+
.. _internals-iproto-keys-events:
326+
322327
Events and subscriptions
323328
~~~~~~~~~~~~~~~~~~~~~~~~
324329

@@ -342,6 +347,8 @@ Events and subscriptions
342347

343348
:ref:`Learn more about events and subscriptions in iproto <box-protocol-watchers>`.
344349

350+
.. _internals-iproto-keys-sql-specific:
351+
345352
SQL-specific
346353
~~~~~~~~~~~~
347354

@@ -460,7 +467,7 @@ Available IPROTO_FEATURES are the following:
460467
in the request header). Learn more about :ref:`sending transaction commands <box_protocol-stream_transactions>`.
461468

462469
- ``IPROTO_FEATURE_ERROR_EXTENSION = 2`` -- :ref:`MP_ERROR <msgpack_ext-error>`
463-
MsgPack extension support. Clients that don't support this feature will receive
470+
MsgPack extension support. Clients that don't support this feature receive
464471
error responses for :ref:`IPROTO_EVAL <box_protocol-eval>` and
465472
:ref:`IPROTO_CALL <box_protocol-call>` encoded to string error messages.
466473

@@ -606,7 +613,7 @@ IPROTO_ERROR_24
606613

607614
Code: 0x31.
608615

609-
IPROTO_ERROR_24 is used in Tarantool versions prior to :doc:`2.4.1 </release/2.4.1>`.
616+
IPROTO_ERROR_24 is used in Tarantool versions before :doc:`2.4.1 </release/2.4.1>`.
610617
The key contains the error in the string format.
611618

612619
Since :doc:`Tarantool 2.4.1 </release/2.4.1>`,
@@ -654,10 +661,10 @@ Code: 0x09.
654661
When it comes to replicating synchronous transactions, the IPROTO_FLAGS key is included in the header.
655662
The key contains an MP_UINT value of one or more bits:
656663

657-
* IPROTO_FLAG_COMMIT (0x01) will be set if this is the last message for a transaction.
658-
* IPROTO_FLAG_WAIT_SYNC (0x02) will be set if this is the last message
664+
* IPROTO_FLAG_COMMIT (0x01) is set if this is the last message for a transaction.
665+
* IPROTO_FLAG_WAIT_SYNC (0x02) is set if this is the last message
659666
for a transaction which cannot be completed immediately.
660-
* IPROTO_FLAG_WAIT_ACK (0x04) will be set if this is the last message for a synchronous transaction.
667+
* IPROTO_FLAG_WAIT_ACK (0x04) is set if this is the last message for a synchronous transaction.
661668

662669
Example:
663670

@@ -739,7 +746,7 @@ at least IPROTO_FIELD_NAME (0x00) and MP_STR, and IPROTO_FIELD_TYPE (0x01) and M
739746

740747
Additionally, if ``sql_full_metadata`` in the
741748
:ref:`_session_settings <box_space-session_settings>` system space
742-
is TRUE, then the array will have these additional column maps
749+
is TRUE, then the array has these additional column maps
743750
which correspond to components described in the :ref:`box.execute() <box-sql_if_full_metadata>` section.
744751

745752
.. _internals-iproto-keys-sql_bind:

doc/dev_guide/internals/iproto/replication.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ These values and the corresponding packet body structures are considered below.
1111

1212
Connectors and clients do not need to send replication packets.
1313

14+
.. _box_protocol-general:
15+
1416
General
1517
-------
1618

@@ -198,7 +200,7 @@ Synchronous
198200
- 0x28
199201
- Confirm that the RAFT transactions have achieved quorum and can be committed
200202

201-
* - :ref:`IPROTO_RAFT_ROLLBACK <box_protocol-raft_confirm>`
203+
* - :ref:`IPROTO_RAFT_ROLLBACK <box_protocol-raft_rollback>`
202204
- 0x29
203205
- Roll back the RAFT transactions because they haven't achieved quorum
204206

doc/dev_guide/internals/iproto/requests.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Overview
3838
- 0x8XXX |br| MP_INT
3939
- Error response
4040

41+
* - :ref:`IPROTO_UNKNOWN <internals-iproto-unknown>`
42+
- -1 |br| MP_UINT
43+
- An unknown request type
44+
4145
* - :ref:`IPROTO_SELECT <box_protocol-select>`
4246
- 0x01
4347
- :ref:`Select <box_space-select>` request
@@ -126,6 +130,18 @@ constants for return codes.
126130
To learn more about error responses,
127131
check the section :ref:`Request and response format <box_protocol-responses_error>`.
128132

133+
.. _internals-iproto-unknown:
134+
135+
IPROTO_UNKNOWN
136+
~~~~~~~~~~~~~~
137+
138+
Since :doc:`2.11.0 </release/2.11.0>`.
139+
140+
Code: -1.
141+
142+
An unknown request type. The constant is used to override the handler of unknown IPROTO request types.
143+
Learn more: :ref:`box.iproto.override() <reference_lua-box_iproto_override>` and :ref:`box_iproto_override <box_box_iproto_override>`.
144+
129145
.. _box_protocol-select:
130146

131147
IPROTO_SELECT

0 commit comments

Comments
 (0)