From: Vladimir Davydov via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: mechanik20051988 <mechanik20051988@tarantool.org> Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, mechanik20051988 <mechanik20.05.1988@gmail.com> Subject: Re: [Tarantool-patches] [PATCH v3 8/8] net.box: add interactive transaction support in net.box Date: Wed, 11 Aug 2021 15:47:07 +0300 [thread overview] Message-ID: <20210811124707.r6jompr4ekdjjbge@esperanza> (raw) In-Reply-To: <ac85e784d35d530a1dda81d83407d6dd21e7fdd7.1628671235.git.mechanik20051988@tarantool.org> On Wed, Aug 11, 2021 at 11:56:58AM +0300, mechanik20051988 wrote: > From: mechanik20051988 <mechanik20.05.1988@gmail.com> > > Implement `begin`, `commit` and `rollback` methods for stream object > in `net.box`, which allows to begin, commit and rollback transaction > accordingly. > > Closes #5860 > > @TarantoolBot document > Title: add interactive transaction support in net.box > Implement `begin`, `commit` and `rollback` methods for stream object > in `net.box`, which allows to begin, commit and rollback transaction > accordingly. Now there are multiple ways to begin, commit and rollback > transaction from `net.box`: using appropriate stream methods, using 'call` > or 'eval' methods or using `execute` method with sql transaction syntax. > User can mix these methods, for example, start transaction using > `stream:begin()`, and commit transaction using `stream:call('box.commit')` > or stream:execute('COMMIT'). > Simple example of using interactive transactions via iproto from net.box: > ```lua > stream = conn:new_stream() > space = stream.space.test > space_not_from_stream = conn.space.test > > stream:begin() > space:replace({1}) > -- return previously inserted tuple, because request > -- belongs to transaction. > space:select({}) > -- empty select, because select doesn't belongs to > -- transaction > space_not_from_stream:select({}) > stream:call('box.commit') > -- now transaction was commited, so all requests > -- returns tuple. > ``` > Different examples of using streams you can find in > gh-5860-implement-streams-in-iproto.test.lua > --- > .../gh-5860-implement-streams-in-iproto.md | 26 + > src/box/lua/net_box.c | 49 +- > src/box/lua/net_box.lua | 35 +- > test/box/stream.result | 3558 +++++++++++++++-- > test/box/stream.test.lua | 1202 ++++++ Please add a separate test file for this (net.box.transactions or something like this). > 5 files changed, 4554 insertions(+), 316 deletions(-) > create mode 100644 changelogs/unreleased/gh-5860-implement-streams-in-iproto.md > > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua > index 3dffc245f..745a8c0f5 100644 > --- a/src/box/lua/net_box.lua > +++ b/src/box/lua/net_box.lua > @@ -51,8 +51,11 @@ local M_GET = 13 > local M_MIN = 14 > local M_MAX = 15 > local M_COUNT = 16 > +local M_BEGIN = 17 > +local M_COMMIT = 18 > +local M_ROLLBACK = 19 > -- Injects raw data into connection. Used by console and tests. > -local M_INJECT = 17 > +local M_INJECT = 20 > > -- utility tables > local is_final_state = {closed = 1, error = 1} > @@ -754,11 +757,38 @@ local function new_stream(stream) > return stream._conn:new_stream() > end > > +local function begin(stream, opts) stream_begin > + check_remote_arg(stream, 'begin') > + local res = stream:_request(M_BEGIN, opts, nil, stream._stream_id) > + if opts and opts.is_async then > + return res > + end > +end > + > +local function commit(stream, opts) stream_commit > + check_remote_arg(stream, 'commit') > + local res = stream:_request(M_COMMIT, opts, nil, stream._stream_id) > + if opts and opts.is_async then > + return res > + end > +end > + > +local function rollback(stream, opts) stream_rollback > + check_remote_arg(stream, 'rollback') > + local res = stream:_request(M_ROLLBACK, opts, nil, stream._stream_id) > + if opts and opts.is_async then > + return res > + end > +end > + > function remote_methods:new_stream() > check_remote_arg(self, 'new_stream') > self._last_stream_id = self._last_stream_id + 1 > local stream = setmetatable({ > new_stream = new_stream, > + begin = begin, > + commit = commit, > + rollback = rollback, > _stream_id = self._last_stream_id, > space = setmetatable({ > _stream_space_cache = {},
prev parent reply other threads:[~2021-08-11 12:47 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-11 8:56 [Tarantool-patches] [PATCH v3 0/8] implement iproto streams mechanik20051988 via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 1/8] xrow: remove unused call_request::header mechanik20051988 via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 2/8] iproto: clear request::header for client requests mechanik20051988 via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 3/8] iproto: implement stream id in binary iproto protocol mechanik20051988 via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 4/8] salad: fix segfault in case when mhash table allocation failure mechanik20051988 via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 5/8] iproto: implement streams in iproto mechanik20051988 via Tarantool-patches 2021-08-11 11:30 ` Vladimir Davydov via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 6/8] net.box: add stream support to net.box mechanik20051988 via Tarantool-patches 2021-08-11 11:52 ` Vladimir Davydov via Tarantool-patches 2021-08-11 12:09 ` Vladimir Davydov via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 7/8] iproto: implement interactive transactions over iproto streams mechanik20051988 via Tarantool-patches 2021-08-11 12:39 ` Vladimir Davydov via Tarantool-patches 2021-08-11 8:56 ` [Tarantool-patches] [PATCH v3 8/8] net.box: add interactive transaction support in net.box mechanik20051988 via Tarantool-patches 2021-08-11 12:47 ` Vladimir Davydov via Tarantool-patches [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210811124707.r6jompr4ekdjjbge@esperanza \ --to=tarantool-patches@dev.tarantool.org \ --cc=mechanik20.05.1988@gmail.com \ --cc=mechanik20051988@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v3 8/8] net.box: add interactive transaction support in net.box' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox