-
Notifications
You must be signed in to change notification settings - Fork 43
Intro and explanation of Streams feature #2362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf2418b
Add draft
xuniq cffbc67
Update draft
xuniq 63291ba
Update draft
xuniq 456689b
Update draft
xuniq 8ffd0e5
Update draft
xuniq 0e56c12
Update draft
xuniq b168178
Update doc/book/box/atomic.rst
xuniq 9f82771
Update stream.rst
xuniq e60b4a4
Update draft after the review
xuniq b2750ea
Update translations
patiencedaur a9293f3
Update translations
maryartkey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. _box_stream: | ||
|
||
Streams and interactive transactions | ||
==================================== | ||
|
||
.. _box_stream-overview: | ||
|
||
Overview | ||
-------- | ||
|
||
Since :tarantool-release:`2.10.0-beta1`, iproto implements streams and interactive transactions. | ||
|
||
.. glossary:: | ||
|
||
Stream | ||
A stream supports multiplexing several transactions over one connection. | ||
All requests in the stream are executed strictly sequentially, | ||
which allows the implementation of | ||
:term:`interactive transactions <interactive transaction>`. | ||
|
||
Unlike a thread associated with multitasking and execution within a program, | ||
a stream transfers data via the protocol between a client and a server. | ||
|
||
.. glossary:: | ||
|
||
Interactive transaction | ||
An interactive transaction is a transaction that does not need to be sent in a single request. | ||
The ``begin``, ``commit``, and other TX statements can be sent and executed in different requests. | ||
|
||
.. _box_stream-features: | ||
|
||
New features | ||
------------ | ||
|
||
The primary purpose of :term:`streams <stream>` is to execute transactions via iproto. | ||
Every stream has its own identifier, which is unique within the connection. | ||
All requests with the same non-zero stream ID belong to the same stream. | ||
All requests in the stream are processed synchronously. | ||
The next request will not start executing until the previous one is completed. | ||
If a request's stream ID is ``0``, it does not belong to any stream and is processed in the old way. | ||
|
||
In :doc:`net.box </reference/reference_lua/net_box>`, a stream is an object above the connection that has the same methods | ||
but allows executing requests sequentially. | ||
The ID is generated on the client side automatically. | ||
If a user writes their own connector and wants to use streams, | ||
they must transmit the ``stream_id`` over the iproto protocol. | ||
|
||
.. _box_stream-interaction: | ||
|
||
Interaction between streams and transactions | ||
-------------------------------------------- | ||
|
||
As each stream can start a transaction, several transactions can be multiplexed over one connection. | ||
There are multiple ways to begin, commit, and roll back a transaction. | ||
One can do that using the appropriate stream methods---``call``, ``eval``, | ||
or ``execute``---with the SQL transaction syntax. Users can mix these methods. | ||
For example, one might start a transaction using ``stream:begin()`` | ||
and commit it with ``stream:call('box.commit')`` or ``stream:execute('COMMIT')``. | ||
All the requests between ``stream:begin()`` and ``stream:commit()`` are executed within the same transaction. | ||
If any request fails during the transaction, it will not affect the other requests in the transaction. | ||
If a disconnect occurs while there is an active transaction in the stream, | ||
that transaction will be rolled back if it hasn't been committed before the connection failure. | ||
xuniq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Example: | ||
|
||
.. code-block:: lua | ||
|
||
local conn = net_box.connect(remote_server_addr) | ||
local conn_space = conn.space.test | ||
local stream = conn:new_stream() | ||
local stream_space = stream.space.test | ||
|
||
-- Begin transaction over an iproto stream: | ||
stream:begin() | ||
space:replace({1}) | ||
|
||
-- Empty select, the transaction was not committed. | ||
-- You can't see it from the requests that do not belong to the | ||
-- transaction. | ||
|
||
-- Select returns the previously inserted tuple, | ||
-- because this select belongs to the transaction: | ||
conn_space:select{} | ||
stream_space:select({}) | ||
|
||
-- Commit transaction: | ||
stream:commit() | ||
|
||
-- Now this select also returns the tuple, because the transaction has been committed: | ||
conn_space:select{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне кажется, что в этой фразе 'transaction thread statements' должен быть заменен на 'запросы в рамках транзакции'. Хотя возможно это и есть соответствующий термин на английском.