Skip to content

Commit 9f10fa0

Browse files
xuniqpatiencedaurmaryartkey
authored
Add intro and explanation for the Streams feature
Fixes #2349 Written by Kseniia Antonova Translated by Maria Kovalevskaya, translation reviewed by Patience Daur Co-authored-by: Kseniia Antonova <[email protected]> Co-authored-by: Patience Daur <[email protected]> Co-authored-by: Maria Kovalevskaya <[email protected]>
1 parent b5636cb commit 9f10fa0

File tree

7 files changed

+277
-9
lines changed

7 files changed

+277
-9
lines changed

doc/book/box/atomic.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Transactions in Tarantool occur in **fibers** on a single **thread**.
88
That is why Tarantool has a guarantee of execution atomicity.
99
That requires emphasis.
1010

11+
Since :tarantool-release:`2.10.0-beta1`, Tarantool supports streams and interactive transactions over them.
12+
See :ref:`Streams <box_stream>`.
13+
1114
.. _atomic-threads_fibers_yields:
1215

1316
--------------------------------------------------------------------------------

doc/book/box/index.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ a database manager.
99

1010
This chapter contains the following sections:
1111

12-
.. toctree::
13-
:maxdepth: 2
14-
:numbered: 0
12+
.. toctree::
13+
:maxdepth: 2
14+
:numbered: 0
1515

16-
data_model
17-
atomic
18-
authentication
19-
triggers
20-
limitations
21-
engines/index
16+
data_model
17+
atomic
18+
stream
19+
authentication
20+
triggers
21+
limitations
22+
engines/index

doc/book/box/stream.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.. _box_stream:
2+
3+
Streams and interactive transactions
4+
====================================
5+
6+
.. _box_stream-overview:
7+
8+
Overview
9+
--------
10+
11+
Since :tarantool-release:`2.10.0-beta1`, iproto implements streams and interactive transactions.
12+
13+
.. glossary::
14+
15+
Stream
16+
A stream supports multiplexing several transactions over one connection.
17+
All requests in the stream are executed strictly sequentially,
18+
which allows the implementation of
19+
:term:`interactive transactions <interactive transaction>`.
20+
21+
Unlike a thread associated with multitasking and execution within a program,
22+
a stream transfers data via the protocol between a client and a server.
23+
24+
.. glossary::
25+
26+
Interactive transaction
27+
An interactive transaction is a transaction that does not need to be sent in a single request.
28+
The ``begin``, ``commit``, and other TX statements can be sent and executed in different requests.
29+
30+
.. _box_stream-features:
31+
32+
New features
33+
------------
34+
35+
The primary purpose of :term:`streams <stream>` is to execute transactions via iproto.
36+
Every stream has its own identifier, which is unique within the connection.
37+
All requests with the same non-zero stream ID belong to the same stream.
38+
All requests in the stream are processed synchronously.
39+
The next request will not start executing until the previous one is completed.
40+
If a request's stream ID is ``0``, it does not belong to any stream and is processed in the old way.
41+
42+
In :doc:`net.box </reference/reference_lua/net_box>`, a stream is an object above the connection that has the same methods
43+
but allows executing requests sequentially.
44+
The ID is generated on the client side automatically.
45+
If a user writes their own connector and wants to use streams,
46+
they must transmit the ``stream_id`` over the iproto protocol.
47+
48+
.. _box_stream-interaction:
49+
50+
Interaction between streams and transactions
51+
--------------------------------------------
52+
53+
As each stream can start a transaction, several transactions can be multiplexed over one connection.
54+
There are multiple ways to begin, commit, and roll back a transaction.
55+
One can do that using the appropriate stream methods---``call``, ``eval``,
56+
or ``execute``---with the SQL transaction syntax. Users can mix these methods.
57+
For example, one might start a transaction using ``stream:begin()``
58+
and commit it with ``stream:call('box.commit')`` or ``stream:execute('COMMIT')``.
59+
All the requests between ``stream:begin()`` and ``stream:commit()`` are executed within the same transaction.
60+
If any request fails during the transaction, it will not affect the other requests in the transaction.
61+
If a disconnect occurs while there is an active transaction in the stream,
62+
that transaction will be rolled back if it hasn't been committed before the connection failure.
63+
64+
Example:
65+
66+
.. code-block:: lua
67+
68+
local conn = net_box.connect(remote_server_addr)
69+
local conn_space = conn.space.test
70+
local stream = conn:new_stream()
71+
local stream_space = stream.space.test
72+
73+
-- Begin transaction over an iproto stream:
74+
stream:begin()
75+
space:replace({1})
76+
77+
-- Empty select, the transaction was not committed.
78+
-- You can't see it from the requests that do not belong to the
79+
-- transaction.
80+
81+
-- Select returns the previously inserted tuple,
82+
-- because this select belongs to the transaction:
83+
conn_space:select{}
84+
stream_space:select({})
85+
86+
-- Commit transaction:
87+
stream:commit()
88+
89+
-- Now this select also returns the tuple, because the transaction has been committed:
90+
conn_space:select{}

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
CRUD operations <reference/reference_lua/box_space>
6969
book/box/indexes
7070
book/box/atomic
71+
Streams <book/box/stream>
7172
book/box/authentication
7273
book/box/triggers
7374
reference/reference_rock/vshard/vshard_index

