From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v2 0/9] box: rework functions machinery Date: Thu, 6 Jun 2019 15:03:56 +0300 Message-Id: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov List-ID: 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 [ UINT, UINT, STR, UINT, STR, STR, STR, BOOL, MAP] and box.schema.func.create endpoint is changed correspondingly: box.schema.func.create('funcname', , , , , , , } >) 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