From: Alexander Turenko <alexander.turenko@tarantool.org> To: Igor Munkin <imun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH 2/3] box: always wait box loading in box.execute() Date: Wed, 13 May 2020 01:18:04 +0300 [thread overview] Message-ID: <3c0d131898ba3b78c2f36fa82873b78dbf707df6.1589321083.git.alexander.turenko@tarantool.org> (raw) In-Reply-To: <cover.1589321083.git.alexander.turenko@tarantool.org> <box_load_and_execute> checks whether box is configured with appropriate locking and configures it when necessary. However it is not so for <lbox_execute>. We should replace the former with the latter only when box is fully loaded. Follow-up #4231 --- src/box/lua/load_cfg.lua | 20 ++++++++++++--- .../gh-4231-box-execute-locking.test.lua | 25 ++++++++++++++++++- test/box-tap/suite.cfg | 6 +++++ test/box-tap/suite.ini | 1 + 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 test/box-tap/suite.cfg diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index 0b4a14377..9a7b57cd3 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -538,6 +538,11 @@ local box_cfg_guard_whitelist = { NULL = true; }; +-- List of box members that requires full box loading. +local box_restore_after_full_load_list = { + execute = true, +} + local box = require('box') -- Move all box members except the whitelisted to box_configured local box_configured = {} @@ -585,12 +590,13 @@ local function load_cfg(cfg) -- It also would be counter-intuitive to receive an error from -- box.cfg({<...>}), but find that box is actually configured. - -- Restore box members after initial configuration + -- Restore box members after initial configuration. for k, v in pairs(box_configured) do - box[k] = v + if not box_restore_after_full_load_list[k] then + box[k] = v + end end setmetatable(box, nil) - box_configured = nil box.cfg = setmetatable(cfg, { __newindex = function(table, index) @@ -624,6 +630,14 @@ local function load_cfg(cfg) box.schema.upgrade{auto = true} end + -- Restore box members that requires full box loading. + for k, v in pairs(box_configured) do + if box_restore_after_full_load_list[k] then + box[k] = v + end + end + box_configured = nil + box_is_configured = true end box.cfg = locked(load_cfg) diff --git a/test/box-tap/gh-4231-box-execute-locking.test.lua b/test/box-tap/gh-4231-box-execute-locking.test.lua index 52c60f764..f3df2eb0f 100755 --- a/test/box-tap/gh-4231-box-execute-locking.test.lua +++ b/test/box-tap/gh-4231-box-execute-locking.test.lua @@ -4,20 +4,43 @@ -- before box will be loaded) in several fibers in parallel and -- ensure that it returns correct results (i.e. that the function -- waits until box will be fully configured). +-- +-- The test can be configured to call box.execute() from a fiber +-- instead of box_load_and_execute(): it can be done either via +-- test-run using confguration feature or using an argument when +-- the test is invoked directly. local fiber = require('fiber') local tap = require('tap') +-- Determine configuration. +local conf = 'box_load_and_execute' +local ok, test_run = pcall(require, 'test_run') +if ok then + test_run = test_run.new() + conf = test_run:get_cfg('conf') +elseif #arg >= 1 then + conf = arg[1] +end +assert(conf == 'box_load_and_execute' or + conf == 'box.execute') + local box_load_and_execute = box.execute local fiber_count = 10 local results = fiber.channel(fiber_count) local function select_from_vindex() - local res = box_load_and_execute('SELECT * FROM "_vindex"') + local box_execute_func = + conf == 'box_load_and_execute' and box_load_and_execute or + conf == 'box.execute' and box.execute or + function() return false end + + local res = box_execute_func('SELECT * FROM "_vindex"') results:put(res) end local test = tap.test('gh-4231-box-execute-locking') +test:diag('configuration: %s', conf) test:plan(fiber_count) diff --git a/test/box-tap/suite.cfg b/test/box-tap/suite.cfg new file mode 100644 index 000000000..91a721d47 --- /dev/null +++ b/test/box-tap/suite.cfg @@ -0,0 +1,6 @@ +{ + "gh-4231-box-execute-locking.test.lua": { + "box_load_and_execute": {"conf": "box_load_and_execute"}, + "box.execute": {"conf": "box.execute"} + } +} diff --git a/test/box-tap/suite.ini b/test/box-tap/suite.ini index 8d9e32d3f..5b764593a 100644 --- a/test/box-tap/suite.ini +++ b/test/box-tap/suite.ini @@ -5,3 +5,4 @@ is_parallel = True pretest_clean = True fragile = cfg.test.lua ; gh-4344 key_def.test.lua ; gh-4252 +config = suite.cfg -- 2.25.0
next prev parent reply other threads:[~2020-05-12 22:18 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-12 22:18 [Tarantool-patches] [PATCH 0/3] box.execute() and box.cfg() idempotence and locking Alexander Turenko 2020-05-12 22:18 ` [Tarantool-patches] [PATCH 1/3] box: check whether box is loaded in box.execute() Alexander Turenko 2020-05-22 7:31 ` lvasiliev 2020-06-03 21:58 ` Igor Munkin 2020-06-08 18:58 ` Alexander Turenko 2020-06-11 17:43 ` Igor Munkin 2020-05-12 22:18 ` Alexander Turenko [this message] 2020-05-22 11:08 ` [Tarantool-patches] [PATCH 2/3] box: always wait box loading " lvasiliev 2020-06-03 23:12 ` Igor Munkin 2020-05-12 22:18 ` [Tarantool-patches] [PATCH 3/3] box: always reconfigure box at non-first box.cfg() Alexander Turenko 2020-05-22 7:02 ` lvasiliev 2020-06-03 22:41 ` Igor Munkin 2020-06-03 23:22 ` Igor Munkin 2020-06-08 18:59 ` Alexander Turenko 2020-06-17 22:26 ` Vladislav Shpilevoy 2020-06-18 8:41 ` Alexander Turenko 2020-06-18 22:23 ` Vladislav Shpilevoy 2020-05-22 7:06 ` [Tarantool-patches] [PATCH 0/3] box.execute() and box.cfg() idempotence and locking lvasiliev 2020-06-08 18:59 ` Alexander Turenko 2020-06-17 22:30 ` Vladislav Shpilevoy 2020-06-22 10:11 ` Kirill Yukhin 2020-06-23 23:55 ` Alexander Turenko
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=3c0d131898ba3b78c2f36fa82873b78dbf707df6.1589321083.git.alexander.turenko@tarantool.org \ --to=alexander.turenko@tarantool.org \ --cc=imun@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 2/3] box: always wait box loading in box.execute()' \ /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