[tarantool-patches] Re: [PATCH 1/1] netbox: fix wait_connected ignorance
Vladimir Davydov
vdavydov.dev at gmail.com
Sun Dec 9 14:16:37 MSK 2018
On Fri, Dec 07, 2018 at 01:45:16AM +0300, Vladislav Shpilevoy wrote:
> On 06/12/2018 20:46, Vladimir Davydov wrote:
> > On Wed, Dec 05, 2018 at 06:06:39PM +0300, Vladislav Shpilevoy wrote:
> > > diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> > > index fd6ebf9de..d54b3e7d9 100644
> > > --- a/src/box/lua/net_box.lua
> > > +++ b/src/box/lua/net_box.lua
> > > @@ -419,21 +419,21 @@ local function create_transport(host, port, user, password, callback,
> > > local function start()
> > > if state ~= 'initial' then return not is_final_state[state] end
> > > - if not connection and not callback('reconnect_timeout') then
> > > - set_state('error', E_NO_CONNECTION)
> > > - return
> > > - end
> > > fiber.create(function()
> > > local ok, err
> > > worker_fiber = fiber_self()
> > > fiber.name(string.format('%s:%s (net.box)', host, port), {truncate=true})
> > > - -- It is possible, if the first connection attempt had
> > > - -- been failed, but reconnect timeout is set. In such
> > > - -- a case the worker must be run, and immediately
> > > - -- start reconnecting.
> > > if not connection then
> > > - set_state('error_reconnect', E_NO_CONNECTION, greeting)
> > > - goto do_reconnect
> > > + local tm = callback('fetch_connect_timeout')
> > > + connection, greeting = establish_connection(host, port, tm)
> >
> > This code is very similar to the reconnect code below. You probably
> > didn't reuse it for a reason, but still, may be we could do something
> > like this?> diff --git a/src/box/lua/net_box.lua
> > b/src/box/lua/net_box.lua
> > index d54b3e7d..f342889a 100644
> > --- a/src/box/lua/net_box.lua
> > +++ b/src/box/lua/net_box.lua
> > @@ -424,16 +424,7 @@ local function create_transport(host, port, user, password, callback,
> > worker_fiber = fiber_self()
> > fiber.name(string.format('%s:%s (net.box)', host, port), {truncate=true})
> > if not connection then
> > - local tm = callback('fetch_connect_timeout')
> > - connection, greeting = establish_connection(host, port, tm)
> > - if not connection then
> > - if not callback('reconnect_timeout') then
> > - set_state('error', E_NO_CONNECTION, greeting)
> > - return
> > - end
> > - set_state('error_reconnect', E_NO_CONNECTION, greeting)
> > - goto do_reconnect
> > - end
> > + goto do_connect
> > end
> > ::handle_connection::
> > ok, err = pcall(protocol_sm)
> > @@ -448,6 +439,7 @@ local function create_transport(host, port, user, password, callback,
> > local timeout = callback('reconnect_timeout')
> > while timeout and state == 'error_reconnect' do
> > fiber.sleep(timeout)
> > + ::do_connect::
> > timeout = callback('reconnect_timeout')
> > if not timeout or state ~= 'error_reconnect' then
> > break
> >
> Yes, we can, but there are a few problems:
>
> 1. In Lua labels have visibility scope. So to put do_connect inside
> while I need to replace while with another explicit goto.
>
> 2. In the first attempt to connect I set error as set_state('error')
> instead of set_state('error_reconnect') - it is important, because
> the latter logs an error.
>
> But nonetheless I've solved these problems. This makes diff 3 lines
> shorter, but I am not sure that such a small shortening is worth
> making code less clear. It is up to you.
Thanks, the new version looks more straighforward to me, actually.
Pushed to 2.1 and 1.10.
More information about the Tarantool-patches
mailing list