From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id BA6EC7F625; Fri, 6 Aug 2021 17:04:58 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BA6EC7F625 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628258698; bh=RCaDH3Tu/KxZZjLY+jMrqXem8ROn0HfPRBAdPKB9zqE=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Co1NrcX6Kapkx9l/3bJwvvLmXeCWQMELgXwcWEEGBv7PgXMw5hTYelCPG53QasCMm ksInt9XyR/HETA7r0d/7qhvass9MZ0KMUJPrOzDVEzuuZZ3p+JlVQCv2SzJ9BElfYj NReJSeup+O4c+plZgIEZWlf5lWsohPlPJMLCxKP4= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id E05E56CAD4 for ; Fri, 6 Aug 2021 17:04:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E05E56CAD4 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mC0T1-0001P9-OP; Fri, 06 Aug 2021 17:04:56 +0300 Date: Fri, 6 Aug 2021 17:04:54 +0300 To: mechanik20051988 Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org, mechanik20051988 Message-ID: <20210806140454.ccxkvpvysjhb72ne@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F538085040C59667AE2454B891C80537E49163BBF4C93A6C0146D0487A2354BF82459E5069 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DECE8D0A5E25C0FCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637F9CBC1404CDFA5A08638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8E13C4DB27D2A7274C12D053FFF0CB83B117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC60CDF180582EB8FBA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735204B6963042765DA4BF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6A45692FFBBD75A6A089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: 0D63561A33F958A51C4F69D8FF6CB5B690BDF0BA7F9F103DF85738374A2721A2D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3483E1FCD56FEA62E60E5EC292D1145E4D24036A2CDD60C3572463FC4DB7801DC74CD50858A9B79E0E1D7E09C32AA3244C094872880109A92E90F85F979A3AD62C51E887DA02A9F7BF83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojFhlvmGwdUwQD8X5jj8uDww== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DA530CFA8C36F9EE8016370F215EB3CBB274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 7/7] net.box: add interactive transaction support in net.box X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Thu, Aug 05, 2021 at 09:17:45PM +0300, mechanik20051988 wrote: > From: mechanik20051988 > > 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:stream() 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 | 28 + > src/box/lua/net_box.c | 51 +- > src/box/lua/net_box.lua | 50 +- > test/box/stream.result | 3036 +++++++++++++++++ > test/box/stream.test.lua | 1201 +++++++ > 5 files changed, 4358 insertions(+), 8 deletions(-) > create mode 100644 changelogs/unreleased/gh-5860-implement-streams-in-iproto.md > > diff --git a/changelogs/unreleased/gh-5860-implement-streams-in-iproto.md b/changelogs/unreleased/gh-5860-implement-streams-in-iproto.md > new file mode 100644 > index 000000000..d0f1359dd > --- /dev/null > +++ b/changelogs/unreleased/gh-5860-implement-streams-in-iproto.md > @@ -0,0 +1,28 @@ > +## feature/core > + > +* Streams and interactive transactions over streams are implemented > + in iproto. Stream is associated with it's ID, which is unique within > + one connection. All requests with same not zero stream ID belongs to > + the same stream. All requests in stream processed synchronously. The > + execution of the next request will not start until the previous one > + is completed. If request has zero stream ID it does not belong to stream > + and is processed in the old way. > + In `net.box`, stream is an object above connection that has the same > + methods, but allows to execute requests sequentially. ID is generated > + on the client side in two ways: automatically or manually. User can There's no manual id generation anymore. Please update. > + choose any of two methods, but can not mix them. If user writes his > + own connector and wants to use streams, he must transmit stream_id over > + the iproto protocol. > + The main purpose of streams is transactions via iproto. Each stream > + can start its own transaction, so they allows multiplexing several > + transactions over one connection. There are multiple ways to begin, > + commit and rollback transaction: 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'). > + If any request fails during the transaction, it will not affect the other > + requests in the transaction. If disconnect occurs when there is some active > + transaction in stream, this transaction will be rollbacked, if it does not > + have time to commit before this moment. > + > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua > index bf6a89e15..199d78127 100644 > --- a/src/box/lua/net_box.lua > +++ b/src/box/lua/net_box.lua > @@ -70,8 +70,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 > > ffi.cdef[[ > struct error * > @@ -1167,16 +1170,52 @@ local function check_eval_args(args) > end > end > > +local function nothing_or_data(value) > + if value ~= nil then > + return value > + end > +end > + > function stream_methods:new_stream() > check_remote_arg(self, 'stream') > box.error(E_PROC_LUA, "Unsupported for stream"); > end > > +function stream_methods:begin(opts) > + check_remote_arg(self, 'begin') > + local res = self:_request(M_BEGIN, opts, nil, self._stream_id) > + if type(res) ~= 'table' or opts and opts.is_async then > + return nothing_or_data(res) > + end > + return unpack(res) > +end > + > +function stream_methods:commit(opts) > + check_remote_arg(self, 'commit') > + local res = self:_request(M_COMMIT, opts, nil, self._stream_id) > + if type(res) ~= 'table' or opts and opts.is_async then > + return nothing_or_data(res) > + end > + return unpack(res) > +end > + > +function stream_methods:rollback(opts) > + check_remote_arg(self, 'rollback') > + local res = self:_request(M_ROLLBACK, opts, nil, self._stream_id) > + if type(res) ~= 'table' or opts and opts.is_async then > + return nothing_or_data(res) > + end > + return unpack(res) > +end > + In the sync mode BEGIN/COMMIT/ROLLBACK return either error, which will be raise in _request, or nothing. In the async mode they return a future so you don't need unpack() or nothing_or_data(). function stream_methods:rollback(opts) check_remote_arg(self, 'rollback') local res = self:_request(M_ROLLBACK, opts, nil, self._stream_id) if opts and opts.is_async then return res end end