From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org
Subject: Re: [tarantool-patches] [PATCH v2 1/1] schema:frommap() to create table or tuple
Date: Fri, 6 Apr 2018 16:47:23 +0300 [thread overview]
Message-ID: <20180406134723.nskjfdcbcg2nqt7k@esperanza> (raw)
In-Reply-To: <b1229c8e57d77958dc21f4407a954ecd0b85f341.1522859637.git.kshcherbatov@tarantool.org>
On Wed, Apr 04, 2018 at 07:35:54PM +0300, Kirill Shcherbatov wrote:
> diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
> index 29a9aca..2723baf 100644
> --- a/src/box/lua/space.cc
> +++ b/src/box/lua/space.cc
> @@ -386,6 +396,111 @@ static struct trigger on_alter_space_in_lua = {
> RLIST_LINK_INITIALIZER, box_lua_space_new_or_delete, NULL, NULL
> };
>
> +/**
> + * Get a C pointer for space structure.
> + * Caches the result. Cleans the user(negative) stack itself.
> + * @param Lua space object at top of the Lua stack.
> + * @retval not nil C structure pointer.
> + * @retval nil, err Can not find underlying space, error
> + * description is returned.
> + */
> +static int
> +lbox_space_ptr_cached(struct lua_State *L)
> +{
Is it really necessary? Can't you always pass space_id and use
space_cache_find, which already caches last space ptr?
> + if (lua_gettop(L) < 1 || !lua_istable(L, 1))
> + luaL_error(L, "Usage: space:_cptr()");
> +
> + lua_getfield(L, 1, "_schema_version");
> + uint64_t schema_version = luaL_touint64(L, -1);
> + lua_pop(L, 1);
> + uint64_t global_shema_version = box_schema_version();
> +
> + void *space = NULL;
> + if (schema_version == global_shema_version) {
> + lua_getfield(L, 1, "_cptr");
> + space = (void *)lua_topointer(L, -1);
> + } else {
> + lua_getfield(L, 1, "id");
> + uint32_t id = luaL_touint64(L, -1);
> + space = space_by_id(id);
> + if (space == NULL) {
> + lua_pushnil(L);
> + lua_pushstring(L, tt_sprintf("Space with id '%d' "\
> + "doesn't exist", id));
> + return 2;
> + }
> +
> + /** update the cache */
> + luaL_pushuint64(L, global_shema_version);
> + lua_setfield(L, 1, "_schema_version");
> + lua_pushlightuserdata(L, space);
> + lua_setfield(L, 1, "_cptr");
> + }
> + lua_pop(L, 1);
> + lua_pushlightuserdata(L, space);
> + return 1;
> +}
> @@ -464,4 +579,12 @@ box_lua_space_init(struct lua_State *L)
> lua_pushnumber(L, VCLOCK_MAX);
> lua_setfield(L, -2, "REPLICA_MAX");
> lua_pop(L, 2); /* box, schema */
> +
> + static const struct luaL_Reg space_internal_lib[] = {
> + {"frommap", lbox_space_frommap},
> + {"_cptr", lbox_space_ptr_cached},
> + {NULL, NULL}
> + };
> + luaL_register(L, "box.internal.space", space_internal_lib);
> + lua_pop(L, 1);
AFAIU this function might get pretty hot. Shouldn't we use FFI for
calling it?
next prev parent reply other threads:[~2018-04-06 13:47 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-28 17:51 Kirill Shcherbatov
2018-03-28 18:28 ` Kirill Shcherbatov
2018-03-29 7:36 ` [tarantool-patches] " Kirill Shcherbatov
2018-03-29 10:14 ` v.shpilevoy
2018-04-02 10:26 ` Kirill Shcherbatov
2018-04-02 11:19 ` v.shpilevoy
2018-04-02 19:42 ` Kirill Shcherbatov
2018-04-03 9:47 ` Vladislav Shpilevoy
2018-04-04 14:14 ` Kirill Shcherbatov
2018-04-04 16:35 ` [tarantool-patches] " Kirill Shcherbatov
2018-04-04 16:43 ` Vladislav Shpilevoy
2018-04-06 13:47 ` Vladimir Davydov [this message]
2018-04-06 15:44 ` [tarantool-patches] " Konstantin Osipov
2018-04-09 8:30 ` Kirill Shcherbatov
2018-04-09 10:44 ` Vladislav Shpilevoy
2018-04-09 17:23 ` Kirill Shcherbatov
2018-04-09 17:45 ` Vladislav Shpilevoy
2018-04-10 10:31 ` Vladimir Davydov
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=20180406134723.nskjfdcbcg2nqt7k@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=kshcherbatov@tarantool.org \
--cc=tarantool-patches@freelists.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [tarantool-patches] [PATCH v2 1/1] schema:frommap() to create table or tuple' \
/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