From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@freelists.org
Subject: Re: [tarantool-patches] Re: [PATCH 4/8] netbox: extend codec with 'decode' methods
Date: Tue, 24 Apr 2018 16:16:04 +0300 [thread overview]
Message-ID: <20180424131604.nlsj54uztlr75q3n@esperanza> (raw)
In-Reply-To: <aeb9b90c-3af6-3369-466a-63a80903f5c6@tarantool.org>
Ack
On Mon, Apr 23, 2018 at 09:59:13PM +0300, Vladislav Shpilevoy wrote:
> Hello. Thanks for review! See the diff at the end of letter.
> > > 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_nop, may be?
>
> Done.
>
> >
> > > +local function decode_one_tuple(response)
> > > + if response[1] then
> > > + return box.tuple.new(response[1])
> > > + end
> > > +end
> > > +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
> >
> > Do we really need this MORE_THAN_ONE_TUPLE error? Can't we use
> > decode_one_tuple in 'get' as well? I ask, because having two methods
> > called decode_one_tuple and decode_single_tuple is confusing IMO -
> > it's unclear what's the difference between them.
>
> I agree with you, it looks ugly, but IProto has no 'get' method, so
> we must emulate it via select(limit = 2) + check that a tuple is
> only one. I renamed decode_single to decode_unique. Maybe it looks
> not so bad.
>
> >
> > > +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
> > > +local function decode_count(response)
> > > + return response[1]
> > > +end
> > > +
> > > +local method_encoder = {
> > > ping = internal.encode_ping,
> > > call_16 = internal.encode_call_16,
> > > call_17 = internal.encode_call,
> > > @@ -61,6 +88,10 @@ local method_codec = {
> > > update = internal.encode_update,
> > > upsert = internal.encode_upsert,
> > > select = internal.encode_select,
> > > + get = internal.encode_select,
> > > + min = internal.encode_select,
> > > + max = internal.encode_select,
> > > + count = internal.encode_call,
> > > -- inject raw data into connection, used by console and tests
> > > inject = function(buf, id, schema_version, bytes)
> > > local ptr = buf:reserve(#bytes)
> > > @@ -69,6 +100,24 @@ local method_codec = {
> > > end
> > > }
> > > +local method_decoder = {
> > > + ping = decode_nil,
> > > + call_16 = decode_select,
> > > + call_17 = decode_nothing,
> > > + eval = decode_nothing,
> > > + insert = decode_one_tuple,
> > > + replace = decode_one_tuple,
> > > + delete = decode_one_tuple,
> > > + update = decode_one_tuple,
> > > + upsert = decode_nil,
> > > + select = decode_select,
> > > + get = decode_single_tuple,
> > > + min = decode_single_tuple,
> > > + max = decode_single_tuple,
> > > + count = decode_count,
> > > + inject = decode_nothing,
> > > +}
> > > +
> > > local function next_id(id) return band(id + 1, 0x7FFFFFFF) end
> > > --
> >
> > > @@ -1144,9 +1175,8 @@ index_metatable = function(remote)
> > > if opts and opts.buffer then
> > > error("index:min() doesn't support `buffer` argument")
> > > end
> > > - local res = remote:_request('select', opts, self.space.id, self.id,
> > > - box.index.GE, 0, 1, key)
> > > - return one_tuple(res)
> > > + return remote:_request('get', opts, self.space.id, self.id,
> >
> > Should be 'min'?
>
> Yes, did not notice that. Fixed on the branch.
>
> >
> > > + box.index.GE, 0, 1, key)
> > > end
> > > function methods:max(key, opts)
> > > @@ -1154,9 +1184,8 @@ index_metatable = function(remote)
> > > if opts and opts.buffer then
> > > error("index:max() doesn't support `buffer` argument")
> > > end
> > > - local res = remote:_request('select', opts, self.space.id, self.id,
> > > - box.index.LE, 0, 1, key)
> > > - return one_tuple(res)
> > > + return remote:_request('get', opts, self.space.id, self.id,
> >
> > Should be 'max'?
>
> Same, you are right. Fixed.
>
> See the diff:
>
> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> index 3868cdf1c..53f301356 100644
> --- a/src/box/lua/net_box.lua
> +++ b/src/box/lua/net_box.lua
> @@ -52,13 +52,13 @@ local E_PROC_LUA = box.error.PROC_LUA
> local is_final_state = {closed = 1, error = 1}
> local function decode_nil(...) end
> -local function decode_nothing(...) return ... end
> +local function decode_nop(...) return ... end
> local function decode_one_tuple(response)
> if response[1] then
> return box.tuple.new(response[1])
> end
> end
> -local function decode_single_tuple(response)
> +local function decode_unique_tuple(response)
> if response[2] then
> return nil, box.error.MORE_THAN_ONE_TUPLE
> end
> @@ -103,19 +103,19 @@ local method_encoder = {
> local method_decoder = {
> ping = decode_nil,
> call_16 = decode_select,
> - call_17 = decode_nothing,
> - eval = decode_nothing,
> + call_17 = decode_nop,
> + eval = decode_nop,
> insert = decode_one_tuple,
> replace = decode_one_tuple,
> delete = decode_one_tuple,
> update = decode_one_tuple,
> upsert = decode_nil,
> select = decode_select,
> - get = decode_single_tuple,
> - min = decode_single_tuple,
> - max = decode_single_tuple,
> + get = decode_unique_tuple,
> + min = decode_unique_tuple,
> + max = decode_unique_tuple,
> count = decode_count,
> - inject = decode_nothing,
> + inject = decode_nop,
> }
> local function next_id(id) return band(id + 1, 0x7FFFFFFF) end
> @@ -1175,7 +1175,7 @@ index_metatable = function(remote)
> if opts and opts.buffer then
> error("index:min() doesn't support `buffer` argument")
> end
> - return remote:_request('get', opts, self.space.id, self.id,
> + return remote:_request('min', opts, self.space.id, self.id,
> box.index.GE, 0, 1, key)
> end
> @@ -1184,7 +1184,7 @@ index_metatable = function(remote)
> if opts and opts.buffer then
> error("index:max() doesn't support `buffer` argument")
> end
> - return remote:_request('get', opts, self.space.id, self.id,
> + return remote:_request('max', opts, self.space.id, self.id,
> box.index.LE, 0, 1, key)
> end
>
next prev parent reply other threads:[~2018-04-24 13:16 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 [this message]
2018-05-08 15:49 ` [tarantool-patches] " Konstantin Osipov
2018-05-08 17:24 ` [tarantool-patches] " 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=20180424131604.nlsj54uztlr75q3n@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [tarantool-patches] Re: [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