Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH v2 0/9] box: rework functions machinery
@ 2019-06-06 12:03 Kirill Shcherbatov
  2019-06-06 12:03 ` [PATCH v2 1/9] box: refactor box_lua_find helper Kirill Shcherbatov
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Kirill Shcherbatov @ 2019-06-06 12:03 UTC (permalink / raw)
  To: tarantool-patches, vdavydov.dev; +Cc: Kirill Shcherbatov

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-06-10 15:18 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06 12:03 [PATCH v2 0/9] box: rework functions machinery Kirill Shcherbatov
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox