[Tarantool-patches] [PATCH 3/3] box: always reconfigure box at non-first box.cfg()

Alexander Turenko alexander.turenko at tarantool.org
Wed May 13 01:18:05 MSK 2020


From: Maria <maria.khaydich at tarantool.org>

Calling box.cfg{} more than once does not normally cause any errors
(even though it might not have any effect). In contrast, assigning
it to some variable and then using it after the box was configured
caused an error since the method was overwritten by the initial call
of <load_cfg>.

The patch fixes this issue making box.cfg behave consistently in both
scenarios.

Follow-up #4231

Co-developed-by: Alexander Turenko <alexander.turenko at tarantool.org>
---
 src/box/lua/load_cfg.lua                      |  8 +++++
 .../gh-4231-box-cfg-idempotence.test.lua      | 34 +++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100755 test/box-tap/gh-4231-box-cfg-idempotence.test.lua

diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 9a7b57cd3..014379826 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -571,6 +571,14 @@ setmetatable(box, {
 local box_is_configured = false
 
 local function load_cfg(cfg)
+    -- A user may save box.cfg (this function) before box loading
+    -- and call it afterwards. We should reconfigure box in the
+    -- case.
+    if box_is_configured then
+        reload_cfg(box.cfg, cfg)
+        return
+    end
+
     cfg = upgrade_cfg(cfg, translate_cfg)
     cfg = prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg)
     apply_default_cfg(cfg, default_cfg);
diff --git a/test/box-tap/gh-4231-box-cfg-idempotence.test.lua b/test/box-tap/gh-4231-box-cfg-idempotence.test.lua
new file mode 100755
index 000000000..4f3ba68a6
--- /dev/null
+++ b/test/box-tap/gh-4231-box-cfg-idempotence.test.lua
@@ -0,0 +1,34 @@
+#!/usr/bin/env tarantool
+
+--
+-- gh-4231: box.cfg is another function (so called <load_cfg>)
+-- before box is loaded. Usually a user calls box.cfg({<...>}),
+-- it configures box and replaces box.cfg implementation to one
+-- that performs box reconfiguration: so further calls to
+-- box.cfg({<...>}) reconfigures box.
+--
+-- However it is possible to save box.cfg value (<load_cfg>)
+-- before box loading and call it after box loading: the behaviour
+-- should be the same as for box.cfg call: box should be
+-- reconfigured.
+--
+
+local tap = require('tap')
+local test = tap.test('gh-4231-box-cfg-idempotence')
+test:plan(4)
+
+local load_cfg = box.cfg
+
+box.cfg{}
+
+-- This call should be successful and should reinitialize box.
+local ok, res = pcall(load_cfg, {read_only = true})
+test:ok(ok, 'verify load_cfg after box.cfg() call', {err = res})
+test:is(box.cfg.read_only, true, 'verify that load_cfg reconfigures box')
+
+-- Just in case: verify usual box.cfg() after load_cfg().
+local ok, res = pcall(box.cfg, {read_only = false})
+test:ok(ok, 'verify box.cfg() after load_cfg()', {err = res})
+test:is(box.cfg.read_only, false, 'verify that box.cfg() reconfigures box')
+
+os.exit(test:check() and 0 or 1)
-- 
2.25.0



More information about the Tarantool-patches mailing list