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 762BE6EC40; Wed, 11 Aug 2021 15:47:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 762BE6EC40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628686031; bh=q/mw8ZFcwpvSAEOTfpyUMlyPxJOts72oodpsdl0qDTQ=; 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=nJCE7CHRws5iGu3NPJe9dZ4Wvt4EMHCRoiWrQkjDwo2ux+adBYvGDE9Me4++dHhck HBY+1Vhy+K2ftbynkAf9Sme8AeW/xxPnQTzzXWLKiEOwD4z+6NfnUlyKapF5XLs009 rzi8GVFqqUHugS5TRvsvSJJXH7R/e5eNoSEPeOCg= 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 1DF4B6EC40 for ; Wed, 11 Aug 2021 15:47:10 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1DF4B6EC40 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mDndV-0005IQ-4P; Wed, 11 Aug 2021 15:47:09 +0300 Date: Wed, 11 Aug 2021 15:47:07 +0300 To: mechanik20051988 Cc: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org, mechanik20051988 Message-ID: <20210811124707.r6jompr4ekdjjbge@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: 4F1203BC0FB41BD92087353F0EC44DD9BCE6B93DE0C6C3914462CDB1732D383C182A05F53808504038E6156A67CB6DA6CD08805F8FDD2AFC03F131565FBA37D12079501F77285893 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79145AB6E9E75F07EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EF59B520676799BC8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D89CEE412054C6A3CE5CC6A2DE6B47A4A0117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCECADA55FE5B58BB7A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209647ADFADE5905B1F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDCE939D40DBB93CA75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A5BAE95C80E617E2078DF43AB6E998CF277B6354D828F99DDBD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA753177526CD55AFC11410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340297C696F996E38426073274ABB7DC0D6CCA547003E542E30401310CB5E147ADFDB9DA6C28D09E9B1D7E09C32AA3244C12F8980BB6C7AE811E1B09C118D04BFD51E887DA02A9F7BF83B48618A63566E0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj6qlzQV0oSZNm96WeEYfb6Q== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DA416F971494F7BFDEB9A576530B8AFA2274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v3 8/8] 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 Wed, Aug 11, 2021 at 11:56:58AM +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: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 = {},