From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 CFA4C440F3C for ; Tue, 5 Nov 2019 18:00:35 +0300 (MSK) Date: Tue, 5 Nov 2019 18:00:32 +0300 From: Alexander Turenko Message-ID: <20191105150032.lf3eujv2ddygsijl@tkn_work_nb> References: <0706877cdc0598bb77489636dd22e852b7a50682.1572385348.git.v.shpilevoy@tarantool.org> <20191105131207.3tyydx33ti45rgdu@tkn_work_nb> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [PATCH 1/1] netbox: don't fire on_connect() at schema update List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org 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.