box: introduce Lua persistent functions
Closes #4182 Needed for #1260 @TarantoolBot document Title: Persistent Lua functions Now Tarantool supports 'persistent' Lua functions. Such functions are stored in snapshot and are available after restart. To create a persistent Lua function, specify a function body in box.schema.func.create call: e.g. body = "function(a, b) return a + b end" A Lua persistent function may be 'sandboxed'. The 'sandboxed' function is 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 Finally, the new 'is_deterministic' flag allows to mark a registered function as deterministic, i.e. the function that can produce only one result for a given list of parameters. The new box.schema.func.create interface is: box.schema.func.create('funcname', <setuid = true|FALSE>, <if_not_exists = true|FALSE>, <language = LUA|c>, <body = string ('')>, <is_deterministic = true|FALSE>, <is_sandboxed = true|FALSE>, <comment = string ('')>) Example: lua_code = [[function(a, b) return a + b end]] box.schema.func.create('sum', {body = lua_code, is_deterministic = true, is_sandboxed = true}) box.func.sum --- - is_sandboxed: true is_deterministic: true id: 2 setuid: false body: function(a, b) return a + b end name: sum language: LUA ... box.func.sum:call({1, 3}) --- - 4 ...
Showing
- src/box/alter.cc 76 additions, 13 deletionssrc/box/alter.cc
- src/box/bootstrap.snap 0 additions, 0 deletionssrc/box/bootstrap.snap
- src/box/func.c 6 additions, 1 deletionsrc/box/func.c
- src/box/func_def.c 12 additions, 0 deletionssrc/box/func_def.c
- src/box/func_def.h 27 additions, 3 deletionssrc/box/func_def.h
- src/box/lua/call.c 224 additions, 2 deletionssrc/box/lua/call.c
- src/box/lua/schema.lua 15 additions, 3 deletionssrc/box/lua/schema.lua
- src/box/lua/upgrade.lua 34 additions, 1 deletionsrc/box/lua/upgrade.lua
- src/box/schema_def.h 11 additions, 0 deletionssrc/box/schema_def.h
- test/box-py/bootstrap.result 9 additions, 3 deletionstest/box-py/bootstrap.result
- test/box-py/bootstrap.test.py 1 addition, 1 deletiontest/box-py/bootstrap.test.py
- test/box/access_misc.result 8 additions, 2 deletionstest/box/access_misc.result
- test/box/function1.result 201 additions, 8 deletionstest/box/function1.result
- test/box/function1.test.lua 71 additions, 2 deletionstest/box/function1.test.lua
Loading
Please register or sign in to comment