[Tarantool-patches] [PATCH 1/1] netbox: don't fire on_connect() at schema update

Alexander Turenko alexander.turenko at tarantool.org
Tue Nov 5 18:00:32 MSK 2019


On Tue, Nov 05, 2019 at 05:12:09PM +0300, Vladislav Shpilevoy wrote:
> Hi! Thanks for the review!
> 
> So, in short, you are against assuming that errno ~= nil always
> means that it is a terminal state.

'error_reconnect' is not the terminal state, but yes: I'm against
assuming that errno ~= nil means anything about a current state.

> I don't think that error ~= nil is a bad idea, but ok, I don't mind
> checking the states explicitly as it was before.

I'm more comfortable with this approach, thanks!

The patch LGTM. CCed Kirill.

https://github.com/tarantool/tarantool/issues/4593
https://github.com/tarantool/tarantool/tree/gerold103/gh-4593-netbox-on_connect

> 
> Force pushed to the branch:
> =======================================================================
> 
> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> index 696b30fd9..c2e1bb9c4 100644
> --- a/src/box/lua/net_box.lua
> +++ b/src/box/lua/net_box.lua
> @@ -933,7 +933,8 @@ local function new_sm(host, port, opts, connection, greeting)
>                      remote._is_connected = true
>                      remote._on_connect:run(remote)
>                  end
> -            elseif errno ~= nil then
> +            elseif state == 'error' or state == 'error_reconnect' or
> +                   state == 'closed' then
>                  if was_connected then
>                      remote._is_connected = false
>                      remote._on_disconnect:run(remote)
> 
> =======================================================================

> > Let's consider unix errno: it should not be used as a primary source of
> > information **whether** an error occurs. You always check a return code
> > and only if it says that an error occurs we can consider 'errno' as a
> > source of information **which kind** of error occurs.
> 
> Yes, but it is not unix errno. Here the error code is rather like a
> return value. Nil means everything is ok, not nil means that the state
> machine has reached a terminal state.

I think that the name 'errno' is not good here, but it is debatable and
surely should not be changed within the bugfix issue.

> > That is why I generally against using of errno / diagnostic area as
> > sources of information whether an error occurs: in context of Unix APIs
> > this would be an improper usage.
> > 
> > I would mark states as 'connected' and 'disconnected' explicitly:
> > 
> >  | -- XXX: Give a comment why, say, 'fetch_schema' is not here.
> >  | local function is_state_connected(state)
> >  |     return state == 'active'
> >  | end
> >  |
> >  | local disconnected_states = {
> >  |     initial = true,
> >  |     error = true,
> >  |     error_reconnect = true,
> >  |     closed = true,
> >  | }
> >  |
> >  | local function is_state_disconnected(state)
> >  |     return disconnected_states[state]
> >  | end
> 
> This way is the same as it was before - checking of the states
> explicitly, by their names. Previously I would need to patch
> callback() on any update in the state set. In your proposal I
> need to update these functions. So it is the same, it does not
> simplify anything.

is_state_disconnected() can be reused in set_state() too, but I don't
mind of checking states explicitly.


More information about the Tarantool-patches mailing list