From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 634A04696C2 for ; Wed, 13 May 2020 01:18:36 +0300 (MSK) From: Alexander Turenko Date: Wed, 13 May 2020 01:18:05 +0300 Message-Id: <59dfb8a35bff974f53943342fb08b1a32c71d0bd.1589321083.git.alexander.turenko@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 3/3] box: always reconfigure box at non-first box.cfg() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org From: Maria 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 . The patch fixes this issue making box.cfg behave consistently in both scenarios. Follow-up #4231 Co-developed-by: Alexander Turenko --- 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 ) +-- 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 () +-- 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