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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Nov 5 17:12:09 MSK 2019


Hi! Thanks for the review!

So, in short, you are against assuming that errno ~= nil always
means that it is a terminal 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.

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)

=======================================================================

On 05/11/2019 16:12, Alexander Turenko wrote:
> The patch LGTM in the sense that it should work as expected as far as I
> see.
> 
> However I would discuss points I described below: I think we can write
> the patch in a bit more clean way. Vlad, please, let me know what do you
> think about this.
> 
> WBR, Alexander Turenko.
> 
>> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
>> index 31a8c16b7..696b30fd9 100644
>> --- a/src/box/lua/net_box.lua
>> +++ b/src/box/lua/net_box.lua
>> @@ -927,14 +927,17 @@ local function new_sm(host, port, opts, connection, greeting)
>>      local function callback(what, ...)
>>          if what == 'state_changed' then
>>              local state, errno, err = ...
>> -            if (remote.state == 'active' or remote.state == 'fetch_schema') and
>> -               (state == 'error' or state == 'closed' or
>> -                state == 'error_reconnect') then
>> -               remote._on_disconnect:run(remote)
>> -            end
>> -            if remote.state ~= 'error' and remote.state ~= 'error_reconnect' and
>> -               state == 'active' then
>> -                remote._on_connect:run(remote)
>> +            local was_connected = remote._is_connected
>> +            if state == 'active' then
>> +                if not was_connected then
>> +                    remote._is_connected = true
>> +                    remote._on_connect:run(remote)
>> +                end
> 
> We splitted states into 'connected', 'neural' and 'disconnected' (a kind
> of tags or properties). We fire the trigger when a connection step into
> one of 'connected' states from one of 'disconnected' ones ('neural' are
> not counted). This looks okay.
> 
>> +            elseif errno ~= nil then
>> +                if was_connected then
>> +                    remote._is_connected = false
>> +                    remote._on_disconnect:run(remote)
>> +                end
> 
> Here we use `errno ~= nil` condition to determine whether a state is
> 'disconnected' one. The condition is true for 'error', 'error_reconnect'
> and 'closed' states. This way should give a correct behaviour.
> 
> When I saw the patch my question was whether a connection step into
> 'fetch_schema' state with `errno ~= nil`. It was not obvious for me what
> list of states are always set with some 'errno' value (however it is
> easy to deduce from set_state() calls). That is the first point.
> 
> The second is that I cannot prove (at least after brief look into the
> code) that 'errno' is newer `nil` / `box.NULL` for 'disconnected'
> states, because that are places where 'errno' is passed through a
> function.
> 
> I think we should at least give a comment that by using `errno ~= nil`
> we lean on assumption that we always step into 'error',
> 'error_reconnect' and 'closed' states with non-null 'errno' and that
> there is no other states that set 'errno'; but better don't assume this.
> 
> 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.

> 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.


More information about the Tarantool-patches mailing list