Skip to content
Snippets Groups Projects
Commit e8d5515a authored by Alexander Turenko's avatar Alexander Turenko Committed by Kirill Yukhin
Browse files

box: always wait box loading in box.execute()

<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
parent 859df3a7
No related branches found
No related tags found
No related merge requests found
......@@ -570,6 +570,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 = {}
......@@ -618,12 +623,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)
......@@ -658,6 +664,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)
......
......@@ -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)
......
{
"gh-4231-box-execute-locking.test.lua": {
"box_load_and_execute": {"conf": "box_load_and_execute"},
"box.execute": {"conf": "box.execute"}
}
}
......@@ -6,3 +6,4 @@ pretest_clean = True
use_unix_sockets_iproto = True
fragile = cfg.test.lua ; gh-4344
key_def.test.lua ; gh-4252
config = suite.cfg
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment