From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [PATCH v2 0/9] box: rework functions machinery Date: Thu, 6 Jun 2019 15:03:56 +0300 [thread overview] Message-ID: <cover.1559822429.git.kshcherbatov@tarantool.org> (raw) This patchset introduces a set of changes in Tarantool function machinery. We need them to implement functional indexes in future. The reworked func object acts like a function frontend and allows to call a function on any supported language and return result to obuf, Lua and region. 1. At first, the format of _func space is changed. A new space format is [<id> UINT, <owner> UINT, <name> STR, <setuid> UINT, <language> STR, <body> STR, <returns> STR, <is_deterministic> BOOL, <opts> MAP] and box.schema.func.create endpoint is changed correspondingly: box.schema.func.create('funcname', <setuid = true|FALSE>, <if_not_exists = true|FALSE>, <language = LUA|c>, <body = string ('')>, <returns = string (ANY)>, <is_deterministic = true|FALSE>, <opts = { <is_sandboxed = true|FALSE>} >) 2. Now all registered with box.schema.func.create functions are exported in box.func folder. Each function have :call and :drop method. The :drop method just a shortcut for legacy box.schema.func.drop interface. The :call method is similar to net.box connection:call method except the format or returned value: the func:call method returns a table of values like space:select does. 3. This patchset also introduces 'persistent' Lua functions. Such functions are stored in snapshoot and are available after restart. To create a persistent Lua function, specify function body in box.schema.func.create call: e.g. body = "function(a, b) return a + b end" 4. A Lua persistent function may be 'sandboxed'. The 'sandboxed' function executed in isolated environment: a. only limited set of Lua functions and modules are available: -assert -error -pairs -ipairs -next -pcall -xpcall -type -print -select -string -tonumber -tostring -unpack -math -utf8; b. global variables are forbidden Branch: http://github.com/tarantool/tarantool/tree/kshch/gh-4182-persistent-lua-functions Issue: https://github.com/tarantool/tarantool/issues/4182 Kirill Shcherbatov (9): box: refactor box_lua_find helper box: move box_module_reload routine to func.c box: rework func cache update machinery box: rework func object as a function frontend schema: rework _func system space format box: load persistent Lua functions on creation box: sandbox option for persistent functions box: implement lua_port dump to region and to Lua box: export _func functions with box.func folder src/box/CMakeLists.txt | 1 + src/box/alter.cc | 118 +++++-- src/box/bootstrap.snap | Bin 4393 -> 4449 bytes src/box/call.c | 157 +-------- src/box/call.h | 14 - src/box/errcode.h | 1 + src/box/execute.c | 1 + src/box/func.c | 564 ++++++++++++++++++++++++++++-- src/box/func.h | 84 +++-- src/box/func_def.c | 9 + src/box/func_def.h | 43 ++- src/box/lua/call.c | 379 ++------------------ src/box/lua/init.c | 2 + src/box/lua/port_lua.c | 318 +++++++++++++++++ src/box/lua/schema.lua | 38 +- src/box/lua/upgrade.lua | 25 +- src/box/port.h | 2 +- src/box/schema.cc | 47 ++- src/box/schema.h | 31 +- src/box/schema_def.h | 4 + src/lib/core/port.h | 16 + src/lua/utils.c | 126 +++++++ src/lua/utils.h | 19 + test/box-py/bootstrap.result | 6 +- test/box/access_misc.result | 6 +- test/box/misc.result | 2 + test/box/persistent_func.result | 257 ++++++++++++++ test/box/persistent_func.test.lua | 112 ++++++ 28 files changed, 1734 insertions(+), 648 deletions(-) create mode 100644 src/box/lua/port_lua.c create mode 100644 test/box/persistent_func.result create mode 100644 test/box/persistent_func.test.lua -- 2.21.0
next reply other threads:[~2019-06-06 12:03 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-06 12:03 Kirill Shcherbatov [this message] 2019-06-06 12:03 ` [PATCH v2 1/9] box: refactor box_lua_find helper Kirill Shcherbatov 2019-06-10 9:17 ` Vladimir Davydov 2019-06-06 12:03 ` [PATCH v2 2/9] box: move box_module_reload routine to func.c Kirill Shcherbatov 2019-06-10 9:19 ` Vladimir Davydov 2019-06-06 12:03 ` [PATCH v2 3/9] box: rework func cache update machinery Kirill Shcherbatov 2019-06-10 9:44 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 4/9] box: rework func object as a function frontend Kirill Shcherbatov 2019-06-10 10:32 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 5/9] schema: rework _func system space format Kirill Shcherbatov 2019-06-10 12:10 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 6/9] box: load persistent Lua functions on creation Kirill Shcherbatov 2019-06-10 12:19 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 7/9] box: sandbox option for persistent functions Kirill Shcherbatov 2019-06-10 14:06 ` Vladimir Davydov 2019-06-10 14:15 ` [tarantool-patches] " Kirill Shcherbatov 2019-06-10 14:41 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 8/9] box: implement lua_port dump to region and to Lua Kirill Shcherbatov 2019-06-10 14:24 ` Vladimir Davydov 2019-06-06 12:04 ` [PATCH v2 9/9] box: export _func functions with box.func folder Kirill Shcherbatov 2019-06-10 15:18 ` Vladimir Davydov 2019-06-10 9:14 ` [PATCH v2 0/9] box: rework functions machinery 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=cover.1559822429.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v2 0/9] box: rework functions machinery' \ /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