From: Aleksandr Lyapunov <alyapunov@tarantool.org> To: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v4 11/12] test: move txn_proxy.lua to box/lua Date: Tue, 8 Sep 2020 13:22:11 +0300 [thread overview] Message-ID: <1599560532-27089-12-git-send-email-alyapunov@tarantool.org> (raw) In-Reply-To: <1599560532-27089-1-git-send-email-alyapunov@tarantool.org> txn_proxy is a special utility for transaction tests. Formerly it was used only for vinyl tests and thus was placed in vinyl folder. Now the time has come to test memtx transactions and the utility must be placed amongst other utils - in box/lua. Needed for #4897 --- test/box/lua/txn_proxy.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++ test/vinyl/suite.ini | 2 +- test/vinyl/txn_proxy.lua | 54 ---------------------------------------------- 3 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 test/box/lua/txn_proxy.lua delete mode 100644 test/vinyl/txn_proxy.lua diff --git a/test/box/lua/txn_proxy.lua b/test/box/lua/txn_proxy.lua new file mode 100644 index 0000000..7a4d0b8 --- /dev/null +++ b/test/box/lua/txn_proxy.lua @@ -0,0 +1,54 @@ +-- A fiber can't use multiple transactions simultaneously; +-- i.e. [fiber] --? [transaction] in UML parlor. +-- +-- This module provides a simple transaction proxy facility +-- to control multiple transactions at once. A proxy executes +-- statements in a worker fiber in order to overcome +-- "one transaction per fiber" limitation. +-- +-- Ex: +-- proxy = require('txn_proxy').new() +-- proxy:begin() +-- proxy('box.space.test:replace{1, 42}') +-- proxy:commit() -- or proxy:rollback() + +local ffi = require('ffi') +local yaml = require('yaml') +local fiber = require('fiber') +local console = require('console') + +local array_mt = { __serialize = 'array' } + +local mt = { + __call = function(self, code_str) + self.c1:put(code_str) + local res = yaml.decode(self.c2:get()) + return type(res) == 'table' and setmetatable(res, array_mt) or res + end, + __index = { + begin = function(self) return self('box.begin()') end, + commit = function(self) return self('box.commit()') end, + rollback = function(self) return self('box.rollback()') end, + close = function(self) self.c1:close(); self.c2:close() end + } +} + +local function fiber_main(c1, c2) + local code_str = c1:get() + if code_str then + c2:put(console.eval(code_str)) + return fiber_main(c1, c2) -- tail call + end +end + +local function new_txn_proxy() + local c1, c2 = fiber.channel(), fiber.channel() + local function on_gc() c1:close(); c2:close() end + fiber.create(fiber_main, c1, c2) + return setmetatable({ + c1 = c1, c2 = c2, + __gc = ffi.gc(ffi.new('char[1]'), on_gc) + }, mt) +end + +return { new = new_txn_proxy } diff --git a/test/vinyl/suite.ini b/test/vinyl/suite.ini index 3e11b08..c6cb89a 100644 --- a/test/vinyl/suite.ini +++ b/test/vinyl/suite.ini @@ -4,7 +4,7 @@ description = vinyl integration tests script = vinyl.lua release_disabled = errinj.test.lua errinj_ddl.test.lua errinj_gc.test.lua errinj_stat.test.lua errinj_tx.test.lua errinj_vylog.test.lua partial_dump.test.lua quota_timeout.test.lua recovery_quota.test.lua replica_rejoin.test.lua gh-4864-stmt-alloc-fail-compact.test.lua gh-4805-open-run-err-recovery.test.lua gh-4821-ddl-during-throttled-dump.test.lua gh-3395-read-prepared-uncommitted.test.lua config = suite.cfg -lua_libs = suite.lua stress.lua large.lua txn_proxy.lua ../box/lua/utils.lua +lua_libs = suite.lua stress.lua large.lua ../box/lua/txn_proxy.lua ../box/lua/utils.lua use_unix_sockets = True use_unix_sockets_iproto = True long_run = stress.test.lua large.test.lua write_iterator_rand.test.lua dump_stress.test.lua select_consistency.test.lua throttle.test.lua diff --git a/test/vinyl/txn_proxy.lua b/test/vinyl/txn_proxy.lua deleted file mode 100644 index 7a4d0b8..0000000 --- a/test/vinyl/txn_proxy.lua +++ /dev/null @@ -1,54 +0,0 @@ --- A fiber can't use multiple transactions simultaneously; --- i.e. [fiber] --? [transaction] in UML parlor. --- --- This module provides a simple transaction proxy facility --- to control multiple transactions at once. A proxy executes --- statements in a worker fiber in order to overcome --- "one transaction per fiber" limitation. --- --- Ex: --- proxy = require('txn_proxy').new() --- proxy:begin() --- proxy('box.space.test:replace{1, 42}') --- proxy:commit() -- or proxy:rollback() - -local ffi = require('ffi') -local yaml = require('yaml') -local fiber = require('fiber') -local console = require('console') - -local array_mt = { __serialize = 'array' } - -local mt = { - __call = function(self, code_str) - self.c1:put(code_str) - local res = yaml.decode(self.c2:get()) - return type(res) == 'table' and setmetatable(res, array_mt) or res - end, - __index = { - begin = function(self) return self('box.begin()') end, - commit = function(self) return self('box.commit()') end, - rollback = function(self) return self('box.rollback()') end, - close = function(self) self.c1:close(); self.c2:close() end - } -} - -local function fiber_main(c1, c2) - local code_str = c1:get() - if code_str then - c2:put(console.eval(code_str)) - return fiber_main(c1, c2) -- tail call - end -end - -local function new_txn_proxy() - local c1, c2 = fiber.channel(), fiber.channel() - local function on_gc() c1:close(); c2:close() end - fiber.create(fiber_main, c1, c2) - return setmetatable({ - c1 = c1, c2 = c2, - __gc = ffi.gc(ffi.new('char[1]'), on_gc) - }, mt) -end - -return { new = new_txn_proxy } -- 2.7.4
next prev parent reply other threads:[~2020-09-08 10:22 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-08 10:22 [Tarantool-patches] [PATCH v4 00/12] Transaction engine for memtx engine Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 01/12] vinyl: rename tx_manager -> vy_tx_manager Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 02/12] txm: add TX status Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 03/12] txm: save does_require_old_tuple flag in txn_stmt Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 04/12] txm: introduce prepare sequence number Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 05/12] txm: introduce memtx tx manager Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 06/12] txm: introduce conflict tracker Aleksandr Lyapunov 2020-09-14 16:36 ` Nikita Pettik 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 07/12] txm: introduce memtx_story Aleksandr Lyapunov 2020-09-15 14:33 ` Nikita Pettik 2020-09-22 17:51 ` Aleksandr Lyapunov 2020-09-23 10:25 ` Nikita Pettik 2020-09-23 11:09 ` Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 08/12] txm: introduce snapshot cleaner Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 09/12] txm: clarify all fetched tuples Aleksandr Lyapunov 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 10/12] txm: use new tx manager in memtx Aleksandr Lyapunov 2020-09-15 17:59 ` Nikita Pettik 2020-09-22 17:53 ` Aleksandr Lyapunov 2020-09-23 10:26 ` Nikita Pettik 2020-09-08 10:22 ` Aleksandr Lyapunov [this message] 2020-09-08 10:22 ` [Tarantool-patches] [PATCH v4 12/12] txm: add a test Aleksandr Lyapunov 2020-09-15 18:05 ` Nikita Pettik 2020-09-22 17:58 ` Aleksandr Lyapunov 2020-09-23 11:07 ` Nikita Pettik 2020-09-23 11:12 ` Aleksandr Lyapunov 2020-09-23 12:18 ` [Tarantool-patches] [PATCH v4 00/12] Transaction engine for memtx engine Kirill Yukhin
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=1599560532-27089-12-git-send-email-alyapunov@tarantool.org \ --to=alyapunov@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH v4 11/12] test: move txn_proxy.lua to box/lua' \ /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