From: Alexander Turenko <alexander.turenko@tarantool.org> To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 1/1] netbox: don't fire on_connect() at schema update Date: Tue, 5 Nov 2019 16:12:08 +0300 [thread overview] Message-ID: <20191105131207.3tyydx33ti45rgdu@tkn_work_nb> (raw) In-Reply-To: <0706877cdc0598bb77489636dd22e852b7a50682.1572385348.git.v.shpilevoy@tarantool.org> 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. 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 And use this markers instead of `state == 'active'` and `errno ~= nil` conditions. What do you think about this way? > end > remote.state, remote.error = state, err > if state == 'error_reconnect' then > @@ -989,6 +992,7 @@ local function new_sm(host, port, opts, connection, greeting) > remote._on_schema_reload = trigger.new("on_schema_reload") > remote._on_disconnect = trigger.new("on_disconnect") > remote._on_connect = trigger.new("on_connect") > + remote._is_connected = false > remote._transport = create_transport(host, port, user, password, callback, > connection, greeting) > remote._transport.start()
next prev parent reply other threads:[~2019-11-05 13:12 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-29 21:43 Vladislav Shpilevoy 2019-10-29 22:03 ` Cyrill Gorcunov 2019-10-29 23:51 ` Vladislav Shpilevoy 2019-11-05 13:12 ` Alexander Turenko [this message] 2019-11-05 14:12 ` Vladislav Shpilevoy 2019-11-05 15:00 ` Alexander Turenko 2019-11-05 16:34 ` Kirill Yukhin 2019-11-06 0:56 ` Alexander Turenko 2019-11-06 13:44 ` Kirill Yukhin
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=20191105131207.3tyydx33ti45rgdu@tkn_work_nb \ --to=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 1/1] netbox: don'\''t fire on_connect() at schema update' \ /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