Skip to content

Commit

Permalink
box: drop 'execute' field from uninitialized box
Browse files Browse the repository at this point in the history
Prior to this patch, it was possible to call box.execute() before box
was initialized, i.e. before calling box.cfg(). This, however, caused
box.cfg() to be called automatically, which could be problematic as some
parameters could not be changed after box.cfg() was called. After this
patch, box.execute() will only be available when the box has been
initialized.

Closes tarantool#4726

@TarantoolBot document
Title: box.execute() now available only after initialization of box

Previously, it was possible to call box.execute() before the box was
configured, in which case the box was configured automatically, which
could lead to problems with box parameters. Now box.execute() can only
be called after the box has been properly configured.

It is also forbidden to set language to SQL in a console with an
unconfigured box.
  • Loading branch information
ImeevMA authored and locker committed Oct 13, 2022
1 parent 6e45042 commit d960476
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 143 deletions.
4 changes: 4 additions & 0 deletions changelogs/unreleased/gh-4726-execute-field-in-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## bugfix/box

* **[Breaking change]** Now the "execute" field is not available until box is
configured (gh-4726).
3 changes: 3 additions & 0 deletions src/box/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ local function set_language(storage, value)
local msg = 'Invalid language "%s", supported languages: lua and sql.'
return error(msg:format(value))
end
if value == 'sql' and rawget(box, 'execute') == nil then
return error("Unable to set language to 'sql' with unconfigured box")
end
storage.language = value
return true
end
Expand Down
37 changes: 0 additions & 37 deletions src/box/lua/load_cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -990,43 +990,6 @@ local function load_cfg(cfg)
end
box.cfg = locked(load_cfg)

--
-- This makes possible do box.execute without calling box.cfg
-- manually. The load_cfg() call overwrites box.execute, see
-- <box_configured> variable.
--
-- box.execute is <box_load_and_execute> when box is not loaded,
-- <lbox_execute> otherwise. <box_load_and_execute> loads box and
-- calls <lbox_execute>.
--
local box_load_and_execute
box_load_and_execute = function(...)
-- Configure box if it is not configured, no-op otherwise (not
-- a reconfiguration).
--
-- We should check whether box is configured, because a user
-- may save <box_load_and_execute> function before box loading
-- and call it afterwards.
if not box_is_configured then
locked(function()
-- Re-check, because after releasing of the lock the
-- box state may be changed. We should call load_cfg()
-- only once.
if not box_is_configured then
load_cfg()
end
end)()
end

-- At this point box should be configured and box.execute()
-- function should be replaced with lbox_execute().
assert(type(box.cfg) ~= 'function')
assert(box.execute ~= box_load_and_execute)

return box.execute(...)
end
box.execute = box_load_and_execute

--
-- Parse TT_* environment variable that corresponds to given
-- option.
Expand Down
15 changes: 15 additions & 0 deletions test/box-luatest/gh_4726_box_execute_before_cfg_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local t = require('luatest')
local g = t.group()

g.test_box_execute_before_box_cfg = function()
t.assert_equals(rawget(box, 'execute'), nil)
end

g.test_sql_language_in_unconfigured_console = function()
local res = [[
---
- error: Unable to set language to 'sql' with unconfigured box
...
]]
t.assert_equals(require('console').eval('\\s l sql'), res)
end
37 changes: 0 additions & 37 deletions test/box-tap/gh-4231-box-execute-idempotence.test.lua

This file was deleted.

69 changes: 0 additions & 69 deletions test/box-tap/gh-4231-box-execute-locking.test.lua

This file was deleted.

0 comments on commit d960476

Please sign in to comment.