Tarantool development patches archive
 help / color / mirror / Atom feed
From: Igor Munkin <imun@tarantool.org>
To: Maria Khaydich <maria.khaydich@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org,
	Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH] box: make box.execute() immutable
Date: Wed, 25 Dec 2019 04:30:38 +0300	[thread overview]
Message-ID: <20191225013038.GC31304@tarantool.org> (raw)
In-Reply-To: <1577201550.829136486@f483.i.mail.ru>

Masha,

Thanks for the patch! It LGTM in general, but please consider a couple
polishing-aimed comments below.

On 24.12.19, Maria Khaydich wrote:
>    Igor, thank you for the review!
>    Proposed fixes are done:
> 

At first, please adjust the commit message subject considering our
contribution guide[1]. I see the component prefix is missing.

> 
>    Using box.execute method before explicitly configuring box
>    automatically invoked box.cfg nonetheless. Any further calls
>    to box.cfg caused its reconfiguration which then led to an
>    error when trying to use execute method again.
> 
>    The patch introduces a fix making box.execute method immutable.
> 
>    Closes #4231
>    ---
>    Issue:
>    https://github.com/tarantool/tarantool/issues/4231
>    Branch:
>    https://github.com/tarantool/tarantool/compare/eljashm/gh-4231-box.exec
>    ute-immutable-function
>     src/box/lua/load_cfg.lua                      | 15 +++++++++++-
>     .../gh-4231_immutable_box.execute.test.lua    | 24 +++++++++++++++++++
>     2 files changed, 38 insertions(+), 1 deletion(-)
>     create mode 100644 test/box-tap/gh-4231_immutable_box.execute.test.lua
>    diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
>    index e7f62cf4e..ad416e578 100644
>    --- a/src/box/lua/load_cfg.lua
>    +++ b/src/box/lua/load_cfg.lua
>    @@ -481,10 +481,14 @@ setmetatable(box, {
>          end
>     })
> 
>    +-- Flag needed to keep immutable functions after box reconfiguration
>    +local box_loaded = false
>    +
>     local function load_cfg(cfg)
>         cfg = upgrade_cfg(cfg, translate_cfg)
>         cfg = prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg)
>         apply_default_cfg(cfg, default_cfg);
>    +    box_loaded = true
>         -- Save new box.cfg
>         box.cfg = cfg
>         if not pcall(private.cfg_check)  then
>    @@ -528,7 +532,16 @@ box.cfg = locked(load_cfg)
>     -- metatable.
>     --
>     function box.execute(...)
>    -    load_cfg()
>    +    --
>    +    -- Calling box.execute before explicitly configuring box led to
>    +    -- automatic box.cfg invocation nonetheless. Following explicit
>    +    -- attempts to configure box led to its reconfiguratin and as a

Typo: s/reconfiguratin/reconfiguration/.

>    +    -- result - to an error when trying to use execute method again.
>    +    -- The check makes sure box.execute is an immutable function.

There is a trailing whitespace within this comment (I pulled your branch
and checked it). Please adjust it.

>    +    --
>    +    if not box_loaded then
>    +        load_cfg()
>    +    end
>         return box.execute(...)
>     end
> 
>    diff     --git    a/test/box-tap/gh-4231_immutable_box.execute.test.lua
>    b/test/box-tap/gh-4231_immutable_box.execute.test.lua
>    new file mode 100644
>    index 000000000..e2469630e
>    --- /dev/null
>    +++ b/test/box-tap/gh-4231_immutable_box.execute.test.lua

As Nikita mentioned before (and we have the issue for it[2]), we're
going to use dashes instead of underscores. Please adjust the test chunk
name regarding this policy.

>    @@ -0,0 +1,24 @@
>    +#!/usr/bin/env tarantool
>    +local tap = require('tap')
>    +local test = tap.test('execute')
>    +test:plan(2)
>    +
>    +--
>    +--  gh-4231:  box.execute  should  be  immutable  function  meaning it
>    doesn't
>    +-- change after first box.cfg implicit invocation
>    +--
>    +
>    +local box_execute = box.execute
>    +local status, err = pcall(function()
>    +    box_execute("SELECT 1")
>    +end)
>    +test:ok(status  and  err  ==  nil, "box.execute does not work properly
>    before box.cfg")
>    +

load_cfg has been already called here, so you can check that box.execute
function prior to this call is the same as the one after it (as Nikita
suggested before).

>    +box.cfg{}
>    +
>    +local status2, err2 = pcall(function()
>    +    box_execute("CREATE TABLE t1 (s1 INTEGER, PRIMARY KEY (s1));")
>    +end)
>    +test:ok(status2 and err2 == nil, "box.execute is changed after box.cfg
>    invocation")

Minor: I guess you can move these lines to a separate function, since
they are quite similar to the ones prior to box.cfg call.

>    +
>    +os.exit(test:check() and 0 or 1)
>    --
>    2.24.0
> 

<snipped>

[1]: https://www.tarantool.io/en/doc/2.2/dev_guide/developer_guidelines/
[2]: https://github.com/tarantool/doc/issues/1004

-- 
Best regards,
IM

  reply	other threads:[~2019-12-25  1:32 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 11:50 [Tarantool-patches] [PATCH] box.execute should be immutable function Maria
2019-11-14 16:51 ` Nikita Pettik
2019-12-17 14:39 ` Igor Munkin
2019-12-24 15:32   ` [Tarantool-patches] [PATCH] box: make box.execute() immutable Maria Khaydich
2019-12-25  1:30     ` Igor Munkin [this message]
2019-12-26 14:08     ` Alexander Turenko
2020-01-13 12:13       ` Maria Khaydich
2020-01-13 15:48         ` Igor Munkin
2020-01-18 10:56           ` Maria Khaydich
2020-02-20 17:51             ` Alexander Turenko
2020-02-20 21:15               ` Igor Munkin
2020-03-11 15:56               ` Maria Khaydich
2020-03-18 22:25                 ` Igor Munkin
2020-05-02 14:52                   ` Alexander Turenko
2020-05-12 16:16                 ` Alexander Turenko
2020-03-11 15:57               ` [Tarantool-patches] [PATCH 1/2] box: make box.cfg idempotent function Maria Khaydich
2020-03-12 13:29                 ` Konstantin Osipov
2020-03-12 19:25                   ` Maria Khaydich
2020-03-12 20:00                     ` Konstantin Osipov
2020-03-18 22:26                       ` Igor Munkin
2020-03-19  7:19                         ` Konstantin Osipov
2020-03-19  9:08                           ` Igor Munkin
2020-03-19 10:06                             ` Konstantin Osipov
2020-03-19 10:26                               ` Igor Munkin
2020-05-06 11:17                           ` Alexander Turenko
2020-05-06 11:49                             ` Konstantin Osipov
2020-05-06 12:53                               ` Alexander Turenko
2020-05-06 13:02                                 ` Konstantin Osipov
2020-05-06 13:13                                   ` Alexander Turenko
2020-03-18 22:26                 ` Igor Munkin
2020-05-12 16:17                   ` 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=20191225013038.GC31304@tarantool.org \
    --to=imun@tarantool.org \
    --cc=maria.khaydich@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] box: make box.execute() immutable' \
    /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