Tarantool development patches archive
 help / color / mirror / Atom feed
From: Konstantin Osipov <kostja@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: Re: [tarantool-patches] [PATCH 4/8] netbox: extend codec with 'decode' methods
Date: Tue, 8 May 2018 18:49:34 +0300	[thread overview]
Message-ID: <20180508154934.GD4867@atlas> (raw)
In-Reply-To: <5196d19705a653bfbf600cf787e05f4f75df99f6.1523903144.git.v.shpilevoy@tarantool.org>

* Vladislav Shpilevoy <v.shpilevoy@tarantool.org> [18/04/16 21:44]:
> Netbox has a table 'method_codec' that is used to encode a
> request by a method name. But a response is decoded out of codec.
> It leads to
> 1) decoding into Lua tables before decoding into tuples where
> needed - it is double decoding and produces a lot of garbage;
> 2) each method contains hacks like one_tuple(), or single tuple
> check.
> 
> These things can not be fixed with no real codec instead of
> encoder only.
> 
> Also global table with decoders is needed for #3107, where
> a request could be sent async with no fiber blocking. An async
> response when received already does not have a call context - it
> has only method name.
> 
> Needed for #3107
> ---
>  src/box/lua/net_box.lua | 116 +++++++++++++++++++++++++++++-------------------
>  test/box/net.box.result |  14 ++++++
>  test/box/sql.result     |   2 +
>  3 files changed, 87 insertions(+), 45 deletions(-)
> 
> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> index 4ed2b375d..3868cdf1c 100644
> --- a/src/box/lua/net_box.lua
> +++ b/src/box/lua/net_box.lua
> @@ -50,7 +50,34 @@ local E_PROC_LUA             = box.error.PROC_LUA
>  
>  -- utility tables
>  local is_final_state         = {closed = 1, error = 1}
> -local method_codec           = {
> +
> +local function decode_nil(...) end
> +local function decode_nothing(...) return ... end

decode_nothing -> decode_nop

> +local function decode_one_tuple(response)
> +    if response[1] then
> +        return box.tuple.new(response[1])
> +    end
> +end

decode_one_tuple -> decode_tuple

Why do you need the if () guard?

> +local function decode_single_tuple(response)
> +    if response[2] then
> +        return nil, box.error.MORE_THAN_ONE_TUPLE
> +    end
> +    if response[1] then
> +        return box.tuple.new(response[1])
> +    end
> +end

decode_single_tuple -> decode_get()

> +local function decode_select(response)
> +    setmetatable(response, sequence_mt)
> +    for i, v in pairs(response) do
> +        response[i] = box.tuple.new(v)
> +    end
> +    return response
> +end

Why are you using pairs() rather than ipairs()?

How does this avoid double decode as you claim in changeset
comment?

> +local function decode_count(response)
> +    return response[1]
> +end
> +
> @@ -336,7 +385,10 @@ local function create_transport(host, port, user, password, callback,
>          -- Decode xrow.body[DATA] to Lua objects
>          body, body_end_check = decode(body_rpos)
>          assert(body_end == body_end_check, "invalid xrow length")
> -            return res -- the length of xrow.body
> -        elseif not err then
> -            setmetatable(res, sequence_mt)
> -            local postproc = method ~= 'eval' and method ~= 'call_17'
> -            if postproc then
> -                local tnew = box.tuple.new

You removed this local variable from the decoder - it was here
for a reason. Please put it back in your implementation of decoder.

> diff --git a/test/box/net.box.result b/test/box/net.box.result
> index cf7b27f0b..6a3713fc0 100644
> --- a/test/box/net.box.result
> +++ b/test/box/net.box.result
> @@ -416,9 +416,11 @@ cn.space.net_box_test_space:select({234}, { iterator = 'LT' })
>  ...
>  cn.space.net_box_test_space:update({1}, { { '+', 2, 2 } })
>  ---
> +- null

net.box calling convention should be the same as local box, if a
tuple is not found, it should return nothing, not null.


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

  parent reply	other threads:[~2018-05-08 15:49 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 18:39 [PATCH 0/8] netbox: introduce fiber-async API Vladislav Shpilevoy
2018-04-16 18:39 ` [PATCH 1/8] lua: fix box.error.raise Vladislav Shpilevoy
2018-04-23 16:19   ` Vladimir Davydov
2018-05-08 15:36   ` [tarantool-patches] " Konstantin Osipov
2018-05-08 17:24     ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-16 18:39 ` [PATCH 2/8] lua: allow to create and error object with no throw Vladislav Shpilevoy
2018-04-23 16:20   ` Vladimir Davydov
2018-05-08 15:37   ` [tarantool-patches] " Konstantin Osipov
2018-04-16 18:39 ` [PATCH 3/8] console: fix a bug in interactive readline usage Vladislav Shpilevoy
2018-04-23 16:20   ` Vladimir Davydov
2018-05-08 15:37   ` [tarantool-patches] " Konstantin Osipov
2018-04-16 18:39 ` [PATCH 4/8] netbox: extend codec with 'decode' methods Vladislav Shpilevoy
2018-04-23 16:42   ` Vladimir Davydov
2018-04-23 18:59     ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-24 13:16       ` Vladimir Davydov
2018-05-08 15:49   ` Konstantin Osipov [this message]
2018-05-08 17:24     ` Vladislav Shpilevoy
2018-04-16 18:39 ` [PATCH 5/8] test: fix unstable test Vladislav Shpilevoy
2018-04-22  5:32   ` [tarantool-patches] " Kirill Yukhin
2018-05-08 15:50   ` Konstantin Osipov
2018-04-16 18:39 ` [PATCH 6/8] netbox: introduce fiber-async API Vladislav Shpilevoy
2018-04-23 12:31   ` [tarantool-patches] " Alexander Turenko
2018-04-23 18:59     ` Vladislav Shpilevoy
2018-04-23 16:44   ` Vladimir Davydov
2018-04-23 18:59     ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-24 13:05       ` Vladimir Davydov
2018-04-16 18:39 ` [PATCH 7/8] netbox: remove schema_version from requests Vladislav Shpilevoy
2018-05-08 16:06   ` [tarantool-patches] " Konstantin Osipov
2018-05-08 17:24     ` [tarantool-patches] " Vladislav Shpilevoy
2018-04-16 18:39 ` [PATCH 8/8] netbox: implement perform_request via async version Vladislav Shpilevoy
2018-04-23 16:47   ` Vladimir Davydov
2018-04-23 19:00     ` [tarantool-patches] " Vladislav Shpilevoy

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=20180508154934.GD4867@atlas \
    --to=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [tarantool-patches] [PATCH 4/8] netbox: extend codec with '\''decode'\'' methods' \
    /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