From: Igor Munkin <imun@tarantool.org> To: Maria Khaydich <maria.khaydich@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH] box: make box.execute() immutable Date: Thu, 19 Mar 2020 01:25:25 +0300 [thread overview] Message-ID: <20200318222525.GE6392@tarantool.org> (raw) In-Reply-To: <1583942174.197473001@f388.i.mail.ru> Masha, Thanks for the patch! I left a couple of comments below, please consider them. Side note: Sasha, there is much work done to solve the issue but we have a ticket[1] requesting to drop the "feature". Could you please write a rationale to proceed with this fix, instead of removing the implicit box.cfg call from of box.execute? On 11.03.20, Maria Khaydich wrote: > > Thank you for the review! I reworked the patch: > ---------------------------------------------------------------------- > Saving box.execute method before explicitly configuring box > automatically invokes load_cfg() nonetheless. Further calls > to box.cfg{} caused its reconfiguration and replacement of > previously saved box.execute meaning it couldn't be used > again without leading to an error. > > The patch introduces a workaround making box.execute idempotent > and is heavily influenced by @Totktonada. > > Closes #4231 > --- > Issue: > https://github.com/tarantool/tarantool/issues/4231 > Branch: > https://github.com/tarantool/tarantool/compare/eljashm/gh-4231-box.execute-immutable-function > > extra/exports | 2 + > src/box/lua/load_cfg.lua | 42 ++++++++++++++++--- > .../gh-4231-immutable-box-execute.test.lua | 28 +++++++++++++ > 3 files changed, 67 insertions(+), 5 deletions(-) > create mode 100755 test/box-tap/gh-4231-immutable-box-execute.test.lua <snipped> > diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua > index 85617c8f0..dc4293bdd 100644 > --- a/src/box/lua/load_cfg.lua > +++ b/src/box/lua/load_cfg.lua <snipped> > @@ -558,15 +564,41 @@ local function load_cfg(cfg) > end > box.cfg = locked(load_cfg) > > +local function box_is_configured() > + return ffi.C.box_is_configured() > +end > + > -- > --- This makes possible do box.execute without calling box.cfg > --- manually. The load_cfg call overwrites following table and > --- metatable. > +-- box.execute is <box_load_and_execute> when box is not loaded, > +-- <lbox_execute> otherwise. See also <box_configured> variable. > +-- <box_load_and_execute> loads box and calls <lbox_execute>. > -- > -function box.execute(...) > - load_cfg() > +local box_load_and_execute > +box_load_and_execute = function(...) > + -- Configure box if it is not configured, no-op otherwise (not > + -- 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 It's better to use a sole function here instead of creating a new one for every call. > + 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 > > -- gh-810: > -- hack luajit default cpath > diff --git a/test/box-tap/gh-4231-immutable-box-execute.test.lua b/test/box-tap/gh-4231-immutable-box-execute.test.lua Minor: test chunk name is left unchanged since the previous version and doesn't respect the commit message wording. > new file mode 100755 > index 000000000..1544591bf > --- /dev/null > +++ b/test/box-tap/gh-4231-immutable-box-execute.test.lua > @@ -0,0 +1,28 @@ > +#!/usr/bin/env tarantool > +local tap = require('tap') > +local test = tap.test('execute') > +test:plan(2) > + > +-- > +-- gh-4231: box.execute should be an idempotent function > +-- meaning its effect should be the same if a user chooses > +-- to use it before explicit box.cfg invocation > +-- > + > +local function execute_is_immutable(execute, cmd, msg) Typo: s/immutable/idempotent/. > + local status, err = pcall(execute, cmd) > + test:ok(status and type(err) == 'table', msg) > +end > + > +local box_execute_stub = box.execute > +-- explicit call to load_cfg > +box.cfg{} > +local box_execute_actual = box.execute > + > +execute_is_immutable(box_execute_stub, > + "CREATE TABLE t1 (s1 INTEGER, PRIMARY KEY (s1));", > + "box.execute stub works before box.cfg") > +execute_is_immutable(box_execute_actual, "DROP TABLE t1", > + "box.execute works properly after box.cfg") > + > +os.exit(test:check() and 0 or 1) > -- > 2.24.0 <snipped> > > > -- > Maria Khaydich > [1]: https://github.com/tarantool/tarantool/issues/4726 -- Best regards, IM
next prev parent reply other threads:[~2020-03-18 22:31 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 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 [this message] 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=20200318222525.GE6392@tarantool.org \ --to=imun@tarantool.org \ --cc=maria.khaydich@tarantool.org \ --cc=tarantool-patches@dev.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