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 05/14] WIP: module api/lua: add luaT_tuple_encode() Date: Mon, 12 Oct 2020 22:06:21 +0300 [thread overview] Message-ID: <20201012190621.ocgqlzrgyqrgu4ta@tkn_work_nb> (raw) In-Reply-To: <6caeccfe-9310-8ae1-f4bb-078b552dae1a@tarantool.org> > > +/** > > + * Encode a Lua table, a tuple or objects on a Lua stack as raw > > + * tuple data (MsgPack). > > + * > > + * @param L Lua state > > + * @param idx acceptable index on the Lua stack > > + * (or zero, see below) > > + * @param tuple_len_ptr where to store tuple data size in bytes > > + * (or NULL) > > + * > > + * Set idx to zero to create the new tuple from objects on the Lua > > + * stack. > > + * > > + * The data is encoded on the shared buffer: so called > > + * <tarantool_lua_ibuf> (it also available as <buffer.SHARED_IBUF> > > 1. Both are private. I wouldn't mention them. I think it is enough to > say, that the allocation is 'internal', and may be freed by any next > lua-related call. It is not more actual: I changed luaT_tuple_encode() to use the box region. > > > + * in Lua). The data is valid until next similar call. It is > > + * generally safe to pass the result to a box function (copy it if > > + * doubt). No need to release this buffer explicitly, it'll be > > + * reused by later calls. > > 2. Why exactly are we doing this export? I need a remainder. I remember > we discussed if we could return the encoded tuple on a region, but > decided it could be too slow, because could lead to oscillation of the > region's slab if the region would be truncated after every call. Not exactly. I doubt about changing the existing user visible function from ibuf to region: box.tuple.new(), but I'm okay with exposing the new one that is initially based on the region allocator. The reason is that I unable to provide a good reason for such change for an existing function. Maybe it'll degrade by performance in some cases. Maybe not. Anyway, there is no reason to change the allocator under box.tuple.new() (except our internal coding problems). Maybe I worry more than necessary. I don't know, so I would go by the more safe pathway. > > Also I remember we discussed if we could expose the ibuf too. Because it > is a nice allocator to allocate contiguous memory blocks but without > an oscillation. Then we looked at it and found, that it actually > oscillates. Because we call ibuf_reinit, which puts the slab back to the > cache. Not exactly. It is seems, it is just mistake on the caller side: ibuf_reinit() is called instead of ibuf_reset(). It is in my backlog, I'll file an issue and fix it when time will permit. So ibuf itself is out of suspicions. > > That makes me wonder why not use the region, if both suck at oscillation, > but at least we exposed and documented the region already. This arguments works for me. It seems, we usually lean on the region in the public APIs, so it would be better to continue to do so and keep some consistency. At least it is easier to understand and use. > > If you worry about code duplication, I think it wouldn't be that terrible. > luaT_tuple_encode() uses mpstream. So most of it could be moved to a new > common static function inside lua/tuple.c which takes an mpstream, and > stores Lua objects into it. And 2 wrappers on top - one creates mpstream > from an ibuf, another from the region. Not exactly so: mpstream initialization also may raise an error. But, yep, it is still possible to do some code unification. It does not look nice, but at least not so disgusting as code duplication. > > What I do worry about - the function may throw, and something would be left > on the region memory. Is it critical? Can't it happen with like any other > allocator too, so the problem is not really in the region itself? I filed #5382 regarding this and fixed it within the patchset.
next prev parent reply other threads:[~2020-10-12 19:06 UTC|newest] Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-23 1:14 [Tarantool-patches] [PATCH 00/14] RFC: module api: extend for external key_def Lua module Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 01/14] module api: get rid of typedef redefinitions Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 02/14] WIP: module api: expose box region Alexander Turenko 2020-09-24 22:31 ` Vladislav Shpilevoy 2020-10-08 19:21 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 03/14] WIP: module api/lua: add luaL_iscdata() function Alexander Turenko 2020-09-24 22:32 ` Vladislav Shpilevoy 2020-10-08 21:46 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 04/14] WIP: module api/lua: expose luaT_tuple_new() Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 05/14] WIP: module api/lua: add luaT_tuple_encode() Alexander Turenko 2020-09-24 22:32 ` Vladislav Shpilevoy 2020-10-12 19:06 ` Alexander Turenko [this message] 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 06/14] WIP: refactoring: add API_EXPORT to lua/tuple functions Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 07/14] WIP: refactoring: add API_EXPORT to key_def functions Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 08/14] WIP: refactoring: extract key_def module API functions Alexander Turenko 2020-09-25 22:58 ` Vladislav Shpilevoy 2020-10-07 11:30 ` Alexander Turenko 2020-10-07 22:12 ` Vladislav Shpilevoy 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 09/14] WIP: module api: add box_key_def_new_ex() Alexander Turenko 2020-09-25 22:58 ` Vladislav Shpilevoy 2020-10-09 21:54 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 10/14] WIP: module api: add box_key_def_dump_parts() Alexander Turenko 2020-09-25 22:58 ` Vladislav Shpilevoy 2020-10-09 9:33 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 11/14] WIP: module api: expose box_tuple_validate_key_parts() Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 12/14] WIP: module api: expose box_key_def_merge() Alexander Turenko 2020-09-25 22:58 ` Vladislav Shpilevoy 2020-10-09 1:46 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 13/14] WIP: module api: expose box_tuple_extract_key_ex() Alexander Turenko 2020-09-25 22:58 ` Vladislav Shpilevoy 2020-10-09 1:14 ` Alexander Turenko 2020-10-10 1:21 ` Alexander Turenko 2020-09-23 1:14 ` [Tarantool-patches] [PATCH 14/14] WIP: module api: add box_key_def_validate_key() Alexander Turenko 2020-09-25 22:59 ` Vladislav Shpilevoy 2020-10-09 1:22 ` Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 00/16] RFC: module api: extend for external key_def Lua module Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 01/16] collation: allow to find a collation by a name Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 02/16] refactoring: adjust contract of luaT_tuple_new() Alexander Turenko 2020-09-28 21:26 ` Vladislav Shpilevoy 2020-10-05 11:58 ` Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 03/16] module api: get rid of typedef redefinitions Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 04/16] WIP: module api: expose box region Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 05/16] WIP: module api/lua: add luaL_iscdata() function Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 06/16] WIP: module api/lua: expose luaT_tuple_new() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 07/16] WIP: module api/lua: add luaT_tuple_encode() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 08/16] WIP: refactoring: add API_EXPORT to lua/tuple functions Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 09/16] WIP: refactoring: add API_EXPORT to key_def functions Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 10/16] WIP: refactoring: extract key_def module API functions Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 11/16] WIP: module api: add box_key_def_new_ex() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 12/16] WIP: module api: add box_key_def_dump_parts() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 13/16] WIP: module api: expose box_tuple_validate_key_parts() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 14/16] WIP: module api: expose box_key_def_merge() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 15/16] WIP: module api: expose box_tuple_extract_key_ex() Alexander Turenko 2020-09-23 1:40 ` [Tarantool-patches] [PATCH 1.10 16/16] WIP: module api: add box_key_def_validate_key() Alexander Turenko 2020-10-05 7:26 ` [Tarantool-patches] [PATCH 00/14] RFC: module api: extend for external key_def Lua module Alexander Turenko
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=20201012190621.ocgqlzrgyqrgu4ta@tkn_work_nb \ --to=alexander.turenko@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 05/14] WIP: module api/lua: add luaT_tuple_encode()' \ /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