Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 3/3] box: always reconfigure box at non-first box.cfg()
Date: Wed, 13 May 2020 01:18:05 +0300	[thread overview]
Message-ID: <59dfb8a35bff974f53943342fb08b1a32c71d0bd.1589321083.git.alexander.turenko@tarantool.org> (raw)
In-Reply-To: <cover.1589321083.git.alexander.turenko@tarantool.org>

From: Maria <maria.khaydich@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@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

  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 ` [Tarantool-patches] [PATCH 2/3] box: always wait box loading " Alexander Turenko
2020-05-22 11:08   ` lvasiliev
2020-06-03 23:12   ` Igor Munkin
2020-05-12 22:18 ` Alexander Turenko [this message]
2020-05-22  7:02   ` [Tarantool-patches] [PATCH 3/3] box: always reconfigure box at non-first box.cfg() 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=59dfb8a35bff974f53943342fb08b1a32c71d0bd.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 3/3] box: always reconfigure box at non-first box.cfg()' \
    /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