doc/toctree.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CRUD operations <reference/reference_lua/box_space>
1010
book/box/indexes
1111
book/box/atomic
12+
Streams <book/box/stream>
1213
book/box/authentication
1314
book/box/triggers
1415
reference/reference_rock/vshard/vshard_index

locale/ru/LC_MESSAGES/book/box/atomic.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ msgstr ""
1111
"почему Tarantool дает гарантию атомарности выполнения. На это следует "
1212
"обратить внимание."
1313

14+
msgid ""
15+
"Since :tarantool-release:`2.10.0-beta1`, Tarantool supports streams and "
16+
"interactive transactions over them. See :ref:`Streams <box_stream>`."
17+
msgstr ""
18+
"Начиная с версии :tarantool-release:`2.10.0-beta1`, Tarantool поддерживает "
19+
"стримы и интерактивные транзакции. Больше информации можно найти здесь: "
20+
":ref:`Стримы <box_stream>`."
21+
1422
msgid "Threads, fibers and yields"
1523
msgstr "Потоки, файберы и передача управления"
1624

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
2+
msgid "Streams and interactive transactions"
3+
msgstr "Стримы и интерактивные транзакции"
4+
5+
msgid "Overview"
6+
msgstr "Общие сведения"
7+
8+
msgid ""
9+
"Since :tarantool-release:`2.10.0-beta1`, iproto implements streams and "
10+
"interactive transactions."
11+
msgstr ""
12+
"Начиная с версии :tarantool-release:`2.10.0-beta1`, в iproto реализованы "
13+
"стримы и интерактивные транзакции."
14+
15+
msgid "Stream"
16+
msgstr "Стрим"
17+
18+
msgid ""
19+
"A stream supports multiplexing several transactions over one connection. All"
20+
" requests in the stream are executed strictly sequentially, which allows the"
21+
" implementation of :term:`interactive transactions <interactive "
22+
"transaction>`."
23+
msgstr ""
24+
"Стрим поддерживает мультиплексирование нескольких транзакций в рамках одного"
25+
" соединения. Все запросы в стриме выполняются строго последовательно, что "
26+
"позволяет проводить :term:`интерактивные транзакции <interactive "
27+
"transaction>`."
28+
29+
msgid ""
30+
"Unlike a thread associated with multitasking and execution within a program,"
31+
" a stream transfers data via the protocol between a client and a server."
32+
msgstr ""
33+
"Стрим передает данные по протоколу между клиентом и сервером. Это понятие не"
34+
" связано с потоками выполнения, реализующими многозадачность внутри "
35+
"программ."
36+
37+
msgid "Interactive transaction"
38+
msgstr "Интерактивная транзакция"
39+
40+
msgid ""
41+
"An interactive transaction is a transaction that does not need to be sent in"
42+
" a single request. The ``begin``, ``commit``, and other TX statements can be"
43+
" sent and executed in different requests."
44+
msgstr ""
45+
"Интерактивной называется транзакция, которую не обязательно отправлять "
46+
"целиком в рамках одного запроса. ``begin``, ``commit`` и другие TX-"
47+
"инструкции могут быть отправлены и выполнены в разных запросах."
48+
49+
msgid "New features"
50+
msgstr "Новые функциональные возможности"
51+
52+
msgid ""
53+
"The primary purpose of :term:`streams <stream>` is to execute transactions "
54+
"via iproto. Every stream has its own identifier, which is unique within the "
55+
"connection. All requests with the same non-zero stream ID belong to the same"
56+
" stream. All requests in the stream are processed synchronously. The next "
57+
"request will not start executing until the previous one is completed. If a "
58+
"request's stream ID is ``0``, it does not belong to any stream and is "
59+
"processed in the old way."
60+
msgstr ""
61+
"Основное предназначение :term:`стрима <stream>` --- выполнение транзакций "
62+
"внутри потока iproto. У каждого стрима есть идентификатор, уникальный в "
63+
"рамках соединения. Все запросы с одинаковым ненулевым идентификатором стрима"
64+
" относятся к одному стриму. Запросы в стриме выполняются синхронно. "
65+
"Следующий запрос не начинает выполняться, пока не завершится предыдущий. "
66+
"Если идентификатор стрима запроса равен ``0``, то этот запрос не привязан к "
67+
"какому-либо стриму и обрабатывается обычным способом."
68+
69+
msgid ""
70+
"In :doc:`net.box </reference/reference_lua/net_box>`, a stream is an object "
71+
"above the connection that has the same methods but allows executing requests"
72+
" sequentially. The ID is generated on the client side automatically. If a "
73+
"user writes their own connector and wants to use streams, they must transmit"
74+
" the ``stream_id`` over the iproto protocol."
75+
msgstr ""
76+
"В :doc:`net.box </reference/reference_lua/net_box>` стрим представляет собой"
77+
" объект над соединением, который имеет те же методы, но позволяет выполнять "
78+
"запросы последовательно. Идентификатор генерируется автоматически на стороне"
79+
" клиента. Пользователь может также создать собственный коннектор с "
80+
"поддержкой стримов. Используя стримы с пользовательским коннектором, "
81+
"необходимо передавать ``stream_id`` через протокол iproto."
82+
83+
msgid "Interaction between streams and transactions"
84+
msgstr "Взаимодействие между стримами и транзакциями"
85+
86+
msgid ""
87+
"As each stream can start a transaction, several transactions can be "
88+
"multiplexed over one connection. There are multiple ways to begin, commit, "
89+
"and roll back a transaction. One can do that using the appropriate stream "
90+
"methods---``call``, ``eval``, or ``execute``---with the SQL transaction "
91+
"syntax. Users can mix these methods. For example, one might start a "
92+
"transaction using ``stream:begin()`` and commit it with "
93+
"``stream:call('box.commit')`` or ``stream:execute('COMMIT')``. All the "
94+
"requests between ``stream:begin()`` and ``stream:commit()`` are executed "
95+
"within the same transaction. If any request fails during the transaction, it"
96+
" will not affect the other requests in the transaction. If a disconnect "
97+
"occurs while there is an active transaction in the stream, that transaction "
98+
"will be rolled back if it hasn't been committed before the connection "
99+
"failure."
100+
msgstr ""
101+
"Поскольку каждый стрим может запустить транзакцию, одно соединение способно "
102+
"мультиплексировать несколько транзакций. Начать транзакцию, сделать ее "
103+
"коммит и отменить ее можно, используя с синтаксисом SQL-транзакций методы "
104+
"стрима: ``call``, ``eval``, ``execute``. Пользователь может комбинировать "
105+
"эти методы. Например, можно начать транзакцию с помощью ``stream:begin()``, "
106+
"а коммит провести, используя ``stream:call('box.commit')`` или "
107+
"``stream:execute('COMMIT')``. Все запросы между ``stream:begin()`` и "
108+
"``stream:commit()`` выполняются в рамках одной транзакции. Если один запрос "
109+
"во время транзакции завершится ошибкой, на остальные запросы это не "
110+
"повлияет. Если во время активной транзакции в стриме произойдет сбой "
111+
"подключения, эта транзакция будет отменена, если она не прошла коммит до "
112+
"сбоя."
113+
114+
msgid "Example:"
115+
msgstr "Пример:"
116+
117+
msgid ""
118+
"local conn = net_box.connect(remote_server_addr)\n"
119+
"local conn_space = conn.space.test\n"
120+
"local stream = conn:new_stream()\n"
121+
"local stream_space = stream.space.test\n"
122+
"\n"
123+
"-- Begin transaction over an iproto stream:\n"
124+
"stream:begin()\n"
125+
"space:replace({1})\n"
126+
"\n"
127+
"-- Empty select, the transaction was not committed.\n"
128+
"-- You can't see it from the requests that do not belong to the\n"
129+
"-- transaction.\n"
130+
"\n"
131+
"-- Select returns the previously inserted tuple,\n"
132+
"-- because this select belongs to the transaction:\n"
133+
"conn_space:select{}\n"
134+
"stream_space:select({})\n"
135+
"\n"
136+
"-- Commit transaction:\n"
137+
"stream:commit()\n"
138+
"\n"
139+
"-- Now this select also returns the tuple, because the transaction has been committed:\n"
140+
"conn_space:select{}"
141+
msgstr ""
142+
"local conn = net_box.connect(remote_server_addr)\n"
143+
"local conn_space = conn.space.test\n"
144+
"local stream = conn:new_stream()\n"
145+
"local stream_space = stream.space.test\n"
146+
"\n"
147+
"-- Начать транзакцию через поток iproto:\n"
148+
"stream:begin()\n"
149+
"space:replace({1})\n"
150+
"\n"
151+
"-- Пустой select, коммит транзакции не выполнен.\n"
152+
"-- Ее нельзя увидеть из запросов, не относящихся\n"
153+
"-- к транзакции.\n"
154+
"\n"
155+
"-- Метод select возвращает ранее вставленный кортеж,\n"
156+
"-- так как этот кортеж относится к транзакции:\n"
157+
"conn_space:select{}\n"
158+
"stream_space:select({})\n"
159+
"\n"
160+
"-- Коммит транзакции:\n"
161+
"stream:commit()\n"
162+
"\n"
163+
"-- Теперь и этот select возвращает кортеж, так как транзакция прошла коммит:\n"
164+
"conn_space:select{}"

0 commit comments

Comments
 (0)