From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 2EFE2469710 for ; Tue, 12 May 2020 19:17:18 +0300 (MSK) Date: Tue, 12 May 2020 19:16:59 +0300 From: Alexander Turenko Message-ID: <20200512161659.lzelms6je2vni64d@tkn_work_nb> References: <20191114115020.21091-1-maria.khaydich@tarantool.org> <1579344991.266039392@f319.i.mail.ru> <20200220175124.pwj24lx3jz4w6zcm@tkn_work_nb> <1583942174.197473001@f388.i.mail.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1583942174.197473001@f388.i.mail.ru> Subject: Re: [Tarantool-patches] [PATCH] box: make box.execute() immutable List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Maria Khaydich Cc: tarantool-patches@dev.tarantool.org > >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 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 : > > > > | 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.