From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] Re: [PATCH 1/1] netbox: fix wait_connected ignorance
Date: Sun, 9 Dec 2018 14:16:37 +0300 [thread overview]
Message-ID: <20181209111637.5imhtm7q5zsdi4hh@esperanza> (raw)
In-Reply-To: <76987bec-c41f-4bf7-30ad-8835357fb9d5@tarantool.org>
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.
prev parent reply other threads:[~2018-12-09 11:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 15:06 Vladislav Shpilevoy
2018-12-06 17:46 ` Vladimir Davydov
2018-12-06 22:45 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-09 11:16 ` Vladimir Davydov [this message]
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=20181209111637.5imhtm7q5zsdi4hh@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [tarantool-patches] Re: [PATCH 1/1] netbox: fix wait_connected ignorance' \
/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