[Tarantool-patches] [PATCH] box: make box.execute() immutable

Alexander Turenko alexander.turenko at tarantool.org
Tue May 12 19:16:59 MSK 2020


> >I considered using of `type(box.cfg) == 'function'` check as in
> >tarantoolctl, but in fact it is not realiable: if box was not configured
> >after box.cfg() due to an error (say, after `box.cfg{listen =
> >'invalid'}`) the type of box.cfg will be 'table' and reload_cfg() will
> >work on the next box.cfg() call. So we should use box_is_configured C
> >function:
> >
> > | local ffi = require('ffi')
> > |
> > | ffi.cdef([[
> > | bool
> > | box_is_configured(void);
> > | ]])
> > |
> > | local function box_is_configured()
> > | return ffi.C.box_is_configured()
> > | end

I was not right here: `type(box.cfg)` is changed only at successful box
configuration, however it is performed before full box loading that is
not suitable for box.execute().

We can set a module local `box_is_configured` variable at end of box
configuration to eliminate the ffi call. I'll update and resend the
patchset soon.

> >BTW, it seems that it is possible that <box_load_and_execute> will be
> >called when `box.cfg{}` is already in progress in another fiber: this is
> >why all load_cfg() / reload_cfg() calls are decorated using `locked`
> >wrapper. It seems we should do the same in <box_load_and_execute>:
> >
> > | function box.execute(...)
> > | if not box_is_configured() then
> > | locked(function()
> > | -- Re-check, because after the lock release the box
> > | -- state may be changed. We should call load_cfg()
> > | -- only once.
> > | if not box_is_configured() then
> > | load_cfg()
> > | end
> > | end)()
> > | end
> > | return box.execute(...)
> > | end
> >
> >I experimented with this like so:
> >
> > | $ ./src/tarantool
> > | tarantool> box_execute = box.execute
> > | tarantool> for i = 1, 10 do require('fiber').create(function() require('log').info(require('yaml').encode((box_execute('SELECT * FROM "_vindex"')))) end) end

I'll add such test case.


More information about the Tarantool-patches mailing list