From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: Alexander Turenko <alexander.turenko@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 17:12:09 +0300 [thread overview] Message-ID: <cd8c59d2-114a-91dc-557f-c0290ee94456@tarantool.org> (raw) In-Reply-To: <20191105131207.3tyydx33ti45rgdu@tkn_work_nb> 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.
next prev parent reply other threads:[~2019-11-05 14:06 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 2019-11-05 14:12 ` Vladislav Shpilevoy [this message] 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=cd8c59d2-114a-91dc-557f-c0290ee94456@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.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