├── Library ├── iconv.lua ├── jit.lua ├── popen.lua ├── swim.lua ├── tap.lua ├── utf8.lua ├── merger.lua ├── pickle.lua ├── crypto.lua ├── metrics │ ├── plugins │ │ ├── prometheus.lua │ │ └── graphite.lua │ ├── http_middleware.lua │ └── init.lua ├── vshard.lua ├── xlog.lua ├── box │ ├── runtime.lua │ ├── backup.lua │ ├── stat.lua │ ├── slab.lua │ ├── error.lua │ ├── ctl.lua │ ├── session.lua │ ├── schema.lua │ ├── tuple.lua │ ├── index.lua │ ├── info.lua │ ├── space.lua │ └── cfg.lua ├── csv.lua ├── strict.lua ├── console.lua ├── uri.lua ├── clock.lua ├── uuid.lua ├── trigger.lua ├── decimal.lua ├── yaml.lua ├── log.lua ├── vshard │ ├── consts.lua │ ├── cfg.lua │ ├── replicaset.lua │ ├── storage.lua │ └── error.lua ├── key_def.lua ├── misc.lua ├── digest.lua ├── config.lua ├── http │ ├── server.lua │ └── client.lua ├── buffer.lua ├── json.lua ├── tarantool.lua ├── net │ └── box.lua ├── datetime.lua ├── string.lua ├── errno.lua ├── box.lua ├── fiber.lua ├── msgpack.lua └── socket.lua ├── config.lua └── README.md /Library/iconv.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/jit.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/popen.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/swim.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/tap.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/utf8.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/merger.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/pickle.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | -------------------------------------------------------------------------------- /Library/crypto.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local crypto = {} 5 | 6 | -------------------------------------------------------------------------------- /Library/metrics/plugins/prometheus.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local prometheus = {} 5 | 6 | function prometheus.collect_http() end 7 | 8 | return prometheus 9 | -------------------------------------------------------------------------------- /Library/vshard.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | return { 5 | consts = require('vshard.consts'), 6 | router = require('vshard.router'), 7 | storage = require('vshard.storage'), 8 | error = require('vshard.error') 9 | } 10 | -------------------------------------------------------------------------------- /Library/xlog.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local xlog = {} 5 | 6 | ---@param path_name string Open a file, and allow iterating over one file entry at a time. 7 | ---@return fun.iterator 8 | function xlog.pairs(path_name) end 9 | 10 | return xlog -------------------------------------------------------------------------------- /Library/box/runtime.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | box.runtime = {} 5 | 6 | ---@class BoxRuntimeInfo 7 | ---@field lua integer 8 | ---@field tuple integer 9 | ---@field maxalloc integer 10 | ---@field used integer 11 | 12 | ---@return BoxRuntimeInfo 13 | function box.runtime.info() end 14 | -------------------------------------------------------------------------------- /Library/csv.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local csv = {} 5 | 6 | 7 | --- Load a CSV file 8 | function csv.load() end 9 | 10 | --- Transform input into a CSV-formatted string 11 | function csv.dump() end 12 | 13 | --- Iterate over CSV records 14 | function csv.iterate() end 15 | 16 | return csv 17 | -------------------------------------------------------------------------------- /config.lua: -------------------------------------------------------------------------------- 1 | configs = { 2 | { 3 | key = 'Lua.runtime.version', 4 | action = 'set', 5 | value = 'LuaJIT', 6 | }, 7 | { 8 | key = 'Lua.diagnostics.globals', 9 | action = 'add', 10 | value = '_TARANTOOL', 11 | }, 12 | { 13 | key = 'Lua.diagnostics.globals', 14 | action = 'remove', 15 | value = 'ngx', 16 | }, 17 | } 18 | -------------------------------------------------------------------------------- /Library/strict.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | ---The strict module has functions for turning “strict mode” on or off. When strict mode is on, an attempt to use an undeclared global variable will cause an error. A global variable is considered “undeclared” if it has never had a value assigned to it. Often this is an indication of a programming error. 3 | --- 4 | ---By default strict mode is off, unless tarantool was built with the -DCMAKE_BUILD_TYPE=Debug option 5 | 6 | --luacheck: ignore 7 | 8 | local strict = {} 9 | 10 | ---Enables strict mode 11 | function strict.on() end 12 | 13 | ---Disables strict mode 14 | function strict.off() end 15 | 16 | return strict -------------------------------------------------------------------------------- /Library/console.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | --TODO: 4 | 5 | local console = {} 6 | 7 | --- Connect to an instance 8 | function console.connect(uri) end 9 | 10 | --- Listen for incoming requests 11 | function console.listen(uri) end 12 | 13 | --- Start the console 14 | function console.start() end 15 | 16 | --- Set the auto-completion flag 17 | function console.ac(auto_completion_flag) end 18 | 19 | --- Set a delimiter 20 | function console.delimiter(marker) end 21 | 22 | --- Get default output format 23 | function console.get_default_output() end 24 | 25 | --- Set default output format 26 | function console.set_default_output(format) end 27 | 28 | --- Set or get end-of-output string 29 | function console.eos(str) end 30 | 31 | return console 32 | -------------------------------------------------------------------------------- /Library/metrics/plugins/graphite.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class options 5 | ---@field prefix string metrics prefix ('tarantool' by default) 6 | ---@field host string Graphite server host ('127.0.0.1' by default) 7 | ---@field port number Graphite server port (2003 by default) 8 | ---@field send_interval number metrics collection interval in seconds (2 by default) 9 | ---@field This function creates a background fiber that periodically sends all metrics to a remote Graphite server. 10 | 11 | local graphite = {} 12 | 13 | --- This function creates a background fiber that periodically sends all metrics to a remote Graphite server. 14 | --- 15 | --- Exported metric names are formatted as follows: . 16 | ---@param options options 17 | function graphite.init(options) end 18 | 19 | return graphite 20 | -------------------------------------------------------------------------------- /Library/box/backup.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | box.backup = {} 5 | 6 | ---Informs the server that activities related to the removal of outdated 7 | ---backups must be suspended. 8 | --- 9 | ---To guarantee an opportunity to copy these files, Tarantool will 10 | ---not delete them. 11 | ---But there will be no read-only mode and checkpoints will continue by 12 | ---schedule as usual. 13 | ---@param n? number optional argument that indicates the checkpoint to use 14 | ---relative to the latest checkpoint. 15 | ---For example `n = 0` means “backup will be based on the latest checkpoint”, 16 | ---`n = 1` means “backup will be based on the first checkpoint before the 17 | ---latest checkpoint (counting backwards)”, and so on. 18 | ---The __default value for n is 0__. 19 | ---@return string[] # a table with the names of snapshot and vinyl files that should be copied 20 | function box.backup.start(n) end 21 | 22 | ---Informs the server that normal operations may resume. 23 | function box.backup.stop() end 24 | -------------------------------------------------------------------------------- /Library/box/stat.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class BoxStatDefault 5 | ---@field total number 6 | ---@field rps number 7 | 8 | ---@class BoxStatDefaultWithCurrent:BoxStatDefault 9 | ---@field current number 10 | 11 | ---@class BoxStatNet 12 | ---@field SENT BoxStatDefault sent bytes to iproto 13 | ---@field RECEIVED BoxStatDefault received bytes from iproto 14 | ---@field CONNECTIONS BoxStatDefaultWithCurrent iproto connections statistics 15 | ---@field REQUESTS BoxStatDefaultWithCurrent iproto requests statistics 16 | 17 | ---@class BoxStat 18 | ---@field reset fun() # resets current statistics 19 | ---@field net fun(): BoxStatNet 20 | ---@overload fun(): BoxStatInfo 21 | 22 | ---@class BoxStatInfo 23 | ---@field INSERT BoxStatDefault 24 | ---@field DELETE BoxStatDefault 25 | ---@field SELECT BoxStatDefault 26 | ---@field REPLACE BoxStatDefault 27 | ---@field UPDATE BoxStatDefault 28 | ---@field UPSERT BoxStatDefault 29 | ---@field CALL BoxStatDefault 30 | ---@field EVAL BoxStatDefault 31 | ---@field AUTH BoxStatDefault 32 | ---@field ERROR BoxStatDefault 33 | 34 | ---@type BoxStat 35 | box.stat = {} 36 | -------------------------------------------------------------------------------- /Library/box/slab.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | box.slab = {} 5 | 6 | ---@class boxSlabInfo 7 | ---@field quota_size integer memory limit for slab allocator 8 | ---@field quota_used integer used by slab allocator 9 | ---@field quota_used_ratio string 10 | ---@field arena_size integer allocated for both tuples and indexes 11 | ---@field arena_used integer used for both tuples and indexes 12 | ---@field arena_used_ratio string 13 | ---@field items_size integer allocated only for tuples 14 | ---@field items_used integer used only for tuples 15 | ---@field items_used_ratio string 16 | 17 | ---@return boxSlabInfo 18 | function box.slab.info() end 19 | 20 | ---@class boxSlabStat 21 | ---@field mem_free integer is the allocated, but currently unused memory; 22 | ---@field mem_used integer is the memory used for storing data items (tuples and indexes); 23 | ---@field item_count integer is the number of stored items; 24 | ---@field item_size integer is the size of each data item; 25 | ---@field slab_count integer is the number of slabs allocated; 26 | ---@field slab_size integer is the size of each allocated slab. 27 | 28 | ---@return boxSlabStat[] 29 | function box.slab.stats() end 30 | -------------------------------------------------------------------------------- /Library/uri.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | local uri = {} 4 | 5 | ---@class URIFormat 6 | ---@field fragment? string string after # 7 | ---@field host? string host (same as Host header in HTTP) 8 | ---@field ipv4? string ipv4 address if was parsed 9 | ---@field ipv6? string ipv6 address if was parsed 10 | ---@field login? string login as for basic auth if was parsed 11 | ---@field password? string password as for basic auth if was parsed 12 | ---@field path? string path in HTTP URI if was parsed 13 | ---@field query? table query of arguments. values are a list of strings 14 | ---@field scheme? string scheme 15 | ---@field service? string port if was given 16 | ---@field unix? string path to unix socket if was parsed 17 | 18 | ---Get a table of URI components 19 | ---@param uri_string string a Uniform Resource Identifier 20 | ---@return URIFormat 21 | function uri.parse(uri_string) end 22 | 23 | ---Form a URI string from its components 24 | ---@param uri_format URIFormat a series of name=value pairs, one for each component 25 | ---@param include_password boolean? If this is supplied and is true, then the password component is rendered in clear text, otherwise it is omitted. 26 | ---@return string 27 | function uri.format(uri_format, include_password) end 28 | 29 | return uri -------------------------------------------------------------------------------- /Library/clock.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | ---@module 'clock' 3 | --luacheck: ignore 4 | --TODO: 5 | 6 | ---@class Clock 7 | local clock = {} 8 | 9 | --- Get the wall clock time in seconds 10 | ---@return number 11 | function clock.time() end 12 | 13 | --- Get the wall clock time in seconds 14 | ---@return number 15 | function clock.realtime() end 16 | 17 | --- Get the wall clock time in nanoseconds 18 | ---@return uint64_t 19 | function clock.time64() end 20 | 21 | --- Get the wall clock time in nanoseconds 22 | ---@return uint64_t 23 | function clock.realtime64() end 24 | 25 | --- Get the monotonic time in seconds 26 | ---@return number 27 | function clock.monotonic() end 28 | 29 | --- Get the monotonic time in nanoseconds 30 | ---@return uint64_t 31 | function clock.monotonic64() end 32 | 33 | --- Get the processor time in seconds 34 | ---@return number 35 | function clock.proc() end 36 | 37 | --- Get the processor time in nanoseconds 38 | ---@return uint64_t 39 | function clock.proc64() end 40 | 41 | --- Get the thread time in seconds 42 | ---@return number 43 | function clock.thread() end 44 | 45 | --- Get the thread time in nanoseconds 46 | ---@return uint64_t 47 | function clock.thread64() end 48 | 49 | --- Measure the time a function takes within a processor 50 | ---@param func fun(...: any): ...:any 51 | ---@return table 52 | function clock.bench(func, ...) end 53 | 54 | return clock 55 | -------------------------------------------------------------------------------- /Library/uuid.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@module 'uuid' 5 | ---@operator call: uuid 6 | local uuid = {} 7 | 8 | ---@class uuid: ffi.cdata* 9 | local uuid_obj = {} 10 | 11 | ---Since version 2.4.1. Create a UUID sequence. You can use it in an index over a uuid field. 12 | ---@return uuid 13 | function uuid.new() end 14 | 15 | ---@param byte_order? "l"|"b"|"h"|"n"|"host"|"network" Byte order of the resulting UUID 16 | ---@return string uuid 16-byte string 17 | function uuid.bin(byte_order) end 18 | 19 | ---@param byte_order? "l"|"b"|"h"|"n"|"host"|"network" Byte order of the resulting UUID 20 | ---@return string uuid 16-byte string 21 | function uuid_obj:bin(byte_order) end 22 | 23 | ---@return string uuid 36-byte binary string 24 | function uuid.str() end 25 | 26 | ---@return string uuid 36-byte binary string 27 | function uuid_obj:str() end 28 | 29 | ---@param uuid_str string UUID in 36-byte hexadecimal string 30 | ---@return uuid uuid converted UUID 31 | function uuid.fromstr(uuid_str) end 32 | 33 | ---@param uuid_bin string UUID in 16-byte binary string 34 | ---@param byte_order? "l"|"b"|"h"|"n"|"host"|"network" Byte order of the resulting UUID 35 | ---@return uuid uuid converted UUID 36 | function uuid.frombin(uuid_bin, byte_order) end 37 | 38 | ---Since version 2.6.1. 39 | ---@param value any 40 | ---@return boolean is_uuid true if the specified value is a uuid, and false otherwise 41 | function uuid.is_uuid(value) end 42 | 43 | return uuid -------------------------------------------------------------------------------- /Library/trigger.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | ---To create the trigger, you need to: 3 | --- 1. Provide an event name used to associate the trigger with. 4 | --- 2. Define the trigger name. 5 | --- 3. Provide a trigger handler function. 6 | 7 | local trigger = {} 8 | 9 | ---@alias trigger_func fun(value: any) 10 | 11 | ---Registers trigger for event `event_name` under name `trigger_name` 12 | --- 13 | ---If other trigger is defined for the pair {event_name, trigger_name} it will be replaced 14 | ---@generic F:trigger_func 15 | ---@param event_name string 16 | ---@param trigger_name string 17 | ---@param func F 18 | ---@return F 19 | function trigger.set(event_name, trigger_name, func) end 20 | 21 | ---Unregisters trigger with name `trigger_name` for event `event_name` 22 | ---@param event_name string 23 | ---@param trigger_name string 24 | function trigger.del(event_name, trigger_name) end 25 | 26 | ---@alias trigger_generator (fun(): string, trigger_func) 27 | 28 | ---Returns Lua Generator for given `event_name` 29 | --- 30 | ---Usage: 31 | ---```lua 32 | ---for name, func in trigger.pairs('box.ctl.on_election') do ... end 33 | ---``` 34 | ---@param event_name string 35 | ---@return trigger_generator, any? param 36 | function trigger.pairs(event_name) end 37 | 38 | ---@param event_name? string 39 | ---@return table 40 | function trigger.info(event_name) end 41 | 42 | ---May raise exception if trigger raises an exception 43 | ---@param event_name string 44 | ---@param ... any arguments of the event 45 | function trigger.call(event_name, ...) end 46 | 47 | return trigger 48 | -------------------------------------------------------------------------------- /Library/decimal.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local decimal = {} 5 | 6 | ---@class decimal 7 | ---@operator unm: decimal 8 | ---@operator add(decimal|number|string): decimal 9 | ---@operator sub(decimal|number|string): decimal 10 | ---@operator mul(decimal|number|string): decimal 11 | ---@operator div(decimal|number|string): decimal 12 | ---@operator mod(decimal|number|string): decimal 13 | ---@operator pow(decimal|number|string): decimal 14 | local decimal_obj = {} 15 | 16 | ---@param n decimal|string|number 17 | ---@return decimal 18 | function decimal.abs(n) end 19 | 20 | ---@param n decimal|string|number 21 | ---@return decimal 22 | function decimal.exp(n) end 23 | 24 | ---@param n decimal|string|number 25 | ---@return boolean 26 | function decimal.is_decimal(n) end 27 | 28 | ---@param n decimal|string|number 29 | ---@return decimal 30 | function decimal.ln(n) end 31 | 32 | ---@param n decimal|string|number 33 | ---@return decimal 34 | function decimal.new(n) end 35 | 36 | ---@param n decimal|string|number 37 | ---@return integer 38 | function decimal.precision(n) end 39 | 40 | ---@param n decimal 41 | ---@param new_scale number 42 | ---@return decimal 43 | function decimal.rescale(n, new_scale) end 44 | 45 | ---@param n decimal|string|number 46 | ---@return number scale 47 | function decimal.scale(n, new_scale) end 48 | 49 | ---@param n decimal|string|number 50 | ---@return decimal 51 | function decimal.log10(n) end 52 | 53 | ---@param n decimal|string|number 54 | ---@param digits? number 55 | ---@return decimal 56 | function decimal.round(n, digits) end 57 | 58 | ---@param n decimal|string|number 59 | ---@return decimal 60 | function decimal.sqrt(n) end 61 | 62 | ---@param n decimal 63 | ---@return decimal 64 | function decimal.trim(n) end 65 | 66 | return decimal 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | # 🕷 Tarantool VScode Library 6 | 7 | > Adds IntelliSense features for Tarantool to VS Code. This is a Library for [Sumneko's Lua Language Server](https://github.com/sumneko/lua-language-server) with extended EmmyLua annotations. 8 | 9 | ## 🎓 Quick start 10 | 11 | In the future, just install the [VSCode extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) for Lua by Sumneko! 12 | 13 | ## 💣 Features 14 | 15 | > TODO 16 | 17 | ## 📝 Contributing 18 | 19 | For local development you need: 20 | 21 | 1. Clone this repository 22 | 2. Add the path to this library in the extension settings 23 | 24 | ![Screenshot 2022-10-02 at 16 59 46](https://user-images.githubusercontent.com/63997548/193460234-7bdd642d-20dd-40ad-bf88-15ed1233865e.png) 25 | 26 | ## ☑️ TODO 27 | 28 | - [ ] Add box module annotations 29 | - [X] box functions (not all) 30 | - [ ] backup 31 | - [X] ctl 32 | - [X] error 33 | - [X] space 34 | - [ ] index 35 | - [X] cfg 36 | - [ ] schema 37 | - [X] stat 38 | - [X] slab 39 | - [X] tuple 40 | - [X] net.box 41 | - [ ] http server, client 42 | - [X] annotations (not all) 43 | - [ ] doc 44 | - [ ] Datetime 45 | - [X] Add annotations 46 | - [ ] Add doc 47 | - [X] json, yaml 48 | - [X] digest 49 | - [X] fiber 50 | - [X] fio 51 | - [X] buffer 52 | - [X] fun 53 | - [X] decimal 54 | - [X] socket 55 | - [ ] csv 56 | - [ ] Add vshard annotations 57 | - [ ] Add cartridge annotations 58 | - [ ] Add library to sumneko's repository 59 | 60 | ## 🕷 Keywords 61 | 62 | - [Tarantool](https://www.tarantool.io/en/) 63 | - [Sumneko](https://github.com/sumneko/lua-language-server) 64 | - [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=sumneko.lua) 65 | -------------------------------------------------------------------------------- /Library/yaml.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class yaml 5 | local yaml = {} 6 | 7 | 8 | ---@return yaml 9 | function yaml.new() end 10 | 11 | ---Convert a Lua object to a YAML string 12 | ---@param lua_value any 13 | ---@return string 14 | function yaml.encode(lua_value) end 15 | 16 | ---Convert a YAML string to a Lua object. 17 | ---@param string string 18 | ---@return table 19 | function yaml.decode(string) end 20 | 21 | ---@class yaml.cfg 22 | ---@field encode_invalid_numbers ?boolean (true) A flag saying whether to enable encoding of NaN and Inf numbers 23 | ---@field encode_number_precision ?number (14) Precision of floating point numbers 24 | ---@field encode_load_metatables ?boolean (true) A flag saying whether the serializer will follow __serialize metatable field 25 | ---@field encode_use_tostring ?boolean (false) A flag saying whether to use tostring() for unknown types 26 | ---@field encode_invalid_as_nil ?boolean (false) A flag saying whether to use NULL for non-recognized types 27 | ---@field encode_sparse_convert ?boolean (true) A flag saying whether to handle excessively sparse arrays as maps 28 | ---@field encode_sparse_ratio ?number (2) 1/encode_sparse_ratio is the permissible percentage of missing values in a sparse array 29 | ---@field encode_sparse_safe ?number (10) A limit ensuring that small Lua arrays are always encoded as sparse arrays (instead of generating an error or encoding as map) 30 | ---@field decode_invalid_numbers ?boolean (true) A flag saying whether to enable decoding of NaN and Inf numbers 31 | ---@field decode_save_metatables ?boolean (true) A flag saying whether to set metatables for all arrays and maps 32 | 33 | ---@param cfg yaml.cfg 34 | function yaml.cfg(cfg) end 35 | 36 | ---A value comparable to Lua “nil” which may be useful as a placeholder in a tuple. 37 | yaml.NULL = box.NULL 38 | 39 | return yaml 40 | -------------------------------------------------------------------------------- /Library/log.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | ---@module 'log' 4 | 5 | ---@class log: table 6 | local log = {} 7 | 8 | ---@class logCfg 9 | ---@field level? log_level Specifies the level of detail the log has. 10 | ---@field log? string Specifies where to send the log’s output, for example, to a file, pipe, or system logger. 11 | ---@field nonblock? boolean If `true`, Tarantool does not block during logging when the system is not ready for writing, and drops the message instead. 12 | ---@field format? log_format pecifies the log format: ‘plain’ or ‘json’. 13 | ---@field modules? { [string]: string } Configures the specified log levels for different modules. 14 | ---@overload fun(cfg: logCfg) 15 | log.cfg = {} 16 | 17 | ---Log a message with the `WARN` level 18 | ---@param s any 19 | ---@param ... any 20 | function log.warn(s, ...) end 21 | 22 | ---Log a message with the `INFO` level 23 | ---@param s any 24 | ---@param ... any 25 | function log.info(s, ...) end 26 | 27 | ---Log a message with the `ERROR` level 28 | ---@param s any 29 | ---@param ... any 30 | function log.error(s, ...) end 31 | 32 | ---Log a message with the `VERBOSE` level 33 | ---@param s any 34 | ---@param ... any 35 | function log.verbose(s, ...) end 36 | 37 | ---Log a message with the `DEBUG` level 38 | ---@param s any 39 | ---@param ... any 40 | function log.debug(s, ...) end 41 | 42 | ---sets log level 43 | ---@param lvl? integer 44 | function log.level(lvl) end 45 | 46 | ---A PID of a logger. You can use this PID to send a signal to a log rotation program, so it can rotate logs. 47 | ---@return integer 48 | function log.pid() end 49 | 50 | ---Rotate the log. 51 | ---For example, you need to call this function to continue logging after a log rotation program renames or moves a file with the latest logs. 52 | function log.rotate() end 53 | 54 | ---Since 2.11.0 55 | ---Create a new logger with the specified name. 56 | ---You can configure a specific log level for a new logger using the log_modules configuration property. 57 | ---@param name string 58 | ---@return log 59 | function log.new(name) end 60 | 61 | return log 62 | -------------------------------------------------------------------------------- /Library/vshard/consts.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local consts = {} 5 | 6 | consts = { 7 | -- Bucket FSM 8 | BUCKET = { 9 | ACTIVE = 'active', 10 | PINNED = 'pinned', 11 | SENDING = 'sending', 12 | SENT = 'sent', 13 | RECEIVING = 'receiving', 14 | GARBAGE = 'garbage', 15 | }, 16 | 17 | STATUS = { 18 | GREEN = 0, 19 | YELLOW = 1, 20 | ORANGE = 2, 21 | RED = 3, 22 | }, 23 | 24 | REPLICATION_THRESHOLD_SOFT = 1, 25 | REPLICATION_THRESHOLD_HARD = 5, 26 | REPLICATION_THRESHOLD_FAIL = 10, 27 | 28 | DEFAULT_BUCKET_COUNT = 3000; 29 | BUCKET_SENT_GARBAGE_DELAY = 0.5; 30 | BUCKET_CHUNK_SIZE = 1000; 31 | LUA_CHUNK_SIZE = 100000, 32 | DEFAULT_REBALANCER_DISBALANCE_THRESHOLD = 1; 33 | REBALANCER_IDLE_INTERVAL = 60 * 60; 34 | REBALANCER_WORK_INTERVAL = 10; 35 | REBALANCER_CHUNK_TIMEOUT = 60 * 5; 36 | DEFAULT_REBALANCER_MAX_SENDING = 1; 37 | REBALANCER_MAX_SENDING_MAX = 15; 38 | DEFAULT_REBALANCER_MAX_RECEIVING = 100; 39 | CALL_TIMEOUT_MIN = 0.5; 40 | CALL_TIMEOUT_MAX = 64; 41 | FAILOVER_UP_TIMEOUT = 5; 42 | FAILOVER_DOWN_TIMEOUT = 1; 43 | DEFAULT_FAILOVER_PING_TIMEOUT = 5; 44 | DEFAULT_SYNC_TIMEOUT = 1; 45 | RECONNECT_TIMEOUT = 0.5; 46 | GC_BACKOFF_INTERVAL = 5, 47 | GC_MAP_CALL_TIMEOUT = 64, 48 | GC_WAIT_LSN_TIMEOUT = 64, 49 | GC_WAIT_LSN_STEP = 0.1, 50 | RECOVERY_BACKOFF_INTERVAL = 5, 51 | REPLICA_BACKOFF_INTERVAL = 5, 52 | DEFAULT_BUCKET_SEND_TIMEOUT = 10, 53 | DEFAULT_BUCKET_RECV_TIMEOUT = 10, 54 | 55 | DEFAULT_SCHED_REF_QUOTA = 300, 56 | DEFAULT_SCHED_MOVE_QUOTA = 1, 57 | 58 | DISCOVERY_IDLE_INTERVAL = 10, 59 | DISCOVERY_WORK_INTERVAL = 1, 60 | DISCOVERY_WORK_STEP = 0.01, 61 | DISCOVERY_TIMEOUT = 10, 62 | 63 | MASTER_SEARCH_IDLE_INTERVAL = 5, 64 | MASTER_SEARCH_WORK_INTERVAL = 0.5, 65 | MASTER_SEARCH_BACKOFF_INTERVAL = 5, 66 | MASTER_SEARCH_TIMEOUT = 5, 67 | 68 | TIMEOUT_INFINITY = 500 * 365 * 86400, 69 | DEADLINE_INFINITY = math.huge, 70 | } 71 | 72 | return consts 73 | -------------------------------------------------------------------------------- /Library/key_def.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | ---@module 'key_def' 4 | ---The key_def module has a function for defining the field numbers and types of a tuple. 5 | ---The definition is usually used with an index definition to extract or compare the index key values. 6 | 7 | local key_def = {} 8 | 9 | ---@class key_def_object 10 | local key_def_object = {} 11 | 12 | ---Return a tuple containing only the fields of the key_def object. 13 | ---@param tuple box.tuple 14 | ---@return box.tuple 15 | function key_def_object:extract_key(tuple) end 16 | 17 | ---Compare the key fields of tuple_1 with the key fields of tuple_2. 18 | ---It is a tuple-by-tuple comparison so users do not have to write code that compares one field at a time. 19 | ---Each field’s type and collation will be taken into account. 20 | ---In effect it is a comparison of `extract_key(tuple_1)` with `extract_key(tuple_2)`. 21 | ---@param tuple_1 box.tuple 22 | ---@param tuple_2 box.tuple 23 | ---@return number # tuple_1 - tuple_2 24 | function key_def_object:compare(tuple_1, tuple_2) end 25 | 26 | ---Compare the key fields of tuple_1 with all the fields of key_tuple. 27 | ---This is the same as key_def_object:compare() except that tuple_2 28 | ---contains only the key fields. 29 | ---In effect it is a comparison of extract_key(tuple_1) with tuple_2. 30 | ---@param tuple box.tuple 31 | ---@param key_tuple box.tuple 32 | ---@return number # tuple_1 - key_tuple 33 | function key_def_object:compare_with_key(tuple, key_tuple) end 34 | 35 | ---Combine the main `key_def_object` with `other_key_def_object`. 36 | ---The return value is a new `key_def_object` containing all the fields 37 | ---of the main `key_def_object`, then all the fields of `other_key_def_object` 38 | ---which are not in the main `key_def_object`. 39 | ---@param other_key_def_object key_def_object 40 | ---@return key_def_object 41 | function key_def_object:merge(other_key_def_object) end 42 | 43 | ---Returns a table containing the fields of the key_def_object. 44 | ---This is the reverse of key_def.new() 45 | ---@return tuple_type[] 46 | function key_def_object:totable() end 47 | 48 | ---@param parts IndexPart[] 49 | ---@return key_def_object 50 | function key_def.new(parts) end 51 | 52 | 53 | return key_def 54 | -------------------------------------------------------------------------------- /Library/misc.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local misc = {} 5 | 6 | ---https://www.tarantool.io/en/doc/latest/reference/tooling/luajit_getmetrics/ 7 | ---@class misc.metrics 8 | ---@field gc_allocated number (monotonic) number of bytes of allocated memory 9 | ---@field gc_cdatanum number (non-monotonic) number of allocated cdata objects 10 | ---@field gc_freed number (monotonic) number of bytes of freed memory 11 | ---@field gc_steps_atomic number (monotonic) number of steps of garbage collector, atomic phases, incremental 12 | ---@field gc_steps_finalize number (monotonic) number of steps of garbage collector, finalize 13 | ---@field gc_steps_pause number (monotonic) number of steps of garbage collector, pauses 14 | ---@field gc_steps_propagate number (monotonic) number of steps of garbage collector, propagate 15 | ---@field gc_steps_sweep number (monotonic) number of steps of garbage collector, sweep phases (see the Sweep phase description) 16 | ---@field gc_steps_sweepstring number (monotonic) number of steps of garbage collector, sweep phases for strings 17 | ---@field gc_strnum number (non-monotonic) number of allocated string objects 18 | ---@field gc_tabnum number (non-monotonic) number of allocated table objects 19 | ---@field gc_total number (non-monotonic) number of bytes of currently allocated memory (normally equals gc_allocated minus gc_freed) 20 | ---@field gc_udatanum number (non-monotonic) number of allocated udata objects 21 | ---@field jit_mcode_size number (non-monotonic) total size of all allocated machine code areas 22 | ---@field jit_snap_restore number (monotonic) overall number of snap restores, based on the number of guard assertions leading to stopping trace executions (see external Snap tutorial) 23 | ---@field jit_trace_abort number (monotonic) overall number of aborted traces 24 | ---@field jit_trace_num number (non-monotonic) number of JIT traces 25 | ---@field strhash_hit number (monotonic) number of strings being interned because, if a string with the same value is found via the hash, a new one is not created / allocated 26 | ---@field strhash_miss number (monotonic) total number of strings allocations during the platform lifetime 27 | 28 | 29 | ---Get the metrics values into a table. 30 | ---@return misc.metrics 31 | function misc.getmetrics() end 32 | 33 | return misc 34 | -------------------------------------------------------------------------------- /Library/digest.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | --TODO: 4 | 5 | local digest = {} 6 | 7 | ---@return string 8 | function digest.sha512_hex(string) end 9 | 10 | ---@return string 11 | function digest.sha1_hex(string) end 12 | 13 | digest.xxhash64 = {} 14 | function digest.xxhash64.new() end 15 | 16 | ---Returns a number made with consistent hash. 17 | ---@param state number 18 | ---@param bucket number 19 | ---@return number 20 | function digest.guava(state, bucket) end 21 | 22 | ---@param string string 23 | ---@return string 24 | function digest.base64_decode(string) end 25 | 26 | ---@param string string 27 | ---@return string 28 | function digest.sha384(string) end 29 | 30 | digest.xxhash32 = {} 31 | function digest.xxhash32.new() end 32 | 33 | function digest.sha224(string) end 34 | 35 | digest.aes256cbc = {} 36 | function digest.aes256cbc.encrypt(string, key, iv) end 37 | function digest.aes256cbc.decrypt(string, key, iv) end 38 | 39 | 40 | function digest.urandom(integer) end 41 | function digest.sha256_hex(string) end 42 | function digest.sha512(string) end 43 | function digest.crc32_update() end 44 | function digest.sha256(string) end 45 | function digest.md4(string) end 46 | function digest.sha1(string) end 47 | function digest.sha384_hex(string) end 48 | function digest.md4_hex(string) end 49 | 50 | digest.murmur = {} 51 | digest.default_seed = 13 52 | function digest.murmur.new() end 53 | 54 | function digest.pbkdf2_hex() end 55 | 56 | ---Returns base64 encoding from a regular string. 57 | --- 58 | ---nopad – result must not include ‘=’ for padding at the end, 59 | --- 60 | ---nowrap – result must not include line feed for splitting lines after 72 characters, 61 | --- 62 | ---urlsafe – result must not include ‘=’ or line feed, and may contain ‘-‘ or ‘_’ instead of ‘+’ or ‘/’ for positions 62 and 63 in the index table. 63 | ---@param string_variable string 64 | ---@param b64opts? { nopad: boolean, nowrap: boolean, urlsafe: boolean } 65 | ---@return string 66 | function digest.base64_encode(string_variable, b64opts) end 67 | 68 | digest.crc32 = {} 69 | digest.crc32.crc_begin = 4294967295 70 | function digest.crc32.new() end 71 | 72 | function digest.pbkdf2() end 73 | function digest.md5_hex(string) end 74 | function digest.sha224_hex(string) end 75 | function digest.md5(string) end 76 | 77 | 78 | return digest 79 | -------------------------------------------------------------------------------- /Library/config.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | ---@class LoadedConfig 4 | ---@field public box BoxCfg config of box.cfg 5 | ---@field public etcd EtcdCfg config of etcd connector 6 | ---@field public app table application cfg 7 | ---@field public sys config system configuration 8 | 9 | 10 | ---@class EtcdCfg 11 | ---@field endpoints string[] http URI to etcd nodes 12 | ---@field prefix string (required) prefix in etcd of cluster configuration 13 | ---@field instance_name string (required) name of the instance 14 | ---@field login string (optional) username to etcd 15 | ---@field password string (optional) password to etcd 16 | ---@field boolean_auto boolean (default: false) casts each string 'true' and 'false' to boolean 17 | ---@field print_config boolean (default: false) prints loaded etcd config after first fetch 18 | ---@field uuid string (default: nil) if uuid == 'auto' config autogenerates instance_uuid/replicaset_uuid from instance_name 19 | 20 | ---@class config 21 | ---@field public file string path to file with conf.lua 22 | ---@field public mkdir boolean (default:false) flag which enables creation dirs for tarantool application 23 | ---@field public instance_name string name of the instance 24 | ---@field public default_readonly boolean (default: false) sets read_only=default_read_only for `etcd.instance.read_only` if cfg.read_only not specified 25 | ---@field public master_selection_policy string (for ETCD only) sets `etcd.cluster.master` if /clusters/ found otherwise sets `etcd.instance.single` 26 | ---@field public bypass_non_dynamic boolean disables checks for dynamic changes in box.cfg (default: false) 27 | ---@field public tidy_load boolean (default: true) for ETCD only: runs box.cfg{read_only=true} if instance already bootstrapped 28 | ---@field public wrap_box_cfg fun(cfg: BoxCfg) wrapper instead box.cfg performing tidy_load 29 | ---@field public boxcfg fun(cfg: BoxCfg) callback to call instead tidy_load and other logic 30 | ---@field public on_load fun(conf: config, cfg: LoadedConfig) callback to be called each time cfg changes 31 | ---@field public on_before_cfg fun(conf: config, cfg: LoadedConfig) callback to be called right before instance bootstrap (before mkdir) or recovery (once) 32 | ---@field public on_after_cfg fun(conf: config, cfg: LoadedConfig) callback will be called after box completely configured (once) 33 | local conf = {} 34 | 35 | return conf -------------------------------------------------------------------------------- /Library/metrics/http_middleware.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local metrics = { 5 | http_middleware = {} 6 | } 7 | 8 | ---@class CollectorObj 9 | local collector_obj = {} 10 | 11 | 12 | ---Collecting HTTP request latency statistics 13 | ---metrics also provides middleware for monitoring HTTP (set by the http module) latency statistics. 14 | --- 15 | ---Register a collector for the middleware and set it as default. 16 | --- 17 | --- **Possible errors:** 18 | --- 19 | --- * A collector with the same type and name already exists in the registry. 20 | ---@param type_name string collector type: histogram or summary. The default is histogram. 21 | ---@param name string collector name. The default is http_server_request_latency. 22 | ---@param help string collector description. The default is HTTP Server Request Latency. 23 | function metrics.http_middleware.configure_default_collector(type_name, name, help) end 24 | 25 | 26 | 27 | --- Register and return a collector for the middleware. 28 | --- 29 | --- **Possible errors:** 30 | --- 31 | --- * A collector with the same type and name already exists in the registry. 32 | ---@param type_name string collector type: histogram or summary. The default is histogram. 33 | ---@param name string collector name. The default is http_server_request_latency. 34 | ---@param help string? collector description. The default is HTTP Server Request Latency. 35 | ---@return CollectorObj 36 | function metrics.http_middleware.build_default_collector(type_name, name, help) end 37 | 38 | 39 | 40 | ---Set the default collector. 41 | ---@param collector CollectorObj middleware collector object. 42 | function metrics.http_middleware.set_default_collector(collector) end 43 | 44 | --- Return the default collector. If the default collector hasn’t been set yet, 45 | --- register it (with default `http_middleware.build_default_collector(...) parameters)` and set it as default. 46 | ---@return CollectorObj 47 | function metrics.http_middleware.get_default_collector() end 48 | 49 | ---Latency measuring wrap-up for the HTTP ver. 1.x.x handler. Returns a wrapped handler. 50 | ---@param handler function handler function 51 | ---@param collector any middleware collector object. If not set, the default collector is used (like in http_middleware.get_default_collector()). **Usage:** `httpd:route(route, http_middleware.v1(request_handler, collector))` 52 | function metrics.http_middleware.v1(handler, collector) end 53 | 54 | 55 | return metrics.http_middleware 56 | -------------------------------------------------------------------------------- /Library/http/server.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local server = {} 5 | 6 | ---@class ServerHTTPNewOptions 7 | ---@field disable_keepalive string[]? default {} 8 | ---@field idle_timeout number? default 0s 9 | ---@field max_header_size number? default 4096 10 | ---@field header_timeout number? default 100s 11 | ---@field handler fun(ServerHTTP, Request) 12 | ---@field app_dir string? default '.' 13 | ---@field charset string? default 'utf-8' 14 | ---@field cache_templates boolean? default true 15 | ---@field cache_controllers boolean? default true 16 | ---@field cache_static boolean? default true 17 | ---@field log_requests boolean? default true 18 | ---@field log_errors boolean? default true 19 | ---@field display_errors boolean? default false 20 | 21 | ---@param host string 22 | ---@param port number 23 | ---@param options? table 24 | ---@return ServerHTTP 25 | function server.new(host, port, options) end 26 | 27 | 28 | ---@class ServerHTTP 29 | ---@field host string 30 | ---@field port number 31 | ---@field is_run boolean 32 | ---@field routes table 33 | ---@field iroutes any --TODO: type? 34 | ---@field helpers any --TODO: type? 35 | ---@field hooks any --TODO: type? 36 | ---@field cache any --TODO: type? 37 | local server_object = {} 38 | 39 | ---@return ServerHTTP 40 | function server_object:start() end 41 | 42 | function server_object:stop() end 43 | 44 | function server_object:route() end 45 | 46 | function server_object:match() end 47 | 48 | function server_object:helper() end 49 | 50 | function server_object:hook() end 51 | 52 | function server_object:url_for() end 53 | 54 | ---comment 55 | ---@param opts any 56 | ---@param sub any 57 | ---@return ServerHTTP 58 | function server_object:route(opts, sub) end 59 | 60 | 61 | ---@class Request 62 | local request_object = {} 63 | 64 | function request_object:render() end 65 | 66 | function request_object:cookie() end 67 | 68 | function request_object:redirect_to() end 69 | 70 | function request_object:iterate() end 71 | 72 | function request_object:stash() end 73 | 74 | function request_object:url_for() end 75 | 76 | function request_object:content_type() end 77 | 78 | function request_object:request_line() end 79 | 80 | function request_object:read_cached() end 81 | 82 | function request_object:query_param() end 83 | 84 | function request_object:post_param() end 85 | 86 | function request_object:param() end 87 | 88 | function request_object:read() end 89 | 90 | function request_object:json() end 91 | 92 | return server 93 | -------------------------------------------------------------------------------- /Library/box/error.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---When called without arguments, box.error() re-throws whatever the last error was. 5 | ---@return BoxErrorObject 6 | function box.error() end 7 | 8 | ---Throw an error. When called with a Lua-table argument, the code and reason have any user-desired values. The result will be those values. 9 | ---@param err { reason: string, code: number? } reason is description of an error, defined by user; code is numeric code for this error, defined by user 10 | ---@return BoxErrorObject 11 | function box.error(err) end 12 | 13 | ---Throw an error. This method emulates a request error, with text based on one of the pre-defined Tarantool errors defined in the file errcode.h in the source tree. 14 | ---@param code number number of a pre-defined error 15 | ---@param errtext string part of the message which will accompany the error 16 | ---@param ... string part of the message which will accompany the error 17 | function box.error(code, errtext, ...) end 18 | 19 | ---@class BoxErrorObject: ffi.cdata* 20 | ---@field type string (usually ClientError) 21 | ---@field base_type string (usually ClientError) 22 | ---@field code number number of error 23 | ---@field prev? BoxErrorObject previous error 24 | ---@field message any message of error given during `box.error.new` 25 | local box_error_object = {} 26 | 27 | ---@class BoxErrorTrace 28 | ---@field file string Tarantool source file 29 | ---@field line number Tarantool source file line number 30 | 31 | ---@class BoxErrorObjectTable 32 | ---@field code number error’s number 33 | ---@field type string error’s C++ class 34 | ---@field message string error’s message 35 | ---@field prev? BoxErrorObject previous error 36 | ---@field base_type string usually ClientError or CustomError 37 | ---@field custom_type string? present if custom ErrorType was passed 38 | ---@field trace BoxErrorTrace[]? backtrace 39 | 40 | ---@return BoxErrorObjectTable 41 | function box_error_object:unpack() end 42 | 43 | ---Raises error 44 | function box_error_object:raise() end 45 | 46 | ---Instances new BoxError 47 | ---@param code number number of a pre-defined error 48 | ---@param errtxt string part of the message which will accompany the error 49 | ---@return BoxErrorObject 50 | function box.error.new(code, errtxt, ...) end 51 | 52 | ---Instances new BoxError 53 | ---@param err { reason: string, code: number?, type: string? } custom error 54 | ---@return BoxErrorObject 55 | function box.error.new(err) end 56 | 57 | ---@return BoxErrorObject 58 | function box.error.last() end -------------------------------------------------------------------------------- /Library/buffer.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---The buffer module returns a dynamically resizable buffer which is solely for optional use by methods of the net.box module or the msgpack module. 5 | ---@module 'buffer' 6 | 7 | ---@class Buffer 8 | local buffer = {} 9 | 10 | ---@class BufferObject 11 | ---@field buf ffi.cdata* a pointer to the beginning of the buffer 12 | ---@field rpos ffi.cdata* a pointer to the beginning of the range; available for reading data (“read position”) 13 | ---@field wpos ffi.cdata* a pointer to the end of the range; available for reading data, and to the beginning of the range for writing new data (“write position”) 14 | ---@field epos ffi.cdata* a pointer to the end of the range; available for writing new data (“end position”) 15 | local buffer_object = {} 16 | 17 | --- Create a new buffer 18 | ---@param size? integer 19 | ---@return BufferObject 20 | function buffer.ibuf(size) end 21 | 22 | ---Allocate size bytes for buffer_object. 23 | ---@param size integer memory in bytes to allocate 24 | ---@return ffi.cdata* wpos 25 | function buffer_object:alloc(size) end 26 | 27 | ---Return the capacity of the buffer_object. 28 | ---@return integer # wpos - buf 29 | function buffer_object:capacity() end 30 | 31 | ---Check if size bytes are available for reading in buffer_object. 32 | ---@param size integer memory in bytes to check 33 | ---@return ffi.cdata* rpos 34 | function buffer_object:checksize(size) end 35 | 36 | ---Return the size of the range occupied by data. 37 | ---@return integer # rpos - buf 38 | function buffer_object:pos() end 39 | 40 | ---Read `size` bytes from buffer. 41 | ---@param size integer bytes to read 42 | ---@return ffi.cdata* rpos 43 | function buffer_object:read(size) end 44 | 45 | ---Clear the memory slots allocated by buffer_object. 46 | function buffer_object:recycle() end 47 | 48 | ---Clear the memory slots used by buffer_object. 49 | --- 50 | ---This method allows to keep the buffer but remove data from it. 51 | ---It is useful when you want to use the buffer further. 52 | function buffer_object:reset() end 53 | 54 | ---Reserve memory for buffer_object. 55 | ---Check if there is enough memory to write `size` bytes after `wpos`. 56 | ---If not, `epos` shifts until `size` bytes will be available. 57 | ---@param size integer 58 | ---@return ffi.cdata* wpos 59 | function buffer_object:reserve(size) end 60 | 61 | ---Return a range, available for reading data. 62 | ---@return integer # wpos - rpos 63 | function buffer_object:size() end 64 | 65 | ---Return a range for writing data. 66 | ---@return integer # epos - wpos 67 | function buffer_object:unused() end 68 | 69 | return buffer 70 | -------------------------------------------------------------------------------- /Library/json.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | ---The json module provides JSON manipulation routines. 4 | ---It is based on the Lua-CJSON module by Mark Pulford. 5 | ---For a complete manual on Lua-CJSON please read the official documentation. 6 | ---@module 'json' 7 | 8 | local json = {} 9 | 10 | function json.new() 11 | return json 12 | end 13 | 14 | ---@type metatable 15 | json.array_mt = {} 16 | 17 | ---@type metatable 18 | json.map_mt = {} 19 | 20 | ---@class jsonCfg 21 | ---@field encode_max_depth? integer (default: 128) Max recursion depth for encoding 22 | ---@field encode_deep_as_nil? boolean (default: false) A flag saying whether to crop tables with nesting level deeper than cfg.encode_max_depth. Not-encoded fields are replaced with one null. If not set, too deep nesting is considered an error. 23 | ---@field encode_invalid_numbers? boolean (deafult: true) A flag saying whether to enable encoding of NaN and Inf numbers 24 | ---@field encode_number_precision? number (default: 14) Precision of floating point numbers 25 | ---@field encode_load_metatables? boolean (default: true) A flag saying whether the serializer will follow __serialize metatable field 26 | ---@field encode_use_tostring? boolean (default: false) A flag saying whether to use tostring() for unknown types 27 | ---@field encode_invalid_as_nil? boolean (default: false) A flag saying whether use NULL for non-recognized types 28 | ---@field encode_sparse_convert? boolean (default: true) A flag saying whether to handle excessively sparse arrays as maps. See detailed description below. 29 | ---@field encode_sparse_ratio? number (default: 2) 1/encode_sparse_ratio is the permissible percentage of missing values in a sparse array. 30 | ---@field encode_sparse_safe? number (default: 10) A limit ensuring that small Lua arrays are always encoded as sparse arrays (instead of generating an error or encoding as a map) 31 | ---@field decode_invalid_numbers? boolean (default: true) A flag saying whether to enable decoding of NaN and Inf numbers 32 | ---@field decode_save_metatables? boolean (default: true) A flag saying whether to set metatables for all arrays and maps 33 | ---@field decode_max_depth? integer (default: 128) Max recursion depth for decoding 34 | ---Set values that affect the behavior of `json.encode` and `json.decode` 35 | ---@overload fun(cfg: jsonCfg) 36 | json.cfg = {} 37 | 38 | ---Convert a Lua object to a JSON string 39 | ---@param value any either a scalar value or a Lua table value. 40 | ---@param cfg? jsonCfg configuration 41 | ---@return string 42 | function json.encode(value, cfg) end 43 | 44 | ---Convert a JSON string to a Lua object. 45 | ---@param str string a string formatted as JSON. 46 | ---@param cfg? jsonCfg configuration 47 | ---@return any 48 | function json.decode(str, cfg) end 49 | 50 | ---A value comparable to Lua “nil” which may be useful as a placeholder in a tuple. 51 | json.NULL = box.NULL 52 | 53 | return json 54 | -------------------------------------------------------------------------------- /Library/tarantool.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@alias integer64 ffi.cdata* 5 | ---@alias float64 ffi.cdata* 6 | 7 | ---@alias scalar 8 | ---| nil # box.NULL or Lua nil 9 | ---| boolean # true/false 10 | ---| string # lua string 11 | ---| integer # lua number 12 | ---| integer64 # luajit cdata 13 | ---| number # lua number 14 | ---| float64 # luajit cdata 15 | ---| decimal # Tarantool decimal 16 | ---| datetime # Tarantool datetime 17 | ---| interval # Tarantool interval 18 | ---| uuid # Tarantool uuid 19 | 20 | ---@alias tuple_type scalar|compound 21 | 22 | ---@alias map table Tarantool kv map, keys are always strings 23 | ---@alias array tuple_type[] Tarantool array 24 | 25 | ---@alias compound 26 | ---| map # Tarantool map 27 | ---| array # Tarantool array 28 | 29 | ---Convert a string or a Lua number to a 64-bit integer. 30 | ---@param value string|number|ffi.cdata* 31 | ---@return ffi.cdata*|number 32 | function tonumber64(value) end 33 | 34 | ---Allocates new Lua table 35 | ---@param narr number 36 | ---@param nrec number 37 | ---@return table 38 | function table.new(narr, nrec) end 39 | 40 | ---Compare two lua tables 41 | ---Supports __eq metamethod for comparing custom tables with metatables 42 | ---@param a table 43 | ---@param b table 44 | ---@return boolean 45 | function table.equals(a, b) end 46 | 47 | ---Deepcopy lua table (all levels) 48 | ---Supports __copy metamethod for copying custom tables with metatables 49 | ---@param t table 50 | ---@return table deepcopy 51 | function table.deepcopy(t) end 52 | 53 | ---Copy any table (only top level) 54 | ---Supports __copy metamethod for copying custom tables with metatables 55 | ---@param t table 56 | ---@return table copy 57 | function table.copy(t) end 58 | 59 | ---Removes all keys from table 60 | ---@param t table 61 | function table.clear(t) end 62 | 63 | ---@type ffi.cdata* 64 | box.NULL = {} 65 | 66 | ---Parse and execute an arbitrary chunk of Lua code. This function is mainly useful to define and run Lua code without having to introduce changes to the global Lua environment. 67 | ---@param lua_chunk_string string Lua code 68 | ---@param ... any zero or more scalar values which will be appended to 69 | ---@return any ... whatever is returned by the Lua code chunk. 70 | function dostring(lua_chunk_string, ...) end 71 | 72 | ---@class int64_t: ffi.cdata* 73 | ---@operator add(int64_t|number): int64_t 74 | ---@operator sub(int64_t|number): int64_t 75 | ---@operator mul(int64_t|number): int64_t 76 | ---@operator div(int64_t|number): int64_t 77 | ---@operator unm: int64_t 78 | ---@operator mod(int64_t|number): int64_t 79 | ---@operator pow(int64_t|number): int64_t 80 | 81 | ---@class uint64_t: ffi.cdata* 82 | ---@operator add(int64_t|number|uint64_t): uint64_t 83 | ---@operator sub(int64_t|number|uint64_t): uint64_t 84 | ---@operator mul(int64_t|number|uint64_t): uint64_t 85 | ---@operator div(int64_t|number|uint64_t): uint64_t 86 | ---@operator unm: uint64_t 87 | ---@operator mod(int64_t|number|uint64_t): uint64_t 88 | ---@operator pow(int64_t|number|uint64_t): uint64_t 89 | 90 | ---Returns path of the library 91 | ---@param name string 92 | ---@return string? 93 | function package.search(name) end 94 | 95 | function package.searchroot() end 96 | 97 | ---sets root for require 98 | ---@param path ?string 99 | function package.setsearchroot(path) end 100 | -------------------------------------------------------------------------------- /Library/vshard/cfg.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@alias UUID string 5 | 6 | ---@alias replica {uri: string|number|table, listen: string|number|table?, name: string?, zone: string|number?, master: boolean?} 7 | 8 | ---@alias replicaset {replicas: replica[], weight: table?, lock: boolean?, master: UUID?} 9 | 10 | ---@alias discovery_mode 11 | ---| "on" # Discovery fiber works during all the lifetime of the router. Even after all buckets are discovered, it will still come to storages and download their buckets with some big period (DISCOVERY_IDLE_INTERVAL). This is useful if the bucket topology changes often and the number of buckets is not big. The router will keep its route table up to date even when no requests are processed. 12 | ---| "off" # Discovery is disabled completely. 13 | ---| "once" # Discovery starts and finds the locations of all buckets, and then the discovery fiber is terminated. This is good for a large bucket count and for clusters, where rebalancing is rare. 14 | 15 | ---@class VshardCfg: BoxCfg 16 | ---@field sharding table (Default: false) A field defining the logical topology of the sharded Tarantool cluster. 17 | ---@field bucket_count number (Default: 3000) The total number of buckets in a cluster. This number should be several orders of magnitude larger than the potential number of cluster nodes, considering potential scaling out in the foreseeable future. 18 | ---@field weights? table>|boolean (Default: false) A field defining the configuration of relative weights for each zone pair in a replica set. See the Replica weights section. 19 | ---@field shard_index? string|number (Default: "bucket_id") Name or id of a TREE index over the bucket id. Spaces without this index do not participate in a sharded Tarantool cluster and can be used as regular spaces if needed. It is necessary to specify the first part of the index, other parts are optional. 20 | ---@field collect_bucket_garbage_interval? number (DEPRECATED) (Default: 0.5) The interval between garbage collector actions, in seconds. 21 | ---@field collect_lua_garbage? boolean (DEPRECATED) (Default: false) If set to true, the Lua collectgarbage() function is called periodically. 22 | ---@field sync_timeout? number (Default: 1) Timeout to wait for synchronization of the old master with replicas before demotion. Used when switching a master or when manually calling the sync() function. 23 | ---@field rebalancer_disbalance_threshold? number (Default: 1) A maximum bucket disbalance threshold, in percent. The threshold is calculated for each replica set using the following formula: (etalon_bucket_count - real_bucket_count) / etalon_bucket_count * 100 24 | ---@field rebalancer_max_receiving? number (Default: 100) The maximum number of buckets that can be received in parallel by a single replica set. This number must be limited, because when a new replica set is added to a cluster, the rebalancer sends a very large amount of buckets from the existing replica sets to the new replica set. This produces a heavy load on the new replica set. 25 | ---@field rebalancer_max_sending? number (Default: 1) The degree of parallelism for parallel rebalancing. Works for storages only, ignored for routers. The maximum value is 15. 26 | ---@field discovery_mode? discovery_mode (Default: "on") A mode of a bucket discovery fiber: on/off/once 27 | ---@field connection_outdate_delay? number 28 | ---@field failover_ping_timeout? number 29 | ---@field sched_ref_quota? number 30 | ---@field sched_move_quota? number 31 | ---@field zone? string|number 32 | -------------------------------------------------------------------------------- /Library/box/ctl.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class boxCtl 5 | box.ctl = {} 6 | 7 | ---Wait, then choose new replication leader. 8 | ---For synchronous transactions it is possible that a new leader 9 | ---will be chosen but the transactions of the old leader have not been completed. 10 | --- 11 | ---Therefore to finalize the transaction, the function box.ctl.promote() should be called, 12 | ---as mentioned in the notes for leader election. 13 | ---The old name for this function is box.ctl.clear_synchro_queue(). 14 | function box.ctl.promote() end 15 | 16 | ---Since version 2.10.0. 17 | ---Revoke the leader role from the instance. 18 | function box.ctl.demote() end 19 | 20 | 21 | ---Wait until box.info.ro is false. 22 | ---@async 23 | ---@param timeout? number 24 | function box.ctl.wait_rw(timeout) end 25 | 26 | ---Wait until box.info.ro is true. 27 | ---@async 28 | ---@param timeout? number 29 | function box.ctl.wait_ro(timeout) end 30 | 31 | ---Define a trigger for execution before shutdown 32 | ---@param trigger_func? fun() function which will become the trigger function 33 | ---@param old_trigger_func? fun() existing trigger function which will be replaced by trigger-function 34 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 35 | function box.ctl.on_shutdown(trigger_func, old_trigger_func) end 36 | 37 | ---Set a timeout for the on_shutdown trigger. 38 | ---@param timeout? number 39 | function box.ctl.set_on_shutdown_timeout(timeout) end 40 | 41 | ---Since: 3.0.0. 42 | ---Make the instance a bootstrap leader of a replica set. 43 | function box.ctl.make_bootstrap_leader() end 44 | 45 | ---Since version 2.5.3. 46 | ---Check whether the recovery process has finished. 47 | ---Until it has finished, space changes such as `insert` or `update` are not possible. 48 | ---@return boolean is_recovery_finished 49 | function box.ctl.is_recovery_finished() end 50 | 51 | ---@alias box.ctl.recovery_state 52 | --- | "snapshot_recovered" the node has recovered the snapshot files. 53 | --- | "wal_recovered" the node has recovered the WAL files. 54 | --- | "indexes_built" the node has built secondary indexes for memtx spaces. 55 | ---This stage might come before any actual data is recovered. 56 | ---This means that the indexes are available right after the first tuple is recovered. 57 | --- | "synced" the node has synced with enough remote peers. 58 | ---This means that the node changes the state from orphan to running. 59 | 60 | ---@alias box.ctl.on_recover_state_trigger fun(state: box.ctl.recovery_state) 61 | 62 | ---Since: 2.11.0 63 | ---Create a trigger executed on different stages of a node recovery or initial configuration. 64 | ---Note that you need to set the box.ctl.on_recovery_state trigger 65 | ---before the initial box.cfg call. 66 | ---@param trigger box.ctl.on_recover_state_trigger 67 | function box.ctl.on_recovery_state(trigger) end 68 | 69 | ---Since: 2.10.0 70 | ---Create a trigger executed every time the current state of a replicaset 71 | ---node in regard to leader election changes. 72 | ---The current state is available in the box.info.election table. 73 | ---@param trigger function 74 | function box.ctl.on_election(trigger) end 75 | 76 | ---Create a “schema_init trigger”. The trigger-function will be executed when `box.cfg{}` happens for the first time. 77 | ---That is, the `schema_init` trigger is called before the server’s configuration and recovery begins, 78 | ---and therefore `box.ctl.on_schema_init` must be called before `box.cfg` is called. 79 | ---@param trigger_func? fun() function which will become the trigger function 80 | ---@param old_trigger_func? fun() existing trigger function which will be replaced by trigger-function 81 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 82 | function box.ctl.on_schema_init(trigger_func, old_trigger_func) end 83 | -------------------------------------------------------------------------------- /Library/net/box.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | 3 | -- luacheck:ignore 4 | ---@class net.box 5 | ---@field self NetBoxConnection 6 | local m = {} 7 | 8 | ---@class NetBoxConnectOptions 9 | ---@field public wait_connected? boolean|number 10 | ---@field public reconnect_after? number 11 | ---@field public user? string 12 | ---@field public password? string 13 | ---@field public connect_timeout? number 14 | 15 | ---@class NetBoxConnection 16 | ---@field public host string 17 | ---@field public port string 18 | ---@field public state 'active'|'fetch_schema'|'error'|'error_reconnect'|'closed'|'initial'|'graceful_shutdown' 19 | ---@field public error string 20 | ---@field public peer_uuid string|nil 21 | ---@field public _fiber? Fiber 22 | local conn = {} 23 | 24 | ---@class NetBoxFuture 25 | local fut = {} 26 | 27 | ---Checks if result is recieved 28 | ---@return boolean 29 | function fut:is_ready() end 30 | 31 | ---@return table result 32 | ---@return nil, BoxErrorObject 33 | function fut:result() end 34 | 35 | --- Waits for result and returns it or raises box.error.TIMEOUT 36 | ---@async 37 | ---@param timeout number 38 | ---@return table result 39 | function fut:wait_result(timeout) end 40 | 41 | ---discards result 42 | function fut:discard() end 43 | 44 | ---@class NetBoxRequestOptions 45 | ---@field public is_async? boolean 46 | ---@field public timeout? number 47 | 48 | ---@class NetBoxCallOptions 49 | ---@field public timeout number? Timeout of Call 50 | ---@field public is_async boolean? makes request asynchronous 51 | ---@field public return_raw boolean? returns raw msgpack (since version 2.10.0) 52 | ---@field public on_push fun(ctx: any?, msg: any)? callback for each inbound message 53 | ---@field public on_push_ctx any? ctx for on_push callback 54 | 55 | ---@async 56 | ---@param func string 57 | ---@param args? any[] 58 | ---@param opts? NetBoxCallOptions 59 | ---@return ... 60 | function conn:call(func, args, opts) end 61 | 62 | ---@async 63 | ---@param expression string 64 | ---@param args any[]? 65 | ---@param opts NetBoxCallOptions? 66 | ---@return ... 67 | function conn:eval(expression, args, opts) end 68 | 69 | 70 | ---@async 71 | ---@return boolean 72 | function conn:ping() end 73 | 74 | ---@param new_callback fun(conn: NetBoxConnection):nil 75 | ---@param old_callback (fun(conn: NetBoxConnection):nil)|nil 76 | function conn:on_connect(new_callback, old_callback) end 77 | 78 | ---@param new_callback fun(conn: NetBoxConnection):nil 79 | ---@param old_callback (fun(conn: NetBoxConnection):nil)|nil 80 | function conn:on_disconnect(new_callback, old_callback) end 81 | 82 | ---Wait for connection to be active or closed. 83 | ---@async 84 | ---@param wait_timeout number? 85 | ---@return boolean is_connected true when connected, false on failure. 86 | function conn:wait_connected(wait_timeout) end 87 | 88 | ---is a wrapper which sets a timeout for the request that follows it. 89 | ---Since version 1.7.4 this method is deprecated – it is better to pass a timeout value for a method’s {options} parameter. 90 | ---@param request_timeout number 91 | ---@return NetBoxConnection 92 | ---@deprecated 93 | function conn:timeout(request_timeout) end 94 | 95 | ---Close a connection. 96 | ---Connection objects are destroyed by the Lua garbage collector, just like any other objects in Lua, so an explicit destruction is not mandatory. However, since close() is a system call, it is good programming practice to close a connection explicitly when it is no longer needed, to avoid lengthy stalls of the garbage collector. 97 | function conn:close() end 98 | 99 | ---@return boolean 100 | function conn:is_connected() end 101 | 102 | ---Creates connection to Tarantool 103 | ---@async 104 | ---@param endpoint string|table 105 | ---@param options? NetBoxConnectOptions 106 | ---@return NetBoxConnection 107 | function m.connect(endpoint, options) end 108 | 109 | ---Creates connection to Tarantool 110 | ---@async 111 | ---@param endpoint string 112 | ---@param options NetBoxConnectOptions? 113 | ---@return NetBoxConnection 114 | function m.new(endpoint, options) end 115 | 116 | return m 117 | -------------------------------------------------------------------------------- /Library/box/session.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class boxSession: table 5 | box.session = {} 6 | 7 | ---the unique identifier (ID) for the current session. The result can be 0 or -1 meaning there is no session. 8 | ---@return number 9 | function box.session.id() end 10 | 11 | 12 | ---Checks if session exists 13 | ---@param id number 14 | ---@return boolean exists true if the session exists, false if the session does not exist. 15 | function box.session.exists(id) end 16 | 17 | ---This function works only if there is a peer, that is, if a connection has been made to a separate Tarantool instance. 18 | ---@param id? number 19 | ---@return string|nil peer The host address and port of the session peer, for example “127.0.0.1:55457”. 20 | function box.session.peer(id) end 21 | 22 | ---the value of the sync integer constant used in the binary protocol. This value becomes invalid when the session is disconnected. 23 | ---@return number 24 | function box.session.sync() end 25 | 26 | ---@return string user the name of current user 27 | function box.session.user() end 28 | 29 | ---@alias SessionType 30 | ---| "binary" # if the connection was done via the binary protocol 31 | ---| "console" # if the connection was done via the administrative console 32 | ---| "repl" # if the connection was done directly 33 | ---| "applier" # if the action is due to replication, regardless of how the connection was done 34 | ---| "background" # if the action is in a background fiber 35 | 36 | ---@return SessionType 37 | function box.session.type() end 38 | 39 | ---Change Tarantool’s current user – this is analogous to the Unix command su. 40 | ---@param user string name of a target user 41 | ---@param func? string name of a function, or definition of a function 42 | ---@return any? ... result of the function 43 | function box.session.su(user, func) end 44 | 45 | ---@return number uid the user ID of the current user. 46 | function box.session.uid() end 47 | 48 | ---The first case: if the call to box.session.euid() is within a function invoked by box.session.su(user-name, function-to-execute) – in that case, box.session.euid() returns the ID of the changed user (the user who is specified by the user-name parameter of the su function) but box.session.uid() returns the ID of the original user (the user who is calling the su function). 49 | ---The second case: if the call to box.session.euid() is within a function specified with box.schema.func.create(function-name, {setuid= true}) and the binary protocol is in use – in that case, box.session.euid() returns the ID of the user who created “function-name” but box.session.uid() returns the ID of the the user who is calling “function-name”. 50 | ---@return number euid the effective user ID of the current user. 51 | function box.session.euid() end 52 | 53 | ---@type table 54 | ---A Lua table that can hold arbitrary unordered session-specific names and values, which will last until the session ends. 55 | box.session.storage = {} 56 | 57 | ---Define a trigger for execution when a new session is created due 58 | ---@param trigger_func fun() 59 | ---@param old_trigger_func fun() 60 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 61 | function box.session.on_connect(trigger_func, old_trigger_func) end 62 | 63 | ---@param trigger_func fun() 64 | ---@param old_trigger_func fun() 65 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 66 | function box.session.on_disconnect(trigger_func, old_trigger_func) end 67 | 68 | ---@param trigger_func fun() 69 | ---@param old_trigger_func fun() 70 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 71 | function box.session.on_auth(trigger_func, old_trigger_func) end 72 | 73 | ---@param trigger_func fun() 74 | ---@param old_trigger_func fun() 75 | ---@return fun()? removed_trigger If the parameters are (nil, old-trigger-function), then the old trigger is deleted. 76 | function box.session.on_access_denied(trigger_func, old_trigger_func) end 77 | 78 | ---Generate an out-of-band message. 79 | ---@param message tuple_type what to send 80 | ---@param sync? number deprecated 81 | function box.session.push(message, sync) end 82 | -------------------------------------------------------------------------------- /Library/box/schema.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class box.schema 5 | box.schema = {} 6 | 7 | box.schema.space = {} 8 | 9 | ---@class SpaceCreateOptions 10 | ---@field engine? "memtx"|"vinyl" (Default: ‘memtx’) 11 | ---@field field_count? number fixed count of fields: for example if field_count=5, it is illegal to insert a tuple with fewer than or more than 5 fields 12 | ---@field format? boxSpaceFormat 13 | ---@field id? number (Default: last space’s id, +1) unique identifier: users can refer to spaces with the id instead of the name 14 | ---@field if_not_exists? boolean (Default: false) create space only if a space with the same name does not exist already, otherwise do nothing but do not cause an error 15 | ---@field is_local? boolean (Default: false) space contents are replication-local: changes are stored in the write-ahead log of the local node but there is no replication. 16 | ---@field is_sync? boolean (Default: false) any transaction doing a DML request on this space becomes synchronous 17 | ---@field temporary? boolean (Default: false) space contents are temporary: changes are not stored in the write-ahead log and there is no replication. Note regarding storage engine: vinyl does not support temporary spaces. 18 | ---@field user? string (Default: current user’s name) name of the user who is considered to be the space’s owner for authorization purposes 19 | ---@field constraint? table|string the constraints that space tuples must satisfy. 20 | ---@field foreign_key? table the foreign keys for space fields. 21 | 22 | ---@param space_name string 23 | ---@param options SpaceCreateOptions|nil 24 | ---@return boxSpaceObject 25 | function box.schema.space.create(space_name, options) end 26 | 27 | ---@deprecated 28 | ---@param space_name string 29 | ---@param options SpaceCreateOptions|nil 30 | ---@return boxSpaceObject 31 | function box.schema.create_space(space_name, options) end 32 | 33 | box.schema.user = {} 34 | 35 | ---@alias boxSchemaGrantObjectType 36 | ---| "universe" 37 | ---| "space" 38 | ---| "function" 39 | ---| "sequence" 40 | ---| "role" 41 | 42 | ---@class boxSchemaGrantOptions 43 | ---@field if_not_exists? boolean 44 | ---@field grantor? string 45 | 46 | ---Grant privileges to a user or to another role. 47 | ---@param user_name string 48 | ---@param priv_or_role string 49 | ---@param object_type? boxSchemaGrantObjectType 50 | ---@param object_name? string 51 | ---@param options? boxSchemaGrantOptions 52 | function box.schema.user.grant(user_name, priv_or_role, object_type, object_name, options) end 53 | 54 | box.schema.func = {} 55 | 56 | ---@class box.schema.func.create.options 57 | ---@field exports? string[] (Default: {'LUA'}) Specify the languages that can call the function. 58 | ---@field language? 'LUA'|'SQL_EXPR'|'C' (Default: 'LUA') Specify the function language. 59 | ---@field body? string Specify a function body. 60 | ---@field param_list? string[] Specify the Lua type names for each parameter of the function. 61 | ---@field returns? string Specify the Lua type name for a function’s return value. 62 | ---@field if_not_exists? boolean (Default: false) Specify whether there should be no error if the function already exists. 63 | ---@field setuid? boolean (Default: false) Make Tarantool treat the function’s caller as the function’s creator, with full privileges. 64 | ---@field is_sandboxed? boolean (Default: false) Whether the function should be executed in an isolated environment. 65 | ---@field is_deterministic? boolean (Default: false) Specify whether a function should be deterministic. 66 | ---@field is_multikey? boolean (Default: false) If `true` is set in the function definition for a functional index, the function returns multiple keys. 67 | ---@field takes_raw_args? boolean (Default: false) If set to `true` the function arguments are passed being wrapped in a MsgPack object 68 | 69 | ---Create a function 70 | ---@param func_name string 71 | ---@param function_options? box.schema.func.create.options 72 | function box.schema.func.create(func_name, function_options) end 73 | 74 | ---Return true if a function tuple exists; return false if a function tuple does not exist. 75 | ---@param func_name string 76 | function box.schema.func.call(func_name) end 77 | 78 | ---Reload a C module with all its functions without restarting the server. 79 | ---@param module_name? string the name of the module to reload 80 | function box.schema.func.reload(module_name) end 81 | 82 | ---Drop a function tuple. 83 | ---@param func_name string 84 | ---@param options? { if_exists?: boolean } 85 | function box.schema.func.drop(func_name, options) end 86 | 87 | ---Return true if a function tuple exists; return false if a function tuple does not exist. 88 | ---@param func_name string 89 | function box.schema.func.exist(func_name) end 90 | 91 | return box.schema 92 | -------------------------------------------------------------------------------- /Library/datetime.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | --TODO: 4 | 5 | local datetime = {} 6 | 7 | ---@class datetime: ffi.cdata* 8 | ---@field nsec integer (Default: 0) (usec, msec) Fractional part of the last second. You can specify either nanoseconds (nsec), or microseconds (usec), or milliseconds (msec). Specifying two of these units simultaneously or all three ones lead to an error 9 | ---@field sec integer (Default: 0) Seconds. Value range: 0 - 60 10 | ---@field min integer (Default: 0) Minutes. Value range: 0 - 59 11 | ---@field hour integer (Default: 0) Hours. Value range: 0 - 23 12 | ---@field day integer (Default: 1) Day number. Value range: 1 - 31. The special value -1 generates the last day of a particular month (see example below) 13 | ---@field month integer (Default: 1) Month number. Value range: 1 - 12 14 | ---@field year integer (Default: 1970) Year. 15 | ---@field timestamp integer (Default: 0) Timestamp, in seconds. Similar to the Unix timestamp, but can have a fractional part which is converted in nanoseconds in the resulting datetime object. If the fractional part for the last second is set via the nsec, usec, or msec units, the timestamp value should be integer otherwise an error occurs. Timestamp is not allowed if you already set time and/or date via specific units, namely, sec, min, hour, day, month, and year 16 | ---@field tzoffset integer (Default: 0) Time zone offset from UTC, in minutes. If both tzoffset and tz are specified, tz has the preference and the tzoffset value is ignored 17 | ---@field tz string Time zone name according to the tz database 18 | ---@field wday integer Days since the beginning of the week 19 | ---@field yday integer Days since the beginning of the year 20 | ---@field isdst boolean Is the DST (Daylight saving time) applicable for the date. Boolean. 21 | local datetime_obj = {} 22 | 23 | --- Create a datetime object from a table of time units. 24 | --- 25 | ---**Default values:** 26 | --- 27 | --- * nsec: 0 28 | --- * sec: 0 29 | --- * min: 0 30 | --- * hour: 1 31 | --- * day: 1 32 | --- * year: 1970 33 | --- * timestamp: 0 34 | --- * tzoffset: 0 35 | --- * tz: nil 36 | ---@param units? { nsec?: integer, sec?: integer, min?: integer, hour?: integer, day?: integer, year?: integer, timestamp?: integer, tzoffset?: integer, tz?: string} 37 | ---@return datetime datetime_obj 38 | function datetime.new(units) end 39 | 40 | --- Convert the standard presentation of a datetime object into a formatted string 41 | ---@param input_string? string (Default: '%FT%T.%f%z') String consisting of zero or more conversion specifications and ordinary characters 42 | ---@return string 43 | function datetime_obj:format(input_string) end 44 | 45 | --- Convert the information from a datetime object into the table format 46 | function datetime_obj:totable() end 47 | 48 | --- Update the field values in the existing datetime object 49 | function datetime_obj:set() end 50 | 51 | --- Convert an input string with the date and time information into a datetime object 52 | function datetime_obj:parse() end 53 | 54 | --- Modify an existing datetime object by adding values of the input arguments 55 | function datetime_obj:add() end 56 | 57 | --- Modify an existing datetime object by subtracting values of the input arguments 58 | function datetime_obj:sub() end 59 | 60 | datetime.interval = {} 61 | 62 | ---@class interval: ffi.cdata* 63 | ---@field nsec integer (Default: 0) (usec, msec) Fractional part of the last second. You can specify either nanoseconds (nsec), or microseconds (usec), or milliseconds (msec). Specifying two of these units simultaneously or all three ones lead to an error 64 | ---@field sec integer (Default: 0) Seconds 65 | ---@field min integer (Default: 0) Minutes 66 | ---@field hour integer (Default: 0) Hours 67 | ---@field day integer (Default: 0) Day number 68 | ---@field week integer (Default: 0) Week number 69 | ---@field month integer (Default: 0) Month number 70 | ---@field year integer (Default: 0) Year 71 | ---@field adjust string (Default: 'none') Defines how to round days in a month after an arithmetic operation 72 | ---@operator add(interval): interval 73 | ---@operator sub(interval): interval 74 | local interval_obj = {} 75 | 76 | --- Create an interval object from a table of time units 77 | --- 78 | ---**Default values:** 79 | --- 80 | --- * nsec: 0 81 | --- * sec: 0 82 | --- * min: 0 83 | --- * hour: 1 84 | --- * day: 1 85 | --- * week: 0 86 | --- * month: 0 87 | --- * year: 0 88 | --- * adjust: 'none' 89 | ---@param units? { nsec?: integer, sec?: integer, min?: integer, hour?: integer, day?: integer, week?: integer, month?: integer, year?: integer, adjust: string} 90 | ---@return interval interval_obj 91 | function datetime.interval.new(units) end 92 | 93 | --- Convert the information from an interval object into the table format 94 | function interval_obj:totable() end 95 | 96 | return datetime 97 | -------------------------------------------------------------------------------- /Library/vshard/replicaset.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class Replica 5 | ---@field uri string 6 | ---@field name string 7 | ---@field uuid UUID 8 | ---@field conn NetBoxConnection 9 | ---@field zone number 10 | ---@field next_by_priority Replica replica object of the same type 11 | ---@field weight number 12 | ---@field down_ts number timestamp of disconnect from the replica 13 | ---@field backoff_ts number timestamp when was sent into backoff state 14 | ---@field backoff_err table error object caused the backoff 15 | ---@field net_timeout number current network timeout for calls doubled on each network fail until max value, and reset to minimal value on each success 16 | ---@field net_sequential_ok number count of sequential success requests to the replica 17 | ---@field net_sequential_fail number count of sequential failed requests to the replica 18 | ---@field is_outdated nil|true 19 | 20 | ---@class Replicaset 21 | ---@field replicas Replica[] 22 | ---@field master Replica Master server from the array above 23 | ---@field master_cond fiber.cond Condition variable signaled when the replicaset finds or changes its master 24 | ---@field is_auto_master boolean true when is configured to find the master on its own 25 | ---@field replica Replica nearest available replica object 26 | ---@field balance_i number index of a next replica in priority_list to use for a load-balanced request 27 | ---@field replica_up_ts number timestamp updated on each attempt to connect to the nearest replica, and on each connect event 28 | ---@field uuid UUID replicaset_uuid 29 | ---@field weight number 30 | ---@field priority_list Replica[] list of replicas, sorted by weight asc 31 | ---@field etalon_bucket_count number bucket count, that must be stored on this replicaset to reach the balance in a cluster 32 | ---@field is_outdated true|nil 33 | local replicaset_object = {} 34 | 35 | --- Call a function on a nearest available master (distances are defined using replica.zone and `cfg.weights` matrix) with specified arguments 36 | ---The `replicaset_object:call` method is similar to `replicaset_object:callrw` 37 | ---@param function_name string A function to execute 38 | ---@param argument_list? table An array of the function’s arguments 39 | ---@param options? NetBoxCallOptions net.box options. `timeout` - if the router cannot identify a shard with the specified bucket_id, the operation will be repeated until the timeout is reached. 40 | ---@return any # Result of function_name on success or nil otherwise 41 | ---@return ShardingErrors? # Error on failure 42 | function replicaset_object:call(function_name, argument_list, options) end 43 | 44 | ---Call a function on the nearest available replica (distances are defined using `replica.zone` and `cfg.weights` matrix) with specified arguments. It is recommended to use `replicaset_object:callro()` for calling only read-only functions, as the called functions can be executed not only on a master, but also on replicas 45 | ---@param function_name string A function to execute 46 | ---@param argument_list? table An array of the function’s arguments 47 | ---@param options? NetBoxCallOptions net.box options. `timeout` - if the router cannot identify a shard with the specified bucket_id, the operation will be repeated until the timeout is reached. 48 | ---@return any # Result of function_name on success or nil otherwise 49 | ---@return ShardingErrors? # Error on failure 50 | function replicaset_object:callro(function_name, argument_list, options) end 51 | 52 | ---Call a function on a nearest available master (distances are defined using `replica.zone` and `cfg.weights` matrix) with a specified arguments 53 | ---The `replicaset_object:callrw` method is similar to `replicaset_object:call` 54 | ---@param function_name string A function to execute 55 | ---@param argument_list? table An array of the function’s arguments 56 | ---@param options? NetBoxCallOptions net.box options. `timeout` - if the router cannot identify a shard with the specified bucket_id, the operation will be repeated until the timeout is reached. 57 | ---@return any # Result of function_name on success or nil otherwise 58 | ---@return ShardingErrors? # Error on failure 59 | function replicaset_object:callrw(function_name, argument_list, options) end 60 | 61 | ---Call a function on the nearest available replica (distances are defined using `replica.zone` and `cfg.weights` matrix) with specified arguments, with preference for a replica rather than a master (similar to calling `vshard.router.call` with `prefer_replica = true`). It is recommended to use `replicaset_object:callre()` for calling only read-only functions, as the called function can be executed not only on a master, but also on replicas 62 | ---@param function_name string A function to execute 63 | ---@param argument_list? table An array of the function’s arguments 64 | ---@param options? NetBoxCallOptions net.box options. `timeout` - if the router cannot identify a shard with the specified bucket_id, the operation will be repeated until the timeout is reached. 65 | ---@return any # Result of function_name on success or nil otherwise 66 | ---@return ShardingErrors? # Error on failure 67 | function replicaset_object:callre(function_name, argument_list, options) end 68 | -------------------------------------------------------------------------------- /Library/string.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---Split `input_string` into one or more output strings in a table. 5 | --- 6 | ---The places to split are the places where `split_string` occurs. 7 | ---@param input_string string the string to split 8 | ---@param split_string? string the string to find within `input_string`. Default = space. 9 | ---@param max? integer maximum number of delimiters to process counting from the beginning of the input string. Result will contain max + 1 parts maximum. 10 | ---@return string[] # table of strings that were split from `input_string` 11 | ---@nodiscard 12 | function string.split(input_string, split_string, max) end 13 | 14 | ---Return the string left-justified in a string of length width. 15 | ---@param input_string string the string to left-justify 16 | ---@param width integer the width of the string after left-justifying 17 | ---@param char? string a single character, default = 1 space 18 | ---@return string # left-justified string (unchanged if width <= string length) 19 | ---@nodiscard 20 | function string.ljust(input_string, width, char) end 21 | 22 | ---Return the string right-justified in a string of length width. 23 | ---@param input_string string the string to right-justify 24 | ---@param width integer the width of the string after right-justifying 25 | ---@param char? string a single character, default = 1 space 26 | ---@return string # right-justified string (unchanged if width <= string length) 27 | ---@nodiscard 28 | function string.rjust(input_string, width, char) end 29 | 30 | ---Center string in a field of given width. 31 | ---Prepend and append "(width - len(input_string))/2" chars to given string. 32 | ---@param input_string string original string 33 | ---@param width integer width at least bytes to be returned 34 | ---@param char? string a single character, default = 1 space 35 | ---@return string # centered string 36 | ---@nodiscard 37 | function string.center(input_string, width, char) end 38 | 39 | ---Return `true` if `input_string` starts with `start_string`, otherwise return `false`. 40 | --- 41 | ---`start_pos` and `end_pos` may be negative, meaning the position should be calculated from the end of the string. 42 | ---@param input_string string the string where `start_string` should be looked for 43 | ---@param start_string string the string to look for 44 | ---@param start_pos? integer position: where to start looking within `input_string` 45 | ---@param end_pos? integer position: where to end looking within `input_string` 46 | ---@return boolean 47 | ---@nodiscard 48 | function string.startswith(input_string, start_string, start_pos, end_pos) end 49 | 50 | ---Return `true` if `input_string` ends with `end_string`, otherwise return `false`. 51 | --- 52 | ---`start_pos` and `end_pos` may be negative, meaning the position should be calculated from the end of the string. 53 | ---@param input_string string the string where `end_string` should be looked for 54 | ---@param end_string string the string to look for 55 | ---@param start_pos? integer position: where to start looking within `input_string` 56 | ---@param end_pos? integer position: where to end looking within `input_string` 57 | ---@return boolean 58 | ---@nodiscard 59 | function string.endswith(input_string, end_string, start_pos, end_pos) end 60 | 61 | ---Return the hexadecimal value of the input string. 62 | ---@param input_string string the string where `start_string` should be looked for 63 | ---@return string # hexadecimal, 2 hex-digit characters for each input character 64 | ---@nodiscard 65 | function string.hex(input_string) end 66 | 67 | ---Given a string containing pairs of hexadecimal digits, return a string with one byte for each pair. 68 | ---This is the reverse of `string.hex()`. 69 | ---The `hexadecimal_input_string` must contain an even number of hexadecimal digits. 70 | ---@param hexadecimal_input_string string string with pairs of hexadecimal digits 71 | ---@return string # string with one byte for each pair of hexadecimal digits 72 | ---@nodiscard 73 | function string.fromhex(hexadecimal_input_string) end 74 | 75 | ---Return the value of the `input_string`, after removing characters on the left. 76 | ---The optional `list_of_characters` parameter is a set not a sequence, 77 | ---so `string.lstrip(...,'ABC')` does not mean strip `'ABC'`, it means strip `'A'` or `'B'` or `'C'`. 78 | ---@param input_string string the string to process 79 | ---@param list_of_characters? string what characters can be stripped. Default = space. 80 | ---@return string # result after stripping characters from input string 81 | ---@nodiscard 82 | function string.lstrip(input_string, list_of_characters) end 83 | 84 | ---Return the value of the `input_string`, after removing characters on the right. 85 | ---The optional `list_of_characters` parameter is a set not a sequence, 86 | ---so `string.rstrip(...,'ABC')` does not mean strip `'ABC'`, it means strip `'A'` or `'B'` or `'C'`. 87 | ---@param input_string string the string to process 88 | ---@param list_of_characters? string what characters can be stripped. Default = space. 89 | ---@return string # result after stripping characters from input string 90 | ---@nodiscard 91 | function string.rstrip(input_string, list_of_characters) end 92 | 93 | ---Return the value of the `input_string`, after removing characters on the left and the right. 94 | ---The optional `list_of_characters` parameter is a set not a sequence, 95 | ---so `string.strip(...,'ABC')` does not mean strip `'ABC'`, it means strip `'A'` or `'B'` or `'C'`. 96 | ---@param input_string string the string to process 97 | ---@param list_of_characters? string what characters can be stripped. Default = space. 98 | ---@return string # result after stripping characters from input string 99 | ---@nodiscard 100 | function string.strip(input_string, list_of_characters) end 101 | -------------------------------------------------------------------------------- /Library/errno.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class errno:table 5 | ---@field E2BIG number Argument list too long (POSIX.1-2001). 6 | ---@field EACCES number Permission denied (POSIX.1-2001). 7 | ---@field EADDRINUSE number Address already in use (POSIX.1-2001). 8 | ---@field EADDRNOTAVAIL number Address not available (POSIX.1-2001). 9 | ---@field EAFNOSUPPORT number Address family not supported (POSIX.1-2001). 10 | ---@field EAGAIN number Resource temporarily unavailable (may be the same value as EWOULDBLOCK) (POSIX.1-2001). 11 | ---@field EALREADY number Connection already in progress (POSIX.1-2001). 12 | ---@field EBADF number Bad file descriptor (POSIX.1-2001). 13 | ---@field EBADMSG number Bad message (POSIX.1-2001). 14 | ---@field EBUSY number Device or resource busy (POSIX.1-2001). 15 | ---@field ECANCELED number Operation canceled (POSIX.1-2001). 16 | ---@field ECHILD number No child processes (POSIX.1-2001). 17 | ---@field ECONNABORTED number Connection aborted (POSIX.1-2001). 18 | ---@field ECONNREFUSED number Connection refused (POSIX.1-2001). 19 | ---@field ECONNRESET number Connection reset (POSIX.1-2001). 20 | ---@field EDEADLK number Resource deadlock avoided (POSIX.1-2001). 21 | ---@field EDESTADDRREQ number Destination address required (POSIX.1-2001). 22 | ---@field EDOM number Mathematics argument out of domain of function (POSIX.1, C99). 23 | ---@field EDQUOT number Disk quota exceeded (POSIX.1-2001). 24 | ---@field EEXIST number File exists (POSIX.1-2001). 25 | ---@field EFAULT number Bad address (POSIX.1-2001). 26 | ---@field EFBIG number File too large (POSIX.1-2001). 27 | ---@field EHOSTUNREACH number Host is unreachable (POSIX.1-2001). 28 | ---@field EIDRM number Identifier removed (POSIX.1-2001). 29 | ---@field EILSEQ number Invalid or incomplete multibyte or wide character (POSIX.1, C99). 30 | ---@field EINPROGRESS number Operation in progress (POSIX.1-2001). 31 | ---@field EINTR number Interrupted function call (POSIX.1-2001); see signal(7). 32 | ---@field EINVAL number Invalid argument (POSIX.1-2001). 33 | ---@field EIO number Input/output error (POSIX.1-2001). 34 | ---@field EISCONN number Socket is connected (POSIX.1-2001). 35 | ---@field EISDIR number Is a directory (POSIX.1-2001). 36 | ---@field ELOOP number Too many levels of symbolic links (POSIX.1-2001). 37 | ---@field EMFILE number Too many open files (POSIX.1-2001). Commonly caused by exceeding the RLIMIT_NOFILE resource limit described in getrlimit(2). Can also be caused by exceeding the limit specified in /proc/sys/fs/nr_open. 38 | ---@field EMLINK number Too many links (POSIX.1-2001). 39 | ---@field EMSGSIZE number Message too long (POSIX.1-2001). 40 | ---@field EMULTIHOP number Multihop attempted (POSIX.1-2001). 41 | ---@field ENAMETOOLONG number Filename too long (POSIX.1-2001). 42 | ---@field ENETDOWN number Network is down (POSIX.1-2001). 43 | ---@field ENETRESET number Connection aborted by network (POSIX.1-2001). 44 | ---@field ENETUNREACH number Network unreachable (POSIX.1-2001). 45 | ---@field ENFILE number Too many open files in system (POSIX.1-2001). On Linux, this is probably a result of encountering the /proc/sys/fs/file-max limit (see proc(5)). 46 | ---@field ENOBUFS number No buffer space available (POSIX.1 (XSI STREAMS option)). 47 | ---@field ENODATA number The named attribute does not exist, or the process has no access to this attribute; see xattr(7). 48 | ---@field ENODEV number No such device (POSIX.1-2001). 49 | ---@field ENOENT number No such file or directory (POSIX.1-2001). 50 | ---@field ENOEXEC number Exec format error (POSIX.1-2001). 51 | ---@field ENOLCK number No locks available (POSIX.1-2001). 52 | ---@field ENOLINK number Link has been severed (POSIX.1-2001). 53 | ---@field ENOMEM number Not enough space/cannot allocate memory (POSIX.1-2001). 54 | ---@field ENOMSG number No message of the desired type (POSIX.1-2001). 55 | ---@field ENOPROTOOPT number Protocol not available (POSIX.1-2001). 56 | ---@field ENOSPC number No space left on device (POSIX.1-2001). 57 | ---@field ENOSR number No STREAM resources (POSIX.1 (XSI STREAMS option)). 58 | ---@field ENOSTR number Not a STREAM (POSIX.1 (XSI STREAMS option)). 59 | ---@field ENOSYS number Function not implemented (POSIX.1-2001). 60 | ---@field ENOTCONN number The socket is not connected (POSIX.1-2001). 61 | ---@field ENOTDIR number Not a directory (POSIX.1-2001). 62 | ---@field ENOTEMPTY number Directory not empty (POSIX.1-2001). 63 | ---@field ENOTSOCK number Not a socket (POSIX.1-2001). 64 | ---@field ENOTSUP number Operation not supported (POSIX.1-2001). 65 | ---@field ENOTTY number Inappropriate I/O control operation (POSIX.1-2001). 66 | ---@field ENXIO number No such device or address (POSIX.1-2001). 67 | ---@field EOPNOTSUPP number Operation not supported on socket (POSIX.1-2001). 68 | ---@field EOVERFLOW number Value too large to be stored in data type (POSIX.1-2001). 69 | ---@field EPERM number Operation not permitted (POSIX.1-2001). 70 | ---@field EPIPE number Broken pipe (POSIX.1-2001). 71 | ---@field EPROTO number Protocol error (POSIX.1-2001). 72 | ---@field EPROTONOSUPPORT number Protocol not supported (POSIX.1-2001). 73 | ---@field EPROTOTYPE number Protocol wrong type for socket (POSIX.1-2001). 74 | ---@field ERANGE number Result too large (POSIX.1, C99). 75 | ---@field EROFS number Read-only filesystem (POSIX.1-2001). 76 | ---@field ESPIPE number Invalid seek (POSIX.1-2001). 77 | ---@field ESRCH number No such process (POSIX.1-2001). 78 | ---@field ESTALE number Stale file handle (POSIX.1-2001). 79 | ---@field ETIME number Timer expired (POSIX.1 (XSI STREAMS option)). 80 | ---@field ETIMEDOUT number Connection timed out (POSIX.1-2001). 81 | ---@field ETXTBSY number Text file busy (POSIX.1-2001). 82 | ---@field EWOULDBLOCK number Operation would block (may be same value as EAGAIN) (POSIX.1-2001). 83 | ---@field EXDEV number Improper link (POSIX.1-2001). 84 | ---@operator call: number 85 | local errno = {} 86 | 87 | ---Return a string, given an error number. 88 | ---@param code number? 89 | ---@return string 90 | function errno.strerror(code) end 91 | 92 | 93 | return errno 94 | -------------------------------------------------------------------------------- /Library/box.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class box 5 | ---@field cfg BoxCfg 6 | box = {} 7 | 8 | ---returns whether fiber is in transaction 9 | ---@return boolean is_in_txn 10 | function box.is_in_txn() end 11 | 12 | ---@param box_cfg BoxCfg 13 | ---@return nil 14 | function box.cfg(box_cfg) end 15 | 16 | ---@alias txn_isolation 17 | ---| 'best-effort' 18 | ---| 'read-committed' 19 | ---| 'read-confirmed' 20 | ---| 'linearizable' 21 | 22 | ---@class begin_options 23 | ---@field txn_isolation? txn_isolation the transaction isolation level (default: best-effort) 24 | ---@field timeout? number a timeout (in seconds), after which the transaction is rolled back 25 | 26 | --- Begin the transaction. Disable implicit yields until the transaction ends. 27 | --- Signal that writes to the write-ahead log will be deferred until the transaction ends. 28 | --- In effect the fiber which executes box.begin() is starting an “active multi-request transaction”, blocking all other fibers 29 | --- 30 | --- **Possible errors:** 31 | --- 32 | --- - Error if this operation is not permitted because there is already an active transaction. 33 | --- 34 | --- - Error if for some reason memory cannot be allocated. 35 | ---@param opts? begin_options 36 | function box.begin(opts) end 37 | 38 | --- End the transaction, and make all its data-change operations permanent. 39 | --- 40 | --- **Possible errors:** 41 | --- 42 | --- - Error and abort the transaction in case of a conflict. 43 | --- 44 | --- - Error if the operation fails to write to disk. 45 | --- 46 | --- - Error if for some reason memory cannot be allocated. 47 | function box.commit() end 48 | 49 | --- End the transaction, but cancel all its data-change operations. 50 | --- An explicit call to functions outside box.space that always yield, such as fiber.sleep() or fiber.yield(), will have the same effect. 51 | function box.rollback() end 52 | 53 | --TODO: BoxError не хватает корректной обработки 54 | --- Return a descriptor of a savepoint (type = table), which can be used later by box.rollback_to_savepoint(savepoint). 55 | --- Savepoints can only be created while a transaction is active, and they are destroyed when a transaction ends 56 | --- 57 | --- **Possible errors:** 58 | --- 59 | --- * Error if for some reason memory cannot be allocated. 60 | ---@return table|BoxErrorObject savepoint 61 | function box.savepoint() end 62 | 63 | --- Do not end the transaction, but cancel all its data-change and box.savepoint() operations that were done after the specified savepoint. 64 | --- 65 | --- **Possible errors:** 66 | --- 67 | --- * Error if the savepoint does not exist. 68 | --- @param savepoint table 69 | --- @return BoxErrorObject error 70 | function box.rollback_to_savepoint(savepoint) end 71 | 72 | ---#if _TARANTOOL<2.10.0 73 | 74 | --- Execute a function, acting as if the function starts with an implicit box.begin() and ends with an implicit box.commit() 75 | ---if successful, or ends with an implicit box.rollback() if there is an error. 76 | --- 77 | --- **Possible errors:** 78 | --- * Error and abort the transaction in case of a conflict. 79 | --- * Error if the operation fails to write to disk. 80 | --- * Error if for some reason memory cannot be allocated. 81 | ---@param tx_function fun(...: any): ... 82 | ---@param ... any 83 | ---@return ...? The result of the function passed to atomic() as an argument. 84 | function box.atomic(tx_function, ...) end 85 | ---#else 86 | 87 | ---Starting with 2.10.1 88 | ---@param opts { txn_isolation: txn_isolation } 89 | ---@param tx_function fun(...: any): ...? 90 | ---@param ... any 91 | ---@return ...? The result of the function passed to atomic() as an argument. 92 | function box.atomic(opts, tx_function, ...) end 93 | ---#end 94 | 95 | ---@alias onCommitIterator fun():(number, box.tuple|nil, box.tuple|nil, number) request_id, old_tuple, new_tuple, space_id 96 | 97 | ---@alias onCommitTriggerFunc fun(iterator: onCommitIterator?) 98 | 99 | ---@param trigger_func onCommitTriggerFunc 100 | ---@param old_trigger_func? onCommitTriggerFunc 101 | function box.on_commit(trigger_func, old_trigger_func) end 102 | 103 | ---@alias boxIterator boxTableIterator 104 | 105 | ---@class boxTableIterator 106 | ---@field iterator? "GE"|"GT"|"LT"|"LE"|"EQ"|"REQ"|"BITS_ALL_NOT_SET"|"BITS_ALL_SET"|"BITS_ANY_SET"|"OVERLAPS"|"NEIGHBOR"|"ALL"|boxIndexIterator 107 | ---@field after string|nil? position in index (starting from Tarantool ≥ 2.11) 108 | 109 | ---@enum boxIndexIterator 110 | box.index = { 111 | EQ = 0, 112 | REQ = 1, 113 | ALL = 2, 114 | LT = 3, 115 | LE = 4, 116 | GE = 5, 117 | GT = 6, 118 | BITS_ALL_SET = 7, 119 | BITS_ANY_SET = 8, 120 | BITS_ALL_NOT_SET = 9, 121 | OVERLAPS = 10, 122 | NEIGHBOR = 11, 123 | } 124 | 125 | ---Execute a function, provided it has not been executed before. 126 | ---@param key string a value that will be checked 127 | ---@param fnc fun(...) function to be executed 128 | ---@vararg any ... arguments to the function 129 | function box.once(key, fnc, ...) end 130 | 131 | ---@async 132 | ---Creates new snapshot of the data and executes checkpoint.gc process 133 | function box.snapshot() end 134 | 135 | ---@class box.watcher 136 | local watcher = {} 137 | 138 | ---unregisters the watcher 139 | function watcher:unregister() end 140 | 141 | ---@since 2.10.0 142 | ---Update the value of a particular key and notify all key watchers of the update. 143 | ---@param key string 144 | ---@param value any 145 | function box.broadcast(key, value) end 146 | 147 | ---2.10.0 148 | ---Subscribe to events broadcast by a local host. 149 | ---@param key string 150 | ---@param func fun(key: string, value: any) 151 | ---@return box.watcher 152 | function box.watch(key, func) end 153 | 154 | ---@since 2.10.0 155 | ---Subscribe to events broadcast by a local host. 156 | --- 157 | ---Automatically unsubscribe when event is delivered 158 | ---@param key string 159 | ---@param func fun(key: string, value: any) 160 | ---@return box.watcher 161 | function box.watch_once(key, func) end 162 | 163 | return box 164 | -------------------------------------------------------------------------------- /Library/vshard/storage.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class Storage 5 | local storage = {} 6 | 7 | ---@param cfg VshardCfg 8 | ---@param name string 9 | function storage.cfg(cfg, name) end 10 | 11 | function storage.info() end 12 | 13 | function storage.call(bucket_id, mode, function_name, argument_list) end 14 | 15 | ---Wait until the dataset is synchronized on replicas 16 | ---@param timeout? number 17 | ---@return boolean?, VshardError? 18 | function storage.sync(timeout) end 19 | 20 | ---Pin a bucket to a replicaset. Pinned bucket can not be sent 21 | ---even if is breaks the cluster balance. 22 | ---@param bucket_id integer Identifier of a bucket to pin. 23 | ---@return boolean?, VshardError? 24 | function storage.bucket_pin(bucket_id) end 25 | 26 | ---Return a pinned bucket back into active state. 27 | ---@param bucket_id integer Identifier of a bucket to unpin. 28 | ---@return boolean?, VshardError? 29 | function storage.bucket_unpin(bucket_id) end 30 | 31 | ---Ref shortcut for an obscure mode. 32 | ---@param bucket_id integer Identifier of a bucket to ref. 33 | ---@param mode 'read'|'write' 34 | function storage.bucket_ref(bucket_id, mode) end 35 | 36 | ---Take Read-Only reference on the bucket identified by 37 | ---`bucket_id`. Under such reference a bucket can not be deleted 38 | ---from the storage. Its transfer still can start, but can not 39 | ---finish until ref == 0. 40 | ---@param bucket_id integer Identifier of a bucket to ref. 41 | ---@return boolean?, VshardError? 42 | function storage.bucket_refro(bucket_id) end 43 | 44 | ---Same as bucket_refro, but more strict - the bucket transfer 45 | ---can not start until a bucket has such refs. And if the bucket 46 | ---is already scheduled for transfer then it can not take new RW 47 | ---refs. The rebalancer waits until all RW refs gone and starts transfer. 48 | ---@param bucket_id integer Identifier of a bucket to ref. 49 | ---@return boolean?, VshardError? 50 | function storage.bucket_refrw(bucket_id) end 51 | 52 | -- Unref shortcut for an obscure mode. 53 | ---@param bucket_id integer Identifier of a bucket to unref. 54 | ---@param mode 'read'|'write' 55 | function storage.bucket_unref(bucket_id, mode) end 56 | 57 | ---Remove one RO reference. 58 | ---@param bucket_id integer Identifier of a bucket to unref. 59 | ---@return boolean?, BucketIsCorrupted? 60 | function storage.bucket_unrefro(bucket_id) end 61 | 62 | ---Remove one RW reference. 63 | ---@param bucket_id integer Identifier of a bucket to unref. 64 | ---@return boolean?, BucketIsCorrupted? 65 | function storage.bucket_unrefrw(bucket_id) end 66 | 67 | ---Disable rebalancing. Disabled rebalancer sleeps until it 68 | ---is enabled back. If not a rebalancer node is disabled, it does 69 | ---not sends its state to rebalancer. 70 | function storage.rebalancer_disable() end 71 | 72 | ---Enable rebalancing. Disabled rebalancer sleeps until it 73 | ---is enabled back. If not a rebalancer node is disabled, it does 74 | ---not sends its state to rebalancer. 75 | function storage.rebalancer_enable() end 76 | 77 | ---Check if this replicaset is locked. It means be invisible for the rebalancer. 78 | ---@return boolean 79 | function storage.is_locked() end 80 | 81 | ---Check if a rebalancing is in progress. It is true, if the node 82 | ---applies routes received from a rebalancer node in the special fiber 83 | ---@return boolean 84 | function storage.rebalancing_is_in_progress() end 85 | 86 | ---@param bucket_id? integer 87 | ---@return { [integer]: { id: integer, status: string, destination?: string, ref_ro?: integer, ref_rw?: integer, ro_lock: true|nil, rw_lock: true|nil } } 88 | function storage.buckets_info(bucket_id) end 89 | 90 | ---Get number of buckets stored on this storage. Regardless of their state. 91 | ---@return integer 92 | function storage.buckets_count() end 93 | 94 | ---List of sharded spaces. 95 | ---@return { [integer]: boxSpaceObject } 96 | function storage.sharded_spaces() end 97 | 98 | ---Return information about bucket 99 | ---@param bucket_id integer 100 | ---@return { is_transfering?: boolean, id: integer, status: string, destination?: string }?, VshardError? 101 | function storage.bucket_stat(bucket_id) end 102 | 103 | ---Receive bucket data. If the bucket is not presented here, it is created as RECEIVING. 104 | ---@param bucket_id integer Bucket to receive. 105 | ---@param from UUID from Source UUID 106 | ---@param data any 107 | ---@return boolean?, VshardError? 108 | function storage.bucket_recv(bucket_id, from, data) end 109 | 110 | ---Delete data of a specified garbage bucket. If a bucket is not 111 | ---garbage, then force option must be set. A bucket is not deleted from _bucket space. 112 | ---@param bucket_id integer Identifier of a bucket to delete data from. 113 | ---@param opts? { force?: boolean }. Can contain only 'force' flag to delete a bucket regardless of is it garbage or not. 114 | function storage.bucket_delete_garbage(bucket_id, opts) end 115 | 116 | ---Collect content of the readable bucket. 117 | ---@param bucket_id integer 118 | ---@return { [1]: string, [2]: box.tuple[] }[], WrongBucket? 119 | function storage.bucket_collect(bucket_id) end 120 | 121 | ---Create bucket range manually for initial bootstrap, tests or 122 | ---emergency cases. Buckets id, id + 1, id + 2, ..., id + count 123 | ---are inserted. 124 | ---@param first_bucket_id integer Identifier of a first bucket in a range. 125 | ---@param count? integer Bucket range length to insert. By default is 1. 126 | ---@return boolean?, VshardError? 127 | function storage.bucket_force_create(first_bucket_id, count) end 128 | 129 | ---Drop bucket manually for tests or emergency cases 130 | ---@param bucket_id integer 131 | ---@return boolean? 132 | function storage.bucket_force_drop(bucket_id) end 133 | 134 | ---Send a bucket to other replicaset. 135 | ---@param bucket_id integer 136 | ---@param destination UUID other replicaset UUID 137 | ---@param opts? { timeout: number } 138 | ---@return boolean?, VshardError? 139 | function storage.bucket_send(bucket_id, destination, opts) end 140 | 141 | ---Collect array of active bucket identifiers for discovery. 142 | ---@return integer[] 143 | function storage.buckets_discovery() end 144 | 145 | ---Check all buckets of the host storage to have SENT or ACTIVE 146 | ---state, return active bucket count. 147 | ---return not `nil` Count of active buckets. 148 | ---return `nil` Not SENT or not ACTIVE buckets were found. 149 | ---@return { bucket_active_count:integer, bucket_pinned_count: integer }? 150 | function storage.rebalancer_request_state() end 151 | 152 | ---Immediately wakeup rebalancer, if it exists on the current node. 153 | function storage.rebalancer_wakeup() end 154 | 155 | return storage 156 | -------------------------------------------------------------------------------- /Library/box/tuple.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | ---@class box.tuple: ffi.cdata* 4 | ---@field [string] any 5 | ---@field [integer] any 6 | box.tuple = {} 7 | 8 | ---Construct a new tuple from either a scalar or a Lua table. Alternatively, one can get new tuples from Tarantool’s select or insert or replace or update requests, which can be regarded as statements that do new() implicitly. 9 | ---@overload fun(...: tuple_type): box.tuple 10 | ---@param value tuple_type[] 11 | ---@return box.tuple tuple 12 | function box.tuple.new(value) end 13 | 14 | ---Since versions 2.2.3, 2.3.2, and 2.4.1. A function to check whether a given object is a tuple cdata object. Never raises nor returns an error. 15 | ---@param object any 16 | ---@return boolean is_tuple returns true if given object is box.tuple 17 | function box.tuple.is(object) end 18 | 19 | ---If t is a tuple instance, t:bsize() will return the number of bytes in the tuple. With both the memtx storage engine and the vinyl storage engine the default maximum is one megabyte (memtx_max_tuple_size or vinyl_max_tuple_size). Every field has one or more “length” bytes preceding the actual contents, so bsize() returns a value which is slightly greater than the sum of the lengths of the contents. 20 | ---The value does not include the size of “struct tuple” (for the current size of this structure look in the tuple.h file in Tarantool’s source code). 21 | ---@return integer bytes 22 | function box.tuple:bsize() end 23 | 24 | ---If t is a tuple instance, t:find(search-value) will return the number of the first field in t that matches the search value, and t:findall(search-value [, search-value ...]) will return numbers of all fields in t that match the search value. Optionally one can put a numeric argument field-number before the search-value to indicate “start searching at field number field-number.” 25 | ---@param field_number integer 26 | ---@param search_value any 27 | ---@return integer? 28 | function box.tuple:find(field_number, search_value) end 29 | 30 | ---@param search_value any 31 | ---@return integer? 32 | function box.tuple:find(search_value) end 33 | 34 | ---If `t` is a tuple instance, `t:find(search-value)` will return the number of the first field in t that matches the search value, and t:findall(search-value [, search-value ...]) will return numbers of all fields in t that match the search value. Optionally one can put a numeric argument field-number before the search-value to indicate “start searching at field number field-number.” 35 | ---@param field_number integer 36 | ---@param search_value any 37 | ---@return integer ... 38 | function box.tuple:findall(field_number, search_value) end 39 | 40 | ---@param search_value any 41 | ---@return integer ... 42 | function box.tuple:findall(search_value) end 43 | 44 | ---An analogue of the Lua next() function, but for a tuple object. When called without arguments, tuple:next() returns the first field from a tuple. Otherwise, it returns the field next to the indicated position. 45 | 46 | ---However `tuple:next()` is not really efficient, and it is better to use `box.tuple:pairs()`/`box.tuple:ipairs()`. 47 | ---@see box.tuple:pairs 48 | ---@see box.tuple:ipairs 49 | ---@param pos? integer 50 | ---@return integer field_number, any value 51 | function box.tuple:next(pos) end 52 | 53 | ---@return fun.iterator, box.tuple 54 | function box.tuple:pairs() end 55 | 56 | ---@return fun.iterator, box.tuple 57 | function box.tuple:ipairs() end 58 | 59 | ---If `t` is a tuple instance, `t:totable()` will return all fields, 60 | ---`t:totable(1)` will return all fields starting with field number 1, 61 | ---`t:totable(1,5)` will return all fields between field number 1 and field number 5. 62 | ---It is preferable to use t:totable() rather than t:unpack(). 63 | ---@param start_field_number? integer 64 | ---@param end_field_number? integer 65 | ---@return any[] 66 | function box.tuple:totable(start_field_number, end_field_number) end 67 | 68 | ---If `t` is a tuple instance, `t:unpack()` will return all fields, 69 | ---`t:unpack(1)` will return all fields starting with field number 1, 70 | ---`t:unpack(1,5)` will return all fields between field number 1 and field number 5. 71 | ---@param start_field_number? integer 72 | ---@param end_field_number? integer 73 | ---@return any ... 74 | function box.tuple:unpack(start_field_number, end_field_number) end 75 | 76 | ---The `tuple_object:totable()` function only returns a table containing the values. But the `tuple_object:tomap()` function returns a table containing not only the values, but also the key:value pairs. 77 | ---This only works if the tuple comes from a space that has been formatted with a format clause. 78 | ---@param options {names_only: true} | {names_only: false} | {} | nil 79 | ---@return table 80 | function box.tuple:tomap(options) end 81 | 82 | ---If `t` is a tuple instance, `t:transform(start_field_number,fields_to_remove)` will return a tuple where, starting from field `start_field_number`, a number of fields (fields-to-remove) are removed. 83 | ---Optionally one can add more arguments after `fields_to_remove` to indicate new values that will replace what was removed. 84 | ---If the original tuple comes from a space that has been formatted with a format clause, the formatting will not be preserved for the result tuple. 85 | ---@param start_field_number integer 86 | ---@param fields_to_remove integer 87 | ---@param ... tuple_type 88 | ---@return box.tuple 89 | function box.tuple:transform(start_field_number, fields_to_remove, ...) end 90 | 91 | ---Update a tuple. 92 | ---This function updates a tuple which is not in a space. Compare the function `box.space.space-name:update(key, {{format, field_no, value}, ...})` which updates a tuple in a space. 93 | ---For details: see the description for `operator`, `field_no`, and `value` in the section box.space.space-name:update{key, format, {field_number, value}…). 94 | ---If the original tuple comes from a space that has been formatted with a format clause, the formatting will be preserved for the result tuple. 95 | ---@param update_operations {[1]: update_operation, [2]: integer|string, [3]: tuple_type }[] 96 | ---@return box.tuple 97 | function box.tuple:update(update_operations) end 98 | 99 | ---The same as `tuple_object:update()`, but ignores errors. 100 | ---In case of an error the tuple is left intact, but an error message is printed. Only client errors are ignored, such as a bad field type, or wrong field index/name. 101 | ---System errors, such as OOM, are not ignored and raised just like with a normal `update()`. Note that only bad operations are ignored. All correct operations are applied. 102 | ---@param update_operations {[1]: update_operation, [2]: integer|string, [3]: tuple_type }[] 103 | ---@return box.tuple 104 | function box.tuple:upsert(update_operations) end 105 | 106 | return box.tuple 107 | -------------------------------------------------------------------------------- /Library/box/index.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@alias boxIndexPartType 5 | ---| "datetime" 6 | ---| "number" 7 | ---| "double" 8 | ---| "boolean" 9 | ---| "decimal" 10 | ---| "scalar" 11 | ---| "uuid" 12 | ---| "integer" 13 | ---| "unsigned" 14 | ---| "string" 15 | ---| "varbinary" 16 | ---| "array" 17 | 18 | ---@class boxIndex: boxIndexOptions 19 | ---@field parts boxIndexPart[] list of index parts 20 | local boxIndex = {} 21 | 22 | ---@class boxIndexPart 23 | ---@field type boxIndexPartType type of the field 24 | ---@field is_nullable boolean false if field not-nullable, otherwise true 25 | ---@field exclude_null? boolean 26 | ---@field fieldno integer position in tuple of the field 27 | ---@field path? string 28 | 29 | ---@alias IndexPart 30 | ---| { field: integer, type: boxIndexPartType, is_nullable: boolean, exclude_null: boolean, collation: string, path: string, fieldno: integer } 31 | ---| { field: string, is_nullable: boolean, exclude_null: boolean, collation: string, path: string, fieldno: integer } 32 | ---| { [1]: integer|string, [2]: boxIndexPartType, is_nullable: boolean, exclude_null: boolean, collation: string, path: string, fieldno: integer } 33 | 34 | ---@class boxIndexOptions: table 35 | ---@field name? string name of the index 36 | ---@field type? "TREE" | "HASH" | "BITSET" | "RTREE" | "tree" | "hash" | "bitset" | "rtree" (Default: TREE) type of index 37 | ---@field id? number (Default: last index’s id + 1) unique identifier 38 | ---@field unique? boolean (Default: true) index is unique 39 | ---@field if_not_exists? boolean (Default: false) no error if duplicate name 40 | ---@field parts? IndexPart[]|string[] field numbers + types 41 | ---@field dimension? number (Default: 2) affects RTREE only 42 | ---@field distance? "euclid"|"manhattan" (Default: euclid) affects RTREE only 43 | ---@field bloom_fpr? number (Default: vinyl_bloom_fpr) affects vinyl only 44 | ---@field page_size? number (Default: vinyl_page_size) affects vinyl only 45 | ---@field range_size? number (Default: vinyl_range_size) affects vinyl only 46 | ---@field run_count_per_level? number (Default: vinyl_run_count_per_level) affects vinyl only 47 | ---@field run_size_ratio? number (Default: vinyl_run_size_ratio) affects vinyl only 48 | ---@field sequence? string|number 49 | ---@field func? string functional index 50 | ---@field hint? boolean (Default: true) affects TREE only. true makes an index work faster, false – index size is reduced by half 51 | 52 | ---Search for a tuple in the given space. 53 | ---@param key box.tuple|tuple_type[]|scalar 54 | ---@return box.tuple? tuple the tuple whose index key matches key, or nil. 55 | function boxIndex:get(key) end 56 | 57 | ---Search for a tuple or a set of tuples in the given space. This method doesn’t yield (for details see Cooperative multitasking). 58 | ---@param key box.tuple|tuple_type[]|scalar 59 | ---@param options? boxSpaceSelectOptions 60 | ---@return box.tuple[] list the tuples whose primary-key fields are equal to the fields of the passed key. If the number of passed fields is less than the number of fields in the primary key, then only the passed fields are compared, so select{1,2} will match a tuple whose primary key is {1,2,3}. 61 | ---@return string? pos 62 | function boxIndex:select(key, options) end 63 | 64 | ---Search for a tuple or a set of tuples in the given space, and allow iterating over one tuple at a time. 65 | ---@param key box.tuple|tuple_type[]|scalar value to be matched against the index key, which may be multi-part 66 | ---@param iterator? boxIterator (Default: 'EQ') defines iterator order 67 | ---@return fun.iterator 68 | function boxIndex:pairs(key, iterator) end 69 | 70 | ---Update a tuple. 71 | --- 72 | ---The update function supports operations on fields — assignment, arithmetic (if the field is numeric), cutting and pasting fragments of a field, deleting or inserting a field. 73 | ---Multiple operations can be combined in a single update request, and in this case they are performed atomically and sequentially. 74 | ---Each operation requires specification of a field identifier, which is usually a number. 75 | ---When multiple operations are present, the field number for each operation is assumed to be relative to the most recent state of the tuple, that is, as if all previous operations in a multi-operation update have already been applied. 76 | ---In other words, it is always safe to merge multiple update invocations into a single invocation, with no change in semantics. 77 | ---@param key box.tuple|tuple_type[]|scalar 78 | ---@param update_operations { [1]: update_operation, [2]: number|string, [3]: tuple_type }[] 79 | ---@return box.tuple? tuple the updated tuple if it was found 80 | function boxIndex:update(key, update_operations) end 81 | 82 | ---Find the maximum value in the specified index. 83 | ---@param key box.tuple|tuple_type[]|scalar 84 | ---@return box.tuple? tuple result 85 | function boxIndex:max(key) end 86 | 87 | ---Find the minimum value in the specified index. 88 | ---@param key box.tuple|tuple_type[]|scalar 89 | ---@return box.tuple? tuple result 90 | function boxIndex:min(key) end 91 | 92 | ---Return the number of tuples. If compared with len(), this method works slower because count() scans the entire space to count the tuples. 93 | ---@param key? box.tuple|tuple_type[]|scalar 94 | ---@param iterator? boxIterator 95 | ---@return integer number_of_tuples 96 | function boxIndex:count(key, iterator) end 97 | 98 | ---Return the number of tuples in the space. If compared with count(), this method works faster because len() does not scan the entire space to count the tuples. 99 | ---@return integer number_of_tuples 100 | function boxIndex:len() end 101 | 102 | ---Returns total bsize of tuples in index 103 | ---@return integer 104 | function boxIndex:bsize() end 105 | 106 | ---@param key box.tuple|tuple_type[]|scalar 107 | ---@return box.tuple? tuple the deleted tuple 108 | function boxIndex:delete(key) end 109 | 110 | ---Alter an index. 111 | ---It is legal in some circumstances to change one or more of the index characteristics, 112 | ---for example its type, its sequence options, its parts, and whether it is unique. 113 | --- 114 | ---Usually this causes rebuilding of the space, except for the simple case 115 | ---where a part’s is_nullable flag is changed from false to true. 116 | ---@param opts boxIndexOptions 117 | function boxIndex:alter(opts) end 118 | 119 | ---Rename an index. 120 | ---@param index_name string new name for index 121 | function boxIndex:rename(index_name) end 122 | 123 | ---Drop an index. Dropping a primary-key index has a side effect: all tuples are deleted. 124 | function boxIndex:drop() end 125 | 126 | ---Return a tuple’s position for an index. 127 | --- 128 | ---This value can be passed to the after option of the select and pairs methods 129 | --- 130 | ---Note that tuple_pos does not work with functional and multikey indexes. 131 | ---@param tuple scalar|table 132 | ---@return string # base64-encoded string (a tuple’s position in a space) 133 | function boxIndex:tuple_pos(tuple) end 134 | 135 | ---Drop an index. 136 | --- 137 | ---Dropping a primary-key index has a side effect: all tuples are deleted. 138 | function boxIndex:drop() end 139 | -------------------------------------------------------------------------------- /Library/box/info.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@alias BoxInfoStatusRunning "running" the instance is loaded 5 | ---@alias BoxInfoStatusLoading "loading" the instance is either recovering xlogs/snapshots or bootstrapping 6 | ---@alias BoxInfoStatusOrphan "orphan" the instance has not (yet) succeeded in joining the required number of masters 7 | ---@alias BoxInfoStatusHotStandBy "hot_standby" the instance is standing by another instance 8 | 9 | ---@alias BoxInfoElectionStateLeader "leader" 10 | ---@alias BoxInfoElectionStateFollower "follower" 11 | ---@alias BoxInfoElectionStateCandidate "candidate" 12 | 13 | ---@class BoxInfoElection 14 | ---@field public state BoxInfoElectionStateLeader | BoxInfoElectionStateFollower | BoxInfoElectionStateCandidate election state (mode) of the node 15 | ---@field public vote integer ID of a node the current node votes for. If the value is 0, it means the node hasn’t voted in the current term yet. 16 | ---@field public leader integer leader node ID in the current term. If the value is 0, it means the node doesn’t know which node is the leader in the current term. 17 | ---@field public term integer current election term. 18 | 19 | ---@class BoxInfoCluster 20 | ---@field public uuid string replicaset_uuid of the replicaset this instance belong 21 | 22 | ---@class BoxInfoSynchroQueue 23 | ---@field public owner integer ID of the replica that owns the synchronous transaction queue. 24 | ---@field public term integer current queue term. 25 | ---@field public len integer the number of entries that are currently waiting in the queue. 26 | ---@field public busy boolean the instance is processing or writing some system request that modifies the queue 27 | 28 | ---@class BoxInfoSynchro 29 | ---@field public queue BoxInfoSynchroQueue 30 | ---@field public quorum integer the resulting value of the replication_synchro_quorum configuration option. 31 | 32 | ---@class BoxInfo: table 33 | ---The box.info submodule provides access to information about server instance variables. 34 | ---@field public id integer is a short numeric identifier of instance n within the replica set. This value is stored in the box.space._cluster system space. 35 | ---@field public uuid string is a globally unique identifier of instance n. 36 | ---@field public pid integer is the process ID. 37 | ---@field public listen string real address to which an instance was bound. 38 | ---@field public uptime integer is the number of seconds since the instance started. 39 | ---@field public status BoxInfoStatusRunning | BoxInfoStatusLoading | BoxInfoStatusOrphan | BoxInfoStatusHotStandBy is the current state of the instance. 40 | ---@field public lsn integer is the log sequence number (LSN) for the latest entry in instance n’s write ahead log (WAL) 41 | ---@field public version string is the Tarantool version 42 | ---@field public schema_version integer database schema version. 43 | ---@field public ro boolean is true if the instance is in “read-only” mode 44 | ---@field public package string 45 | ---@field public vclock integer[] is a table with the vclock values of all instances in a replica set which have made data changes. 46 | ---@field public replication table 47 | ---@field public replication_anon { count: integer } list all the anonymous replicas following the instance. 48 | ---@field public election BoxInfoElection shows the current state of a replica set node regarding leader election 49 | ---@field public signature integer is the sum of all lsn values from each vector clock (vclock) for all instances in the replica set 50 | ---@field public cluster BoxInfoCluster 51 | ---@field public synchro BoxInfoSynchro 52 | ---@field public ro_reason string 53 | ---@overload fun(): BoxInfo 54 | box.info = {} 55 | 56 | ---@class ReplicaInfo 57 | ---@field public id integer is a short numeric identifier of instance n within the replica set 58 | ---@field public uuid string is a globally unique identifier of instance n 59 | ---@field public lsn integer is the log sequence number (LSN) for the latest entry in instance n’s write ahead log (WAL) 60 | ---@field public upstream UpstreamInfo|nil 61 | ---@field public downstream DownstreamInfo|nil 62 | 63 | ---@return { [string]: ReplicaInfo } 64 | function box.info.replication_anon() end 65 | 66 | ---@alias UpstreamStatusAuth "auth" means that authentication is happening. 67 | ---@alias UpstreamStatusConnecting "connecting" means that connection is happening. 68 | ---@alias UpstreamStatusDisconected "disconected" means that it is not connected to the replica set (due to network problems, not replication errors) 69 | ---@alias UpstreamStatusFollow "follow" means that the current instance’s role is “replica” (read-only, or not read-only but acting as a replica for this remote peer in a master-master configuration), and is receiving or able to receive data from instance n’s (upstream) master 70 | ---@alias UpstreamStatusStopped "stopped" means that replication was stopped due to a replication error (for example duplicate key). 71 | ---@alias UpstreamStatusSync "sync" means that the master and replica are synchronizing to have the same data. 72 | 73 | ---@alias DownstreamStatusFollow "follow" means that downstream replication is in progress 74 | ---@alias DownstreamStatusStopped "stopped" means that downstream replication has stopped 75 | 76 | ---@class UpstreamInfo 77 | ---@field public peer string contains instance n’s URI for example 127.0.0.1:3302. 78 | ---@field public status UpstreamStatusAuth | UpstreamStatusConnecting | UpstreamStatusDisconected | UpstreamStatusFollow | UpstreamStatusStopped | UpstreamStatusSync 79 | ---@field public idle number is the time (in seconds) since the last event was received. This is the primary indicator of replication health 80 | ---@field public lag number is the time difference between the local time of instance n, recorded when the event was received, and the local time at another master recorded when the event was written to the write ahead log on that master 81 | ---@field public message string|nil contains an error message in case of a degraded state, otherwise it is nil. 82 | 83 | ---@class DownstreamInfo 84 | ---appears (is not nil) with data about an instance that is following instance n or is intending to follow it 85 | ---@field public status DownstreamStatusFollow | DownstreamStatusStopped 86 | ---@field public idle number is the time (in seconds) since the last time that instance n sent events through the downstream replication 87 | ---@field public lag number is the time difference between the local time at the master node, recorded when a particular transaction was written to the write ahead log, and the local time recorded when it receives an acknowledgement for this transaction from a replica 88 | ---@field public vclock integer[] may be the same as the current instance’s vclock 89 | ---@field public message string|nil 90 | ---@field public system_message string|nil 91 | 92 | ---@class BoxInfoMemory 93 | ---@field public cache number number of bytes used for caching user data. The memtx storage engine does not require a cache, so in fact this is the number of bytes in the cache for the tuples stored for the vinyl storage engine. 94 | ---@field public data number number of bytes used for storing user data (the tuples) with the memtx engine and with level 0 of the vinyl engine, without taking memory fragmentation into account. 95 | ---@field public index number number of bytes used for indexing user data, including memtx and vinyl memory tree extents, the vinyl page index, and the vinyl bloom filters. 96 | ---@field public lua number number of bytes used for Lua runtime. 97 | ---@field public net number number of bytes used for network input/output buffers. 98 | ---@field public tx number number of bytes in use by active transactions. For the vinyl storage engine, this is the total size of all allocated objects (struct txv, struct vy_tx, struct vy_read_interval) and tuples pinned for those objects. 99 | 100 | ---The memory function of box.info gives the admin user a picture of the whole Tarantool instance. 101 | ---@return BoxInfoMemory 102 | function box.info.memory() end 103 | 104 | ---@class BoxInfoGCCheckpoint 105 | ---@field public references table[] a list of references to a checkpoint 106 | ---@field public vclock integer[] a checkpoint’s vclock value 107 | ---@field public signature integer a sum of a checkpoint’s vclock’s components 108 | 109 | ---@class BoxInfoGC 110 | ---@field public vclock integer[] the garbage collector’s vclock 111 | ---@field public signature integer the sum of the garbage collector’s checkpoint’s components 112 | ---@field public checkpoint_is_in_progress boolean true if a checkpoint is in progress, otherwise false 113 | ---@field public consumers table[] a list of users whose requests might affect the garbage collector 114 | ---@field public checkpoints BoxInfoGCCheckpoint[] a list of preserved checkpoints 115 | 116 | ---The gc function of box.info gives the admin user a picture of the factors that affect the Tarantool garbage collector. The garbage collector compares vclock (vector clock) values of users and checkpoints, so a look at box.info.gc() may show why the garbage collector has not removed old WAL files, or show what it may soon remove. 117 | ---@return BoxInfoGC 118 | function box.info.gc() end 119 | -------------------------------------------------------------------------------- /Library/http/client.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@class http 5 | local http = {} 6 | 7 | 8 | ---@class ClientHTTP 9 | local http_client = {} 10 | 11 | ---@class ClientHTTPOptions 12 | ---@field max_connections? number is the maximum number of entries in the cache. It affects libcurl CURLMOPT_MAXCONNECTS. The default is -1. 13 | ---@field max_total_connections? number is the maximum number of active connections. It affects libcurl CURLMOPT_MAX_TOTAL_CONNECTIONS. It is ignored if the curl version is less than 7.30. The default is 0, which allows libcurl to scale accordingly to easily handles count. 14 | 15 | ---@param options? ClientHTTPOptions 16 | ---@return ClientHTTP 17 | function http.new(options) end 18 | 19 | ---@class ClientHTTPRequestOptions 20 | ---@field ca_file? string path to an SSL certificate file to verify the peer with. 21 | ---@field ca_path? string path to a directory holding one or more certificates to verify the peer with. 22 | ---@field headers? table table of HTTP headers. 23 | ---@field keepalive_idle? number delay, in seconds, that the operating system will wait while the connection is idle before sending keepalive probes. See also CURLOPT_TCP_KEEPIDLE and the note below about keepalive_interval. 24 | ---@field keepalive_interval? number the interval, in seconds, that the operating system will wait between sending keepalive probes. See also CURLOPT_TCP_KEEPINTVL. If both keepalive_idle and keepalive_interval are set, then Tarantool will also set HTTP keepalive headers: Connection:Keep-Alive and Keep-Alive:timeout=. Otherwise Tarantool will send Connection:close. 25 | ---@field low_speed_limit? number set the “low speed limit” – the average transfer speed in bytes per second that the transfer should be below during “low speed time” seconds for the library to consider it to be too slow and abort. See also CURLOPT_LOW_SPEED_LIMIT. 26 | ---@field low_speed_time? number set the “low speed time” – the time that the transfer speed should be below the “low speed limit” for the library to consider it too slow and abort. See also CURLOPT_LOW_SPEED_TIME. 27 | ---@field max_header_name_len? number the maximal length of a header name. If a header name is bigger than this value, it is truncated to this length. The default value is ‘32’. 28 | ---@field follow_location? boolean (Default: true) when the option is set to true (default) and the response has a 3xx code, the HTTP client will automatically issue another request to a location that a server sends in the Location header. 29 | ---@field no_proxy? string a comma-separated list of hosts that do not require proxies, or ‘*’, or ‘’. Set no_proxy = host [, host ...] to specify hosts that can be reached without requiring a proxy 30 | ---@field proxy? string a proxy server host or IP address, or ‘’. If proxy is a host or IP address, then it may begin with a scheme, for example https:// for an https proxy or http:// for an http proxy. 31 | ---@field proxy_port? number a proxy server port. The default is 443 for an https proxy and 1080 for a non-https proxy. See also CURLOPT_PROXYPORT. 32 | ---@field proxy_user_pwd? string a proxy server user name and/or password. Format: proxy_user_pwd = user_name: or proxy_user_pwd = :password or proxy_user_pwd = user_name:password 33 | ---@field ssl_cert? string path to a SSL client certificate file. See also CURLOPT_SSLCERT. 34 | ---@field ssl_key? string path to a private key file for a TLS and SSL client certificate. See also CURLOPT_SSLKEY. 35 | ---@field timeout? number (Default: 36586400100) number of seconds to wait for a curl API read request before timing out 36 | ---@field unix_socket? string a socket name to use instead of an Internet address, for a local connection. The Tarantool server must be built with libcurl 7.40 or later. See the second example later in this section. 37 | ---@field verbose? boolean set on/off verbose mode. 38 | ---@field verify_host? boolean set on/off verification of the certificate’s name (CN) against host. See also CURLOPT_SSL_VERIFYHOST. 39 | ---@field verify_peer? boolean set on/off verification of the peer’s SSL certificate. See also CURLOPT_SSL_VERIFYPEER. 40 | ---@field accept_encoding? string enables automatic decompression of HTTP responses by setting the contents of the Accept-Encoding: header sent in an HTTP request and enabling decoding of a response when the Content-Encoding: header is received. 41 | 42 | ---@class HTTPResponse 43 | ---@field status number HTTP response status 44 | ---@field reason string HTTP response status text 45 | ---@field headers table a Lua table with normalized HTTP headers 46 | ---@field body string? response body 47 | ---@field proto number protocol version 48 | 49 | ---Performs an HTTP request and, if there is a successful connection, will return a table with connection information. 50 | ---@param method string 51 | ---@param url string 52 | ---@param body? string 53 | ---@param opts ClientHTTPRequestOptions 54 | ---@return HTTPResponse 55 | ---@async 56 | function http_client:request(method, url, body, opts) end 57 | 58 | ---shortcut for http_client:request("PATCH", url, body, opts) 59 | ---@param url string 60 | ---@param body string 61 | ---@param options ClientHTTPRequestOptions 62 | ---@return HTTPResponse 63 | ---@async 64 | function http_client:patch(url, body, options) end 65 | 66 | ---shortcut for http_client:request("OPTIONS", url, nil, opts) 67 | ---@param url string 68 | ---@param options ClientHTTPRequestOptions 69 | ---@return HTTPResponse 70 | ---@async 71 | function http_client:options(url, options) end 72 | 73 | ---shortcut for http_client:request("PUT", url, body, opts) 74 | ---@param url string 75 | ---@param body string 76 | ---@param options ClientHTTPRequestOptions 77 | ---@return HTTPResponse 78 | ---@async 79 | function http_client:put(url, body, options) end 80 | 81 | ---shortcut for http_client:request("CONNECT", url, body, opts) 82 | ---@param url string 83 | ---@param options ClientHTTPRequestOptions 84 | ---@return HTTPResponse 85 | ---@async 86 | function http_client:connect(url, options) end 87 | 88 | ---shortcut for http_client:request("DELETE", url, body, opts) 89 | ---@param url string 90 | ---@param options ClientHTTPRequestOptions 91 | ---@return HTTPResponse 92 | ---@async 93 | function http_client:delete(url, options) end 94 | 95 | ---shortcut for http_client:request("POST", url, body, opts) 96 | ---@param url string 97 | ---@param body string 98 | ---@param options ClientHTTPRequestOptions 99 | ---@return HTTPResponse 100 | ---@async 101 | function http_client:post(url, body, options) end 102 | 103 | ---shortcut for http_client:request("TRACE", url, body, opts) 104 | ---@param url string 105 | ---@param options ClientHTTPRequestOptions 106 | ---@return HTTPResponse 107 | ---@async 108 | function http_client:trace(url, options) end 109 | 110 | ---shortcut for http_client:request("HEAD", url, body, opts) 111 | ---@param url string 112 | ---@param options ClientHTTPRequestOptions 113 | ---@return HTTPResponse 114 | ---@async 115 | function http_client:head(url, options) end 116 | 117 | ---shortcut for http_client:request("GET", url, body, opts) 118 | ---@param url string 119 | ---@param options ClientHTTPRequestOptions 120 | ---@return HTTPResponse 121 | ---@async 122 | function http_client:get(url, options) end 123 | 124 | ---@class HTTPClientStat 125 | ---@field active_requests number number of currently executing requests 126 | ---@field sockets_added number total number of sockets added into an event loop 127 | ---@field sockets_deleted number total number of sockets sockets from an event loop 128 | ---@field total_requests number total number of requests 129 | ---@field http_200_responses number total number of requests which have returned code HTTP 200 130 | ---@field http_other_responses number total number of requests which have not returned code HTTP 200 131 | ---@field failed_requests number total number of requests which have failed including system errors, curl errors, and HTTP errors 132 | 133 | ---returns a table with statistics 134 | ---@return HTTPClientStat 135 | function http_client:stat() end 136 | 137 | ---Performs an HTTP request and, if there is a successful connection, will return a table with connection information. 138 | ---@param method string 139 | ---@param url string 140 | ---@param body? string 141 | ---@param opts? ClientHTTPRequestOptions 142 | ---@return HTTPResponse 143 | ---@async 144 | function http.request(method, url, body, opts) end 145 | 146 | ---shortcut for http.request("PATCH", url, body, opts) 147 | ---@param url string 148 | ---@param body string 149 | ---@param options? ClientHTTPRequestOptions 150 | ---@return HTTPResponse 151 | ---@async 152 | function http.patch(url, body, options) end 153 | 154 | ---shortcut for http.request("OPTIONS", url, nil, opts) 155 | ---@param url string 156 | ---@param options? ClientHTTPRequestOptions 157 | ---@return HTTPResponse 158 | ---@async 159 | function http.options(url, options) end 160 | 161 | ---shortcut for http.request("PUT", url, body, opts) 162 | ---@param url string 163 | ---@param body string 164 | ---@param options? ClientHTTPRequestOptions 165 | ---@return HTTPResponse 166 | ---@async 167 | function http.put(url, body, options) end 168 | 169 | ---shortcut for http.request("CONNECT", url, body, opts) 170 | ---@param url string 171 | ---@param options? ClientHTTPRequestOptions 172 | ---@return HTTPResponse 173 | ---@async 174 | function http.connect(url, options) end 175 | 176 | ---shortcut for http.request("DELETE", url, body, opts) 177 | ---@param url string 178 | ---@param options? ClientHTTPRequestOptions 179 | ---@return HTTPResponse 180 | ---@async 181 | function http.delete(url, options) end 182 | 183 | ---shortcut for http.request("POST", url, body, opts) 184 | ---@param url string 185 | ---@param body string 186 | ---@param options? ClientHTTPRequestOptions 187 | ---@return HTTPResponse 188 | ---@async 189 | function http.post(url, body, options) end 190 | 191 | ---shortcut for http.request("TRACE", url, body, opts) 192 | ---@param url string 193 | ---@param options? ClientHTTPRequestOptions 194 | ---@return HTTPResponse 195 | ---@async 196 | function http.trace(url, options) end 197 | 198 | ---shortcut for http.request("HEAD", url, body, opts) 199 | ---@param url string 200 | ---@param options? ClientHTTPRequestOptions 201 | ---@return HTTPResponse 202 | ---@async 203 | function http.head(url, options) end 204 | 205 | ---shortcut for http.request("GET", url, body, opts) 206 | ---@param url string 207 | ---@param options? ClientHTTPRequestOptions 208 | ---@return HTTPResponse 209 | ---@async 210 | function http.get(url, options) end 211 | 212 | return http 213 | -------------------------------------------------------------------------------- /Library/vshard/error.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local error = {} 5 | 6 | ---@alias VshardErrCode 7 | ---| 1 # WRONG_BUCKET 8 | ---| 2 # NON_MASTER 9 | ---| 3 # BUCKET_ALREADY_EXISTS 10 | ---| 4 # NO_SUCH_REPLICASET 11 | ---| 5 # MOVE_TO_SELF 12 | ---| 6 # MISSING_MASTER 13 | ---| 7 # TRANSFER_IS_IN_PROGRESS 14 | ---| 8 # UNREACHABLE_REPLICASET 15 | ---| 9 # NO_ROUTE_TO_BUCKET 16 | ---| 10 # NON_EMPTY 17 | ---| 11 # UNREACHABLE_MASTER 18 | ---| 12 # OUT_OF_SYNC 19 | ---| 13 # HIGH_REPLICATION_LAG 20 | ---| 14 # UNREACHABLE_REPLICA 21 | ---| 15 # LOW_REDUNDANCY 22 | ---| 16 # INVALID_REBALANCING 23 | ---| 17 # SUBOPTIMAL_REPLICA 24 | ---| 18 # UNKNOWN_BUCKETS 25 | ---| 19 # REPLICASET_IS_LOCKED 26 | ---| 20 # OBJECT_IS_OUTDATED 27 | ---| 21 # ROUTER_ALREADY_EXISTS 28 | ---| 22 # BUCKET_IS_LOCKED 29 | ---| 23 # INVALID_CFG 30 | ---| 24 # BUCKET_IS_PINNED 31 | ---| 25 # TOO_MANY_RECEIVING 32 | ---| 26 # STORAGE_IS_REFERENCED 33 | ---| 27 # STORAGE_REF_ADD 34 | ---| 28 # STORAGE_REF_USE 35 | ---| 29 # STORAGE_REF_DEL 36 | ---| 30 # BUCKET_RECV_DATA_ERROR 37 | ---| 31 # MULTIPLE_MASTERS_FOUND 38 | ---| 32 # REPLICASET_IN_BACKOFF 39 | ---| 33 # STORAGE_IS_DISABLED 40 | ---| 34 # BUCKET_IS_CORRUPTED 41 | ---| 35 # ROUTER_IS_DISABLED 42 | ---| 36 # BUCKET_GC_ERROR 43 | ---| 37 # STORAGE_CFG_IS_IN_PROGRESS 44 | ---| 38 # ROUTER_CFG_IS_IN_PROGRESS 45 | 46 | ---@alias ShardingErrors 47 | ---| WrongBucket 48 | ---| NonMaster 49 | ---| NoSuchReplicaset 50 | ---| MoveToSelf 51 | ---| MissingMaster 52 | ---| TransferIsInProgress 53 | ---| UnreachableReplicaset 54 | ---| NoRouteToBucket 55 | ---| NonEmpty 56 | ---| UnreachableMaster 57 | ---| OutOfSync 58 | ---| HighReplicationLag 59 | ---| UnreachableReplica 60 | ---| LowRedundancy 61 | ---| InvalidRebalancing 62 | ---| SuboptimalReplica 63 | ---| UnknownBuckets 64 | ---| ReplicasetIsLocked 65 | ---| ObjectIsOutdated 66 | ---| BucketIsLocked 67 | ---| InvalidCfg 68 | ---| BucketIsPinned 69 | ---| TooManyReceiving 70 | ---| StorageIsReferenced 71 | ---| StorageRefAdd 72 | ---| StorageRefUse 73 | ---| StorageRefDel 74 | ---| BucketRecvDataError 75 | ---| MultipleMastersFound 76 | ---| ReplicasetInBackoff 77 | ---| StorageIsDisabled 78 | ---| BucketIsCorrupted 79 | ---| RouterIsDisabled 80 | ---| BucketGcError 81 | ---| StorageCfgIsInProgress 82 | ---| RouterCfgIsInProgress 83 | 84 | --- It is created on sharding errors like 85 | --- replicaset unavailability, master absence etc. It has type = 86 | --- 'ShardingError'. 87 | ---@class VshardError 88 | ---@field message string 89 | ---@field type "ShardingError" 90 | ---@field code VshardErrCode 91 | ---@field name string 92 | 93 | ---@class WrongBucket: VshardError 94 | ---@field name "WRONG_BUCKET" 95 | ---@field code 1 96 | ---@field bucket_id number 97 | ---@field reason string 98 | ---@field destination string 99 | 100 | ---@class NonMaster: VshardError 101 | ---@field name "NON_MASTER" 102 | ---@field code 2 103 | ---@field replica_uuid UUID 104 | ---@field replicaset_uuid UUID 105 | ---@field master_uuid UUID 106 | 107 | ---@class BucketAlreadyExists: VshardError 108 | ---@field name "BUCKET_ALREADY_EXISTS" 109 | ---@field code 3 110 | ---@field bucket_id number 111 | 112 | ---@class NoSuchReplicaset: VshardError 113 | ---@field name "NO_SUCH_REPLICASET" 114 | ---@field code 4 115 | ---@field replicaset_uuid UUID 116 | 117 | ---@class MoveToSelf: VshardError 118 | ---@field name "MOVE_TO_SELF" 119 | ---@field code 5 120 | ---@field bucket_id number 121 | ---@field replicaset_uuid UUID 122 | 123 | ---@class MissingMaster: VshardError 124 | ---@field name "MISSING_MASTER" 125 | ---@field code 6 126 | ---@field replicaset_uuid UUID 127 | 128 | ---@class TransferIsInProgress: VshardError 129 | ---@field name "TRANSFER_IS_IN_PROGRESS" 130 | ---@field code 7 131 | ---@field destination string 132 | ---@field bucket_id number 133 | 134 | ---@class UnreachableReplicaset: VshardError 135 | ---@field name "UNREACHABLE_REPLICASET" 136 | ---@field code 8 137 | ---@field unreachable_uuid UUID 138 | ---@field bucket_id number 139 | 140 | ---@class NoRouteToBucket: VshardError 141 | ---@field name "NO_ROUTE_TO_BUCKET" 142 | ---@field code 9 143 | ---@field bucket_id number 144 | 145 | ---@class NonEmpty: VshardError 146 | ---@field name "NON_EMPTY" 147 | ---@field code 10 148 | 149 | ---@class UnreachableMaster: VshardError 150 | ---@field name "UNREACHABLE_MASTER" 151 | ---@field code 11 152 | ---@field reason string 153 | ---@field uuid UUID 154 | 155 | ---@class OutOfSync: VshardError 156 | ---@field name "OUT_OF_SYNC" 157 | ---@field code 12 158 | 159 | ---@class HighReplicationLag: VshardError 160 | ---@field name "HIGH_REPLICATION_LAG" 161 | ---@field code 13 162 | ---@field lag number 163 | 164 | ---@class UnreachableReplica: VshardError 165 | ---@field name "UNREACHABLE_REPLICA" 166 | ---@field code 14 167 | ---@field unreachable_uuid UUID 168 | 169 | ---@class LowRedundancy: VshardError 170 | ---@field name "LOW_REDUNDANCY" 171 | ---@field code 15 172 | 173 | ---@class InvalidRebalancing: VshardError 174 | ---@field name "INVALID_REBALANCING" 175 | ---@field code 16 176 | 177 | ---@class SuboptimalReplica: VshardError 178 | ---@field name "SUBOPTIMAL_REPLICA" 179 | ---@field code 17 180 | 181 | ---@class UnknownBuckets: VshardError 182 | ---@field name "UNKNOWN_BUCKETS" 183 | ---@field code 18 184 | ---@field not_discovered_cnt number 185 | 186 | ---@class ReplicasetIsLocked: VshardError 187 | ---@field name "REPLICASET_IS_LOCKED" 188 | ---@field code 19 189 | 190 | ---@class ObjectIsOutdated: VshardError 191 | ---@field name "OBJECT_IS_OUTDATED" 192 | ---@field code 20 193 | 194 | ---@class RouterAlreadyExists: VshardError 195 | ---@field name "ROUTER_ALREADY_EXISTS" 196 | ---@field code 21 197 | ---@field router_name string 198 | 199 | ---@class BucketIsLocked: VshardError 200 | ---@field name "BUCKET_IS_LOCKED" 201 | ---@field code 22 202 | ---@field bucket_id number 203 | 204 | ---@class InvalidCfg: VshardError 205 | ---@field name "INVALID_CFG" 206 | ---@field code 23 207 | ---@field reason string 208 | 209 | ---@class BucketIsPinned: VshardError 210 | ---@field name "BUCKET_IS_PINNED" 211 | ---@field code 24 212 | ---@field bucket_id number 213 | 214 | ---@class TooManyReceiving: VshardError 215 | ---@field name "TOO_MANY_RECEIVING" 216 | ---@field code 25 217 | 218 | ---@class StorageIsReferenced: VshardError 219 | ---@field name "STORAGE_IS_REFERENCED" 220 | ---@field code 26 221 | 222 | ---@class StorageRefAdd: VshardError 223 | ---@field name "STORAGE_REF_ADD" 224 | ---@field code 27 225 | ---@field reason string 226 | 227 | ---@class StorageRefUse: VshardError 228 | ---@field name "STORAGE_REF_USE" 229 | ---@field code 28 230 | ---@field reason string 231 | 232 | ---@class StorageRefDel: VshardError 233 | ---@field name "STORAGE_REF_DEL" 234 | ---@field code 29 235 | ---@field reason string 236 | 237 | ---@class BucketRecvDataError: VshardError 238 | ---@field name "BUCKET_RECV_DATA_ERROR" 239 | ---@field code 30 240 | ---@field bucket_id number 241 | ---@field space string 242 | ---@field tuple table 243 | ---@field reason string 244 | 245 | ---@class MultipleMastersFound: VshardError 246 | ---@field name "MULTIPLE_MASTERS_FOUND" 247 | ---@field code 31 248 | ---@field replicaset_uuid UUID 249 | ---@field master1 string 250 | ---@field master2 string 251 | 252 | ---@class ReplicasetInBackoff: VshardError 253 | ---@field name "REPLICASET_IN_BACKOFF" 254 | ---@field code 32 255 | ---@field replicaset_uuid UUID 256 | ---@field error table 257 | 258 | ---@class StorageIsDisabled: VshardError 259 | ---@field name "STORAGE_IS_DISABLED" 260 | ---@field code 33 261 | 262 | --- That is similar to WRONG_BUCKET, but the latter is not critical. It 263 | --- usually can be retried. Corruption is a critical error, it requires 264 | --- more attention. 265 | ---@class BucketIsCorrupted: VshardError 266 | ---@field name "BUCKET_IS_CORRUPTED" 267 | ---@field code 34 268 | ---@field reason string 269 | 270 | ---@class RouterIsDisabled: VshardError 271 | ---@field name "ROUTER_IS_DISABLED" 272 | ---@field code 35 273 | ---@field reason string 274 | 275 | ---@class BucketGcError: VshardError 276 | ---@field name "BUCKET_GC_ERROR" 277 | ---@field code 36 278 | ---@field reason string 279 | 280 | ---@class StorageCfgIsInProgress: VshardError 281 | ---@field name "STORAGE_CFG_IS_IN_PROGRESS" 282 | ---@field code 37 283 | 284 | ---@class RouterCfgIsInProgress: VshardError 285 | ---@field name "ROUTER_CFG_IS_IN_PROGRESS" 286 | ---@field code 38 287 | ---@field router_name string 288 | 289 | error.code = { 290 | WRONG_BUCKET = 1, 291 | NON_MASTER = 2, 292 | BUCKET_ALREADY_EXISTS = 3, 293 | NO_SUCH_REPLICASET = 4, 294 | MOVE_TO_SELF = 5, 295 | MISSING_MASTER = 6, 296 | TRANSFER_IS_IN_PROGRESS = 7, 297 | UNREACHABLE_REPLICASET = 8, 298 | NO_ROUTE_TO_BUCKET = 9, 299 | NON_EMPTY = 10, 300 | UNREACHABLE_MASTER = 11, 301 | OUT_OF_SYNC = 12, 302 | HIGH_REPLICATION_LAG = 13, 303 | UNREACHABLE_REPLICA = 14, 304 | LOW_REDUNDANCY = 15, 305 | INVALID_REBALANCING = 16, 306 | SUBOPTIMAL_REPLICA = 17, 307 | UNKNOWN_BUCKETS = 18, 308 | REPLICASET_IS_LOCKED = 19, 309 | OBJECT_IS_OUTDATED = 20, 310 | ROUTER_ALREADY_EXISTS = 21, 311 | BUCKET_IS_LOCKED = 22, 312 | INVALID_CFG = 23, 313 | BUCKET_IS_PINNED = 24, 314 | TOO_MANY_RECEIVING = 25, 315 | STORAGE_IS_REFERENCED = 26, 316 | STORAGE_REF_ADD = 27, 317 | STORAGE_REF_USE = 28, 318 | STORAGE_REF_DEL = 29, 319 | BUCKET_RECV_DATA_ERROR = 30, 320 | MULTIPLE_MASTERS_FOUND = 31, 321 | REPLICASET_IN_BACKOFF = 32, 322 | STORAGE_IS_DISABLED = 33, 323 | BUCKET_IS_CORRUPTED = 34, 324 | ROUTER_IS_DISABLED = 35, 325 | BUCKET_GC_ERROR = 36, 326 | STORAGE_CFG_IS_IN_PROGRESS = 37, 327 | ROUTER_CFG_IS_IN_PROGRESS = 38, 328 | } 329 | 330 | --- Unpacking and and adding serialization meta table to json 331 | ---@param err BoxErrorObject 332 | ---@return BoxErrorObject 333 | function error.box(err) end 334 | 335 | -- Construct an vshard error. 336 | ---@param code VshardErrCode Vshard error code 337 | ---@param ... any From `error_message_template` `args` field. Caller have to pass at least as many arguments as `msg` field requires. 338 | ---@return VshardError 339 | function error.vshard(code, ...) end 340 | 341 | -- Convert error object from pcall to lua, box or vshard error object. 342 | ---@param err any 343 | ---@return VshardError|BoxErrorObject 344 | function error.make(err) end 345 | 346 | --- Restore an error object from its string serialization. 347 | ---@param err_str string 348 | ---@return VshardError 349 | function error.from_string(err_str) end 350 | 351 | ---Make alert message 352 | ---@param code number 353 | ---@param ... any 354 | ---@return table 355 | function error.alert(code, ...) end 356 | 357 | --- Create a timeout error object 358 | ---@return BoxErrorObject 359 | function error.timeout() end 360 | 361 | return error 362 | -------------------------------------------------------------------------------- /Library/fiber.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | ---A fiber is a set of instructions which are executed with cooperative multitasking. 3 | ---Fibers managed by the fiber module are associated with a user-supplied function called the fiber function. 4 | ---A fiber has three possible states, detectable by fiber.status(): running, suspended or dead. 5 | ---When a fiber is created with fiber.create(), it is running. 6 | ---When a fiber is created with fiber.new() or yields control with fiber.sleep(), it is suspended. 7 | ---When a fiber ends (because the fiber function ends), it is dead. 8 | ---All fibers are part of the fiber registry. 9 | ---This registry can be searched with fiber.find() - via fiber id (fid), which is a numeric identifier. 10 | ---A runaway fiber can be stopped with fiber_object.cancel. 11 | ---However, fiber_object.cancel is advisory — it works only if the runaway fiber calls fiber.testcancel() occasionally. 12 | ---Most box.* functions, such as box.space…delete() or box.space…update(), do call fiber.testcancel() but box.space…select{} does not. 13 | ---In practice, a runaway fiber can only become unresponsive if it does many computations and does not check whether it has been cancelled. 14 | ---Like all Lua objects, dead fibers are garbage collected. 15 | ---The Lua garbage collector frees pool allocator memory owned by the fiber, resets all fiber data, 16 | ---and returns the fiber (now called a fiber carcass) to the fiber pool. 17 | ---The carcass can be reused when another fiber is created. 18 | ---A fiber has all the features of a Lua coroutine and all the programming concepts 19 | ---that apply for Lua coroutines will apply for fibers as well. 20 | ---However, Tarantool has made some enhancements for fibers and has used fibers internally. 21 | ---So, although use of coroutines is possible and supported, use of fibers is recommended. 22 | ---@module 'fiber' 23 | 24 | local fiber = {} 25 | 26 | ---Create and start a fiber 27 | ---@param func fun(...:any) the function to be associated with the fiber 28 | ---@vararg ... what will be passed to function 29 | ---@return Fiber 30 | function fiber.create(func, ...) end 31 | 32 | ---Create but do not start a fiber 33 | ---@param func fun(...:any) the function to be associated with the fiber 34 | ---@vararg ... what will be passed to function 35 | ---@return Fiber 36 | function fiber.new(func, ...) end 37 | 38 | ---Get a fiber object 39 | ---@return Fiber 40 | function fiber.self() end 41 | 42 | ---Get a fiber object by ID 43 | ---@param id integer numeric identifier of the fiber. 44 | ---@return Fiber 45 | function fiber.find(id) end 46 | 47 | ---Yield control to the scheduler and sleep for the specified number of seconds. 48 | ---Only the current fiber can be made to sleep. 49 | ---@async 50 | ---@param timeout number number of seconds to sleep. 51 | function fiber.sleep(timeout) end 52 | 53 | ---Yield control to the scheduler. Equivalent to `fiber.sleep(0)`. 54 | ---@async 55 | function fiber.yield() end 56 | 57 | ---Return the status of the current fiber. 58 | ---Or, if optional fiber_object is passed, return the status of the specified fiber. 59 | ---@param fiber_object? Fiber 60 | ---@return "running"|"dead"|"supspected" 61 | function fiber.status(fiber_object) end 62 | 63 | ---@class FiberInfo 64 | ---@field csw number number of context switches. 65 | ---@field memory { total: number, used: number } `total` is memory occupied by the fiber as a C structure, its stack, etc. `actual` is memory used by the fiber. 66 | ---@field time number duplicates the “time” entry from fiber.top().cpu for each fiber. (Only shown if fiber.top is enabled.) 67 | ---@field name string name of the fiber 68 | ---@field fid number id of the fiber 69 | ---@field backtrace { C: string, L: string }[] fiber’s stack trace 70 | 71 | ---Get information about all fibers 72 | ---@param opts? {backtrace:boolean, bt:boolean}` 73 | ---@return table 74 | function fiber.info(opts) end 75 | 76 | ---@return integer fiber_id returns current fiber id 77 | function fiber.id() end 78 | 79 | ---@class FiberTop 80 | ---@field instant number (in percent), which indicates the share of time the fiber was executing during the previous event loop iteration. 81 | ---@field average number (in percent), which is calculated as an exponential moving average of instant values over all the previous event loop iterations. 82 | ---@field time number (in seconds), which estimates how much CPU time each fiber spent processing during its lifetime. 83 | 84 | ---Return a table of alive fibers and show their CPU consumption 85 | ---@return { cpu: table, cpu_misses: number } 86 | function fiber.top() end 87 | 88 | ---Cancel a fiber 89 | ---@param fiber_object Fiber 90 | ---@overload fun(fiber_id: integer) 91 | function fiber.kill(fiber_object) end 92 | 93 | ---Check if the current fiber has been cancelled 94 | function fiber.testcancel() end 95 | 96 | ---Get the system time in seconds as Lua number 97 | ---``` 98 | ---tarantool> fiber.time(), fiber.time() 99 | --- - 1448466279.2415 100 | --- - 1448466279.2415 101 | ---``` 102 | ---@return number 103 | function fiber.time() end 104 | 105 | ---Get the system time in microseconds 106 | ---@return int64_t 107 | function fiber.time64() end 108 | 109 | ---Get the monotonic time in seconds 110 | ---@return number 111 | function fiber.clock() end 112 | 113 | ---Get the monotonic time in microseconds 114 | ---@return ffi.cdata* 115 | function fiber.clock64() end 116 | 117 | function fiber.top_enable() end 118 | 119 | function fiber.top_disable() end 120 | 121 | ---Check whether a slice for the current fiber is over. 122 | --- 123 | ---A fiber slice limits the time period of executing a fiber without yielding control. 124 | function fiber.check_slice() end 125 | 126 | ---@class fiber.slice 127 | ---@field warn number 128 | ---@field err number 129 | 130 | ---Set a slice for the current fiber execution. 131 | --- 132 | ---A fiber slice limits the time period of executing a fiber without yielding control. 133 | ---@param slice fiber.slice|number a time period (in seconds) that specifies the error slice 134 | function fiber.set_slice(slice) end 135 | 136 | ---Set the default maximum slice for all fibers. 137 | --- 138 | ---A fiber slice limits the time period of executing a fiber without yielding control. 139 | ---@param slice fiber.slice|number a time period (in seconds) that specifies the error slice 140 | function fiber.set_max_slice(slice) end 141 | 142 | ---Extend a slice for the current fiber execution. 143 | ---For example, if the default error slice is set using fiber.set_max_slice() to 3 seconds, extend_slice(1) 144 | ---extends the error slice to 4 seconds. 145 | ---@param slice fiber.slice|number a time period (in seconds) that specifies the error slice 146 | function fiber.extend_slice(slice) end 147 | 148 | ---@class Fiber: userdata 149 | local fiber_object = {} 150 | 151 | ---Get a fiber’s ID 152 | ---@return integer # fiber id 153 | function fiber_object:id() end 154 | 155 | ---Gets or changes a fiber’s name 156 | ---@param name? string 157 | ---@param options? {truncate: boolean} 158 | ---@return string name 159 | function fiber_object:name(name, options) end 160 | 161 | ---Gets or changes a fiber’s name 162 | ---@param name? string 163 | ---@param options? {truncate: boolean} 164 | ---@return string name 165 | function fiber.name(name, options) end 166 | 167 | ---Get a fiber’s status 168 | ---@return "dead"|"running"|"suspended" 169 | function fiber_object:status() end 170 | 171 | ---Cancel a fiber 172 | function fiber_object:cancel() end 173 | 174 | ---Wakeup a fiber 175 | function fiber_object:wakeup() end 176 | 177 | ---returns csw of the fiber 178 | ---@return number 179 | function fiber_object:csw() end 180 | 181 | ---Local storage within the fiber 182 | fiber_object.storage = {} 183 | 184 | ---Make it possible for a new fiber to join 185 | ---`fiber_object:set_joinable(true)` makes a fiber joinable; 186 | --- 187 | ---`fiber_object:set_joinable(false)` makes a fiber not joinable; the default is `false`. 188 | --- 189 | ---A joinable fiber can be waited for, with fiber_object:join(). 190 | --- 191 | --- 192 | ---@param true_or_false boolean 193 | function fiber_object:set_joinable(true_or_false) end 194 | 195 | ---@async 196 | ---“Join” a joinable fiber. That is, let the fiber’s function run and wait until the fiber’s status is ‘dead’ (normally a status becomes ‘dead’ when the function execution finishes). 197 | --- 198 | ---Joining will cause a yield, therefore, if the fiber is currently in a suspended state, execution of its fiber function will resume. 199 | --- 200 | ---This kind of waiting is more convenient than going into a loop and periodically checking the status; 201 | --- 202 | ---however, it works only if the fiber was created with `fiber.new()` and was made joinable with `fiber_object:set_joinable()`. 203 | ---Wait for a fiber’s state to become ‘dead’ 204 | ---@return boolean success, any ... 205 | function fiber_object:join() end 206 | 207 | ---@class fiber.channel 208 | local channel_object = {} 209 | 210 | ---Create a communication channel 211 | ---@param capacity? integer the maximum number of slots (spaces for channel:put messages) that can be in use at once. The default is 0. 212 | ---@return fiber.channel 213 | function fiber.channel(capacity) end 214 | 215 | ---Send a message via a channel 216 | ---@async 217 | ---@param message any 218 | ---@param timeout? number 219 | ---@return boolean success If timeout is specified, and there is no free slot in the channel for the duration of the timeout, then the return value is false. If the channel is closed, then the return value is false. Otherwise, the return value is true, indicating success. 220 | function channel_object:put(message, timeout) end 221 | 222 | ---Close a channel 223 | function channel_object:close() end 224 | 225 | ---Fetch a message from a channel 226 | ---@async 227 | ---@param timeout? number maximum number of seconds to wait for a message. Default: infinity. 228 | ---@return any message 229 | function channel_object:get(timeout) end 230 | 231 | ---Check if a channel is empty 232 | ---@return boolean # is_empty 233 | function channel_object:is_empty() end 234 | 235 | ---Count messages in a channel 236 | ---@return integer 237 | function channel_object:count() end 238 | 239 | ---Returns size of channel 240 | ---@return integer 241 | function channel_object:size() end 242 | 243 | ---Check if a channel is full 244 | ---@return boolean # is_full 245 | function channel_object:is_full() end 246 | 247 | ---Check if an empty channel has any readers waiting 248 | ---@return boolean 249 | function channel_object:has_readers() end 250 | 251 | ---Check if a full channel has any writers waiting 252 | ---@return boolean 253 | function channel_object:has_writers() end 254 | 255 | ---Check if a channel is closed 256 | ---@return boolean # is_closed 257 | function channel_object:is_closed() end 258 | 259 | ---@class fiber.cond:userdata 260 | local cond_object = {} 261 | 262 | ---Create a condition variable 263 | ---@return fiber.cond 264 | function fiber.cond() end 265 | 266 | ---Make a fiber go to sleep until woken by another fiber 267 | ---@async 268 | ---@param timeout? number number of seconds to wait, default = forever. 269 | ---@return boolean was_signalled If timeout is provided, and a signal doesn’t happen for the duration of the timeout, wait() returns false. If a signal or broadcast happens, wait() returns true. 270 | function cond_object:wait(timeout) end 271 | 272 | ---Wake up a single fiber 273 | function cond_object:signal() end 274 | 275 | ---Wake up all fibers 276 | function cond_object:broadcast() end 277 | 278 | return fiber 279 | -------------------------------------------------------------------------------- /Library/metrics/init.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | local metrics = {} 5 | 6 | ---Enable default Tarantool metrics such as network, memory, operations, etc. 7 | --- 8 | --- **Default metric names:** 9 | --- 10 | --- network, operations, system, replicas, info, slab, runtime, memory, event_loop, 11 | --- 12 | --- spaces, fibers, cpu, vinyl, memtx, luajit, cartridge_issues, cartridge_failover, clock 13 | ---@param include string[]? table containing the names of the default metrics that you need to enable. 14 | ---@param exclude string[]? table containing the names of the default metrics that you need to exclude. 15 | function metrics.enable_default_metrics(include, exclude) end 16 | 17 | 18 | --- All collectors support providing label_pairs on data modification. A label is a piece of metainfo that you associate with a metric in the key-value format. See tags in Graphite and labels in Prometheus. Labels are used to differentiate between the characteristics of a thing being measured. For example, in a metric associated with the total number of HTTP requests, you can represent methods and statuses as label pairs: 19 | --- 20 | --- http_requests_total_counter:inc(1, {method = 'POST', status = '200'}) 21 | --- You don’t have to predefine labels in advance. 22 | --- 23 | --- With labels, you can extract new time series (visualize their graphs) by specifying conditions with regard to label values. The example above allows extracting the following time series: 24 | --- 25 | --- The total number of requests over time with method = "POST" (and any status). 26 | --- The total number of requests over time with status = 500 (and any method). 27 | --- You can also set global labels by calling metrics.set_global_labels({ label = value, ...}) 28 | ---@alias label_pairs table 29 | 30 | ---Set the global labels to be added to every observation. 31 | --- 32 | --- Global labels are applied only to metric collection. They have no effect on how observations are stored. 33 | --- 34 | --- Global labels can be changed on the fly. 35 | --- 36 | ---label_pairs from observation objects have priority over global labels. If you pass label_pairs to an observation method with the same key as some global label, the method argument value will be used. 37 | --- 38 | -- **Note** that both label names and values in label_pairs are treated as strings. 39 | ---@param label_pairs label_pairs 40 | function metrics.set_global_labels(label_pairs) end 41 | 42 | 43 | 44 | 45 | ---@class Counter 46 | local counter_obj = {} 47 | 48 | ---Register a new counter 49 | ---@param name string collector name. Must be unique. 50 | ---@param help string? collector description. 51 | ---@return Counter 52 | function metrics.counter(name, help) end 53 | 54 | 55 | ---Increment the observation for label_pairs. If label_pairs doesn’t exist, the method creates it. 56 | ---@param num number increment value. 57 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 58 | function counter_obj:inc(num, label_pairs) end 59 | 60 | 61 | ---@class ObservationObj 62 | ---@field label_pairs label_pairs `label_pairs` key-value table 63 | ---@field timestamp uint64_t current system time (in microseconds) 64 | ---@field value number current value 65 | ---@field metric_name string collector 66 | 67 | 68 | ---Returns an array of observation objects for a given counter. 69 | ---@return ObservationObj[] 70 | function counter_obj:collect() end 71 | 72 | 73 | ---Remove the observation for label_pairs. 74 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 75 | function counter_obj:remove(label_pairs) end 76 | 77 | ---Set the observation for label_pairs to 0. 78 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 79 | function counter_obj:reset(label_pairs) end 80 | 81 | 82 | 83 | ---@class Gauge 84 | local gauge_obj = {} 85 | 86 | 87 | ---Register a new gauge. 88 | ---@param name string collector name. Must be unique. 89 | ---@param help string? collector description. 90 | ---@return Gauge A gauge object. 91 | function metrics.gauge(name, help) end 92 | 93 | 94 | ---Increment the observation for label_pairs. If label_pairs doesn’t exist, the method creates it. 95 | ---@param num number increment value. 96 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 97 | function gauge_obj:inc(num, label_pairs) end 98 | 99 | ---Decrement the observation for label_pairs. If label_pairs doesn’t exist, the method creates it. 100 | ---@param num number Decrement value. 101 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 102 | function gauge_obj:dec(num, label_pairs) end 103 | 104 | 105 | ---Sets the observation for label_pairs to num. 106 | ---@param num number set value. 107 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 108 | function gauge_obj:set(num, label_pairs) end 109 | 110 | ---Returns an array of observation objects for a given gauge. 111 | ---@return ObservationObj[] 112 | function gauge_obj:collect() end 113 | 114 | ---Remove the observation for label_pairs. 115 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 116 | function gauge_obj:remove(label_pairs) end 117 | 118 | 119 | ---Register a new histogram. 120 | ---@param name string collector name. Must be unique. 121 | ---@param help? string collector description. 122 | ---@param buckets? number[] histogram buckets (an array of sorted positive numbers). The infinity bucket (INF) is appended automatically. Default: {.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 5.0, 7.5, 10.0, INF}. 123 | function metrics.histogram(name, help, buckets) end 124 | 125 | 126 | ---A histogram is basically a set of collectors: 127 | --- 128 | ---name .. "_sum" – a counter holding the sum of added observations. 129 | --- 130 | ---name .. "_count" – a counter holding the number of added observations. 131 | --- 132 | ---name .. "_bucket" – a counter holding all bucket sizes under the label le (less or equal). To access a specific bucket – x (where x is a number), specify the value x for the label. 133 | ---@class Histogram 134 | local histogram_obj = {} 135 | 136 | 137 | ---Record a new value in a histogram. This increments all bucket sizes under the labels le >= num and the labels that match label_pairs. 138 | ---@param num number value to put in the histogram. 139 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. All internal counters that have these labels specified observe new counter values. Note that both label names and values in label_pairs are treated as strings. 140 | function histogram_obj:observe(num, label_pairs) end 141 | 142 | ---Return a concatenation of counter_obj:collect() across all internal counters of histogram_obj. 143 | ---@return ObservationObj[] 144 | function histogram_obj:collect() end 145 | 146 | ---Remove the observation for label_pairs. 147 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 148 | function histogram_obj:remove(label_pairs) end 149 | 150 | 151 | ---Register a new summary. Quantile computation is based on the «Effective computation of biased quantiles over data streams» algorithm. 152 | ---@param name string сollector name. Must be unique 153 | ---@param help string? collector description 154 | ---@param objectives table? a list of «targeted» φ-quantiles in the {quantile = error, ... } form. Example: {[0.5]=0.01, [0.9]=0.01, [0.99]=0.01}. The targeted φ-quantile is specified in the form of a φ-quantile and the tolerated error. For example, {[0.5] = 0.1} means that the median (= 50th percentile) is to be returned with a 10-percent error. Note that percentiles and quantiles are the same concept, except that percentiles are expressed as percentages. The φ-quantile must be in the interval [0, 1]. A lower tolerated error for a φ-quantile results in higher memory and CPU usage during summary calculation. 155 | ---@param params table? table of the summary parameters used to configuring the sliding time window. This window consists of several buckets to store observations. New observations are added to each bucket. After a time period, the head bucket (from which observations are collected) is reset, and the next bucket becomes the new head. This way, each bucket stores observations for max_age_time * age_buckets_count seconds before it is reset. max_age_time sets the duration of each bucket’s lifetime – that is, how many seconds the observations are kept before they are discarded. age_buckets_count sets the number of buckets in the sliding time window. This variable determines the number of buckets used to exclude observations older than max_age_time from the summary. The value is a trade-off between resources (memory and CPU for maintaining the bucket) and how smooth the time window moves. Default value: {max_age_time = math.huge, age_buckets_count = 1}. 156 | ---@return SummaryObj 157 | function metrics.summary(name, help, objectives, params) end 158 | 159 | 160 | --- **A summary represents a set of collectors:** 161 | --- 162 | ---name .. "_sum" – a counter holding the sum of added observations. 163 | --- 164 | ---name .. "_count" – a counter holding the number of added observations. 165 | --- 166 | ---name holds all the quantiles under observation that find themselves under the label quantile (less or equal). To access bucket x (where x is a number), specify the value x for the label quantile. 167 | ---object summary_obj 168 | ---@class SummaryObj 169 | local summary_obj = {} 170 | 171 | 172 | 173 | --- Record a new value in a summary. 174 | ---@param num number value to put in the data stream 175 | ---@param label_pairs label_pairs a table containing label names as keys, label values as values. All internal counters that have these labels specified observe new counter values. You can’t add the "quantile" label to a summary. It is added automatically. If max_age_time and age_buckets_count are set, the observed value is added to each bucket. Note that both label names and values in label_pairs are treated as strings. 176 | function summary_obj:observe(num, label_pairs) end 177 | 178 | 179 | --- Return a concatenation of counter_obj:collect() across all internal counters of summary_obj. For the description of observation, see counter_obj:collect(). If max_age_time and age_buckets_count are set, quantile observations are collected only from the head bucket in the sliding time window, not from every bucket. If no observations were recorded, the method will return NaN in the values. 180 | ---@return ObservationObj 181 | function summary_obj:collect() end 182 | 183 | 184 | ---Remove the observation for label_pairs. 185 | ---@param label_pairs label_pairs table containing label names as keys, label values as values. Note that both label names and values in label_pairs are treated as strings. 186 | function summary_obj:remove(label_pairs) end 187 | 188 | 189 | return metrics 190 | -------------------------------------------------------------------------------- /Library/msgpack.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | ---The msgpack module decodes raw MsgPack strings by converting them to Lua objects, 4 | ---and encodes Lua objects by converting them to raw MsgPack strings. 5 | ---@module 'msgpack' 6 | 7 | local msgpack = {} 8 | 9 | function msgpack.new() 10 | return msgpack 11 | end 12 | 13 | ---@type metatable 14 | msgpack.array_mt = {} 15 | 16 | ---@type metatable 17 | msgpack.map_mt = {} 18 | 19 | ---@class msgpackCfg 20 | ---@field encode_max_depth? integer (default: 128) Max recursion depth for encoding 21 | ---@field encode_deep_as_nil? boolean (default: false) A flag saying whether to crop tables with nesting level deeper than cfg.encode_max_depth. Not-encoded fields are replaced with one null. If not set, too deep nesting is considered an error. 22 | ---@field encode_invalid_numbers? boolean (deafult: true) A flag saying whether to enable encoding of NaN and Inf numbers 23 | ---@field encode_number_precision? number (default: 14) Precision of floating point numbers 24 | ---@field encode_load_metatables? boolean (default: true) A flag saying whether the serializer will follow __serialize metatable field 25 | ---@field encode_use_tostring? boolean (default: false) A flag saying whether to use `tostring()` for unknown types 26 | ---@field encode_invalid_as_nil? boolean (default: false) A flag saying whether use NULL for non-recognized types 27 | ---@field encode_sparse_convert? boolean (default: true) A flag saying whether to handle excessively sparse arrays as maps. See detailed description below. 28 | ---@field encode_sparse_ratio? number (default: 2) 1/`encode_sparse_ratio` is the permissible percentage of missing values in a sparse array. 29 | ---@field encode_sparse_safe? number (default: 10) A limit ensuring that small Lua arrays are always encoded as sparse arrays (instead of generating an error or encoding as a map) 30 | ---@field encode_error_as_ext boolean (default: true) Specify how error objects (box.error.new()) are encoded in the MsgPack format 31 | ---@field decode_invalid_numbers? boolean (default: true) A flag saying whether to enable decoding of NaN and Inf numbers 32 | ---@field decode_save_metatables? boolean (default: true) A flag saying whether to set metatables for all arrays and maps 33 | ---@field decode_max_depth? integer (default: 128) Max recursion depth for decoding 34 | ---Set values that affect the behavior of `msgpack.encode` and `msgpack.decode` 35 | ---@overload fun(cfg: msgpackCfg) 36 | msgpack.cfg = {} 37 | 38 | ---Convert a Lua object to a MsgPack string 39 | ---@param value any either a scalar value or a Lua table value. 40 | ---@return string # raw MsgPack string 41 | function msgpack.encode(value) end 42 | 43 | ---Convert a Lua object to a raw MsgPack string in an ibuf, which is a buffer such as `buffer.ibuf()` creates. 44 | ---As with encode(lua_value), the result is a raw MsgPack string, but it goes to the ibuf output instead of being returned. 45 | --- 46 | --- ibuf = require('buffer').ibuf() 47 | --- msgpack_string_size = require('msgpack').encode({'a'}, ibuf) 48 | --- msgpack_string = require('ffi').string(ibuf.rpos, msgpack_string_size) 49 | --- string.hex(msgpack_string) 50 | ---@param value any either a scalar value or a Lua table value. 51 | ---@param ibuf BufferObject (output parameter) where the result raw MsgPack string goes 52 | ---@return integer # number of bytes in the output 53 | function msgpack.encode(value, ibuf) end 54 | 55 | ---Convert a MsgPack string to a Lua object. 56 | ---@param msgpack_string string a raw MsgPack string. 57 | ---@param start_position? integer where to start, minimum = 1, maximum = string length, default = 1. 58 | ---@return any (if `msgpack_string` is a valid raw MsgPack string) the original contents of msgpack_string, formatted as a Lua object, usually a Lua table, (otherwise) a scalar value, such as a string or a number; 59 | ---@return integer? next_start_position If `decode` stops after parsing as far as byte N in `msgpack_string`, 60 | ---then `next_start_position` will equal N + 1, and `decode(msgpack_string, next_start_position)` will continue parsing from where the previous decode stopped, plus 1. 61 | ---Normally decode parses all of msgpack_string, so “next_start_position” will equal string.len(msgpack_string) + 1. 62 | function msgpack.decode(msgpack_string, start_position) end 63 | 64 | ---@param c_style_string_pointer ffi.cdata* 65 | ---@param size integer 66 | ---@return any (if `c_style_string_pointer` is a valid raw MsgPack string) the original contents of `msgpack_string`, formatted as a Lua object, usually a Lua table, (otherwise) a scalar value, such as a string or a number; 67 | ---@return ffi.cdata* returned_pointer = a C-style pointer to the byte after what was passed, so that `c_style_string_pointer` + `size` = `returned_pointer` 68 | function msgpack.decode(c_style_string_pointer, size) end 69 | 70 | ---Convert a MsgPack string to a Lua object. 71 | ---@param msgpack_string string a raw MsgPack string. 72 | ---@param start_position? integer where to start, minimum = 1, maximum = string length, default = 1. 73 | ---@return any (if `msgpack_string` is a valid raw MsgPack string) the original contents of msgpack_string, formatted as a Lua object, usually a Lua table, (otherwise) a scalar value, such as a string or a number; 74 | ---@return integer? next_start_position If `decode` stops after parsing as far as byte N in `msgpack_string`, 75 | ---then `next_start_position` will equal N + 1, and `decode(msgpack_string, next_start_position)` will continue parsing from where the previous decode stopped, plus 1. 76 | ---Normally decode parses all of msgpack_string, so “next_start_position” will equal string.len(msgpack_string) + 1. 77 | function msgpack.decode_unchecked(msgpack_string, start_position) end 78 | 79 | ---Input and output are the same as for `decode(C_style_string_pointer)`, except that size is not needed. 80 | ---Some checking is skipped, and `decode_unchecked(C_style_string_pointer)` can operate with string pointers to buffers which `decode(C_style_string_pointer)` cannot handle. 81 | ---@param c_style_string_pointer ffi.cdata* 82 | ---@return any (if `c_style_string_pointer` is a valid raw MsgPack string) the original contents of `msgpack_string`, formatted as a Lua object, usually a Lua table, (otherwise) a scalar value, such as a string or a number; 83 | ---@return ffi.cdata* returned_pointer = a C-style pointer to the byte after what was passed, so that `c_style_string_pointer` + `size` = `returned_pointer` 84 | function msgpack.decode_unchecked(c_style_string_pointer) end 85 | 86 | ---Call the MsgPuck’s `mp_decode_array` function and return the array size and a pointer to the first array component. 87 | ---A subsequent call to `msgpack_decode` can decode the component instead of the whole array. 88 | ---@param byte_array ffi.cdata* a pointer to a raw MsgPack string. 89 | ---@param size integer a number greater than or equal to the string’s length 90 | ---@return integer # the size of the array 91 | ---@return ffi.cdata* # a pointer to after the array header 92 | function msgpack.decode_array_header(byte_array, size) end 93 | 94 | ---Call the MsgPuck’s `mp_decode_map` function and return the map size and a pointer to the first map component. 95 | ---A subsequent call to `msgpack_decode` can decode the component instead of the whole map. 96 | ---@param byte_array ffi.cdata* a pointer to a raw MsgPack string. 97 | ---@param size integer a number greater than or equal to the raw MsgPack string’s length 98 | ---@return integer # the size of the map 99 | ---@return ffi.cdata* # a pointer to after the map header 100 | function msgpack.decode_map_header(byte_array, size) end 101 | 102 | ---Encode an arbitrary Lua object into the MsgPack format. 103 | ---@param lua_object any 104 | ---@return msgpackObject # encoded MsgPack data encapsulated in a MsgPack object. 105 | function msgpack.object(lua_object) end 106 | 107 | ---Create a MsgPack object from a raw MsgPack string. 108 | ---@param msgpack_string string 109 | ---@return msgpackObject # a MsgPack object 110 | function msgpack.object_from_raw(msgpack_string) end 111 | 112 | ---Create a MsgPack object from a raw MsgPack string. 113 | ---The address of the MsgPack string is supplied as a C-style string pointer such as the `rpos` pointer inside an `ibuf` that the `buffer.ibuf()` creates. 114 | ---A C-style string pointer may be described as `cdata` or `cdata`. 115 | ---@param c_style_string_pointer ffi.cdata* a pointer to a raw MsgPack string. 116 | ---@param size integer number of bytes in the raw MsgPack string. 117 | ---@return msgpackObject # a MsgPack object 118 | function msgpack.object_from_raw(c_style_string_pointer, size) end 119 | 120 | ---Check if the given argument is a MsgPack object. 121 | ---@param some_argument any 122 | ---@return boolean # `true` if the argument is a MsgPack object; otherwise, `false` 123 | function msgpack.is_object(some_argument) end 124 | 125 | ---A MsgPack object that stores arbitrary MsgPack data. 126 | ---To create a MsgPack object from a Lua object or string, use the following methods: 127 | ---`msgpack.object` `msgpack.object_from_raw` 128 | ---@class msgpackObject 129 | ---@field [integer|string] any 130 | local msgpack_object = {} 131 | 132 | ---Decode MsgPack data in the MsgPack object. 133 | ---@param key integer|string 134 | ---@return any 135 | function msgpack_object:get(key) end 136 | 137 | ---Decode MsgPack data in the MsgPack object. 138 | ---@return any 139 | function msgpack_object:decode() end 140 | 141 | ---Create an iterator over the MsgPack data. 142 | ---@return msgpackIteratorObject # an iterator object over the MsgPack data 143 | function msgpack_object:iterator() end 144 | 145 | ---An iterator over a MsgPack array. 146 | ---@class msgpackIteratorObject 147 | local msgpack_iterator_object = {} 148 | 149 | ---Decode a MsgPack array header under the iterator cursor and advance the cursor. 150 | ---After calling this function, the iterator points to the first element of the array or to the value following the array if the array is empty. 151 | ---@return integer # number of elements in the array 152 | function msgpack_iterator_object:decode_array_header() end 153 | 154 | ---Decode a MsgPack map header under the iterator cursor and advance the cursor. 155 | ---After calling this function, the iterator points to the first key stored in the map or to the value following the map if the map is empty. 156 | ---@return integer # number of key-value pairs in the map 157 | function msgpack_iterator_object:decode_map_header() end 158 | 159 | ---Decode a MsgPack value under the iterator cursor and advance the cursor. 160 | ---@return any # a Lua object corresponding to the MsgPack value 161 | function msgpack_iterator_object:decode() end 162 | 163 | ---Return a MsgPack value under the iterator cursor as a MsgPack object without decoding and advance the cursor. 164 | ---The method doesn’t copy MsgPack data. Instead, it takes a reference to the original object. 165 | ---@return msgpackObject 166 | function msgpack_iterator_object:take() end 167 | 168 | ---Copy the specified number of MsgPack values starting from the iterator’s cursor position to a new MsgPack array object and advance the cursor. 169 | ---@param count integer the number of MsgPack values to copy 170 | ---@return msgpackObject # a new MsgPack object 171 | function msgpack_iterator_object:take_array(count) end 172 | 173 | ---Advance the iterator cursor by skipping one MsgPack value under the cursor. Returns nothing. 174 | function msgpack_iterator_object:skip() end 175 | 176 | ---A value comparable to Lua “nil” which may be useful as a placeholder in a tuple. 177 | msgpack.NULL = box.NULL 178 | 179 | return msgpack 180 | -------------------------------------------------------------------------------- /Library/box/space.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@type table 5 | box.space = {} 6 | 7 | ---@class boxSpaceObject: table 8 | ---@field id number Ordinal space number. Spaces can be referenced by either name or number 9 | ---@field name string name of the space 10 | ---@field enabled boolean Whether or not this space is enabled. The value is false if the space has no index. 11 | ---@field engine string 12 | ---@field is_sync boolean 13 | ---@field is_local boolean 14 | ---@field temporary boolean 15 | ---@field field_count number (Default: 0) The required field count for all tuples in this space 16 | ---@field index table kv and list of indexes of space 17 | local boxSpaceObject = {} 18 | 19 | ---Create an index. 20 | ---It is mandatory to create an index for a space before trying to insert tuples into it, or select tuples from it. The first created index will be used as the primary-key index, so it must be unique. 21 | ---@param index_name string name of index, which should conform to the rules for object names 22 | ---@param options boxIndexOptions 23 | ---@return boxIndex 24 | function boxSpaceObject:create_index(index_name, options) end 25 | 26 | ---@class SpaceAlterOptions 27 | ---@field name? string name of the space 28 | ---@field field_count? number fixed count of fields: for example if field_count=5, it is illegal to insert a tuple with fewer than or more than 5 fields 29 | ---@field format? boxSpaceFormat 30 | ---@field is_sync? boolean (Default: false) any transaction doing a DML request on this space becomes synchronous 31 | ---@field temporary? boolean (Default: false) space contents are temporary: changes are not stored in the write-ahead log and there is no replication. Note regarding storage engine: vinyl does not support temporary spaces. 32 | ---@field user? string (Default: current user’s name) name of the user who is considered to be the space’s owner for authorization purposes 33 | 34 | 35 | ---Since version 2.5.2. Alter an existing space. This method changes certain space parameters. 36 | ---@param options SpaceAlterOptions 37 | function boxSpaceObject:alter(options) end 38 | 39 | ---Number of bytes in the space. This number, which is stored in Tarantool’s internal memory, represents the total number of bytes in all tuples, not including index keys 40 | ---@return number bytes 41 | function boxSpaceObject:bsize() end 42 | 43 | ---Return the number of tuples. If compared with len(), this method works slower because count() scans the entire space to count the tuples. 44 | ---@param key? box.tuple|tuple_type[]|scalar 45 | ---@param iterator? boxIterator 46 | ---@return integer number_of_tuples 47 | function boxSpaceObject:count(key, iterator) end 48 | 49 | ---@class boxSpaceFieldFormat 50 | ---@field name? string value may be any string, provided that two fields do not have the same name 51 | ---@field type? "any" | "unsigned" | "string" | "integer" | "number" | "varbinary" | "boolean" | "double" | "decimal" | "uuid" | "array" | "map" | "scalar" value may be any of allowed types 52 | ---@field is_nullable? boolean (Default: false value specifies whether nil can be used as a field value. 53 | ---@field collation? string value specifies the collation used to compare field values. 54 | ---@field constraint? string specifies the constraints that the field value must satisfy. 55 | ---@field foreign_key? string specifies the foreign keys for the field. 56 | 57 | ---@alias boxSpaceFormat boxSpaceFieldFormat[] 58 | ---field names and types: See the illustrations of format clauses in the space_object:format() description and in the box.space._space example. Optional and usually not specified. 59 | 60 | ---Possible errors: 61 | 62 | ---`ER_TRANSACTION_CONFLICT` if a transaction conflict is detected in the MVCC transaction mode. 63 | ---@param key box.tuple|tuple_type[]|scalar 64 | ---@return box.tuple? tuple the deleted tuple 65 | function boxSpaceObject:delete(key) end 66 | 67 | ---Drop a space. The method is performed in background and doesn’t block consequent requests. 68 | function boxSpaceObject:drop() end 69 | 70 | ---Declare field names and types. 71 | ---@param format_clause? boxSpaceFormat a list of field names and types 72 | ---@return nil|boxSpaceFormat nothing_or_existing_format returns current format if format_clause is not given 73 | function boxSpaceObject:format(format_clause) end 74 | 75 | ---Returns current format 76 | ---@return boxSpaceFormat format 77 | function boxSpaceObject:format() end 78 | 79 | ---Search for a tuple in the given space. 80 | ---@param key box.tuple|tuple_type[]|scalar 81 | ---@return box.tuple? tuple the tuple whose index key matches key, or nil. 82 | function boxSpaceObject:get(key) end 83 | 84 | ---Insert a tuple into a space. 85 | ---@param tuple box.tuple|tuple_type[] tuple to be inserted. 86 | ---@return box.tuple tuple the inserted tuple 87 | function boxSpaceObject:insert(tuple) end 88 | 89 | ---Return the number of tuples in the space. If compared with count(), this method works faster because len() does not scan the entire space to count the tuples. 90 | ---@return number number_of_tuples Number of tuples in the space. 91 | function boxSpaceObject:len() end 92 | 93 | ---@alias replaceTrigger 94 | ---| fun(old_tuple: box.tuple, new_tuple: box.tuple, space_name: string, request_type: "INSERT" | "UPDATE" | "REPLACE" | "UPSERT"): box.tuple? 95 | ---| fun(old_tuple: nil, new_tuple: box.tuple, space_name: string, request_type: "INSERT" | "UPDATE" | "REPLACE" | "UPSERT"): box.tuple? 96 | ---| fun(old_tuple: box.tuple, new_tuple: nil, space_name: string, request_type: "DELETE"): box.tuple? 97 | 98 | ---Create a “replace trigger”. The trigger-function will be executed whenever a replace() or insert() or update() or upsert() or delete() happens to a tuple in . 99 | ---@param trigger_func replaceTrigger|nil 100 | ---@param old_trigger_func? replaceTrigger 101 | ---@return replaceTrigger? func the old trigger if it was replaced or deleted 102 | function boxSpaceObject:on_replace(trigger_func, old_trigger_func) end 103 | 104 | ---Create a “replace trigger”. The trigger-function will be executed whenever a replace() or insert() or update() or upsert() or delete() happens to a tuple in . 105 | ---@param trigger_func replaceTrigger|nil 106 | ---@param old_trigger_func? replaceTrigger 107 | ---@return replaceTrigger? func the old trigger if it was replaced or deleted 108 | function boxSpaceObject:before_replace(trigger_func, old_trigger_func) end 109 | 110 | ---Search for a tuple or a set of tuples in the given space, and allow iterating over one tuple at a time. 111 | ---@param key box.tuple|tuple_type[]|scalar value to be matched against the index key, which may be multi-part 112 | ---@param iterator? boxIterator (Default: 'EQ') defines iterator order 113 | ---@return boxSpaceIterator,boxSpaceIteratorParam,boxSpaceIteratorState 114 | function boxSpaceObject:pairs(key, iterator) end 115 | 116 | ---@class boxSpaceIterator: fun.iterator 117 | ---@class boxSpaceIteratorParam: string 118 | ---@class boxSpaceIteratorState: ffi.cdata* 119 | 120 | ---Rename a space. 121 | ---@param space_name string 122 | function boxSpaceObject:rename(space_name) end 123 | 124 | ---Insert a tuple into a space. 125 | ---@param tuple box.tuple|tuple_type[] tuple to be inserted. 126 | ---@return box.tuple tuple the inserted tuple 127 | function boxSpaceObject:replace(tuple) end 128 | 129 | ---Insert a tuple into a space (synonym for replace). 130 | ---@param tuple box.tuple|tuple_type[] tuple to be inserted. 131 | ---@return box.tuple tuple the inserted tuple 132 | function boxSpaceObject:put(tuple) end 133 | 134 | ---At the time that a trigger is defined, it is automatically enabled - that is, it will be executed. Replace triggers can be disabled with box.space.space-name:run_triggers(false) and re-enabled with box.space.space-name:run_triggers(true). 135 | ---@param flag boolean 136 | function boxSpaceObject:run_triggers(flag) end 137 | 138 | ---@class boxSpaceSelectOptions: boxTableIterator 139 | ---@field limit? number maximum number of tuples 140 | ---@field offset? number number of tuples to skip 141 | ---@field fetch_pos? boolean if `true`, the select method returns the position of the last selected tuple as the second value. 142 | 143 | ---Search for a tuple or a set of tuples in the given space. This method doesn’t yield (for details see Cooperative multitasking). 144 | ---@param key box.tuple|tuple_type[]|scalar 145 | ---@param options? boxSpaceSelectOptions 146 | ---@return box.tuple[] list the tuples whose primary-key fields are equal to the fields of the passed key. If the number of passed fields is less than the number of fields in the primary key, then only the passed fields are compared, so select{1,2} will match a tuple whose primary key is {1,2,3}. 147 | ---@return string? pos 148 | function boxSpaceObject:select(key, options) end 149 | 150 | ---Deletes all tuples. The method is performed in background and doesn’t block consequent requests. 151 | function boxSpaceObject:truncate() end 152 | 153 | ---@alias update_operation string 154 | ---| '+' # for addition. values must be numeric, e.g. unsigned or decimal 155 | ---| '-' # for subtraction. values must be numeric 156 | ---| '&' # for bitwise AND. values must be unsigned numeric 157 | ---| '|' # for bitwise OR. values must be unsigned numeric 158 | ---| '^' # for bitwise XOR. values must be unsigned numeric 159 | ---| ':' # for string splice. 160 | ---| '!' # for insertion of a new field. 161 | ---| '#' # for deletion. 162 | ---| '=' # for assignment. 163 | 164 | ---Update a tuple. 165 | --- 166 | ---The update function supports operations on fields — assignment, arithmetic (if the field is numeric), cutting and pasting fragments of a field, deleting or inserting a field. 167 | ---Multiple operations can be combined in a single update request, and in this case they are performed atomically and sequentially. 168 | ---Each operation requires specification of a field identifier, which is usually a number. 169 | ---When multiple operations are present, the field number for each operation is assumed to be relative to the most recent state of the tuple, that is, as if all previous operations in a multi-operation update have already been applied. 170 | ---In other words, it is always safe to merge multiple update invocations into a single invocation, with no change in semantics. 171 | ---@param key box.tuple|tuple_type[]|scalar 172 | ---@param update_operations { [1]: update_operation, [2]: integer|string, [3]: tuple_type }[] 173 | ---@return box.tuple? tuple the updated tuple if it was found 174 | function boxSpaceObject:update(key, update_operations) end 175 | 176 | ---Update or insert a tuple. 177 | ---If there is an existing tuple which matches the key fields of tuple, then the request has the same effect as space_object:update() and the {{operator, field_identifier, value}, ...} parameter is used. 178 | ---If there is no existing tuple which matches the key fields of tuple, then the request has the same effect as space_object:insert() and the {tuple} parameter is used. 179 | ---However, unlike insert or update, upsert will not read a tuple and perform error checks before returning – this is a design feature which enhances throughput but requires more caution on the part of the user. 180 | ---@param tuple box.tuple|tuple_type[] 181 | ---@param update_operations { [1]: update_operation, [2]: integer|string, [3]: tuple_type }[] 182 | function boxSpaceObject:upsert(tuple, update_operations) end 183 | 184 | ---Converts table to tuple if it is satisfied by format 185 | ---@param tbl table 186 | ---@return box.tuple 187 | function boxSpaceObject:frommap(tbl) end 188 | 189 | return box.space 190 | -------------------------------------------------------------------------------- /Library/box/cfg.lua: -------------------------------------------------------------------------------- 1 | ---@meta 2 | --luacheck: ignore 3 | 4 | ---@alias election_mode 5 | ---| 'candidate' 6 | ---| 'off' 7 | ---| 'voter' 8 | 9 | ---@alias log_level 10 | ---| 'crit' 11 | ---| 'info' 12 | ---| 'debug' 13 | ---| 'syserror' 14 | ---| 'verbose' 15 | ---| 'fatal' 16 | ---| 'error' 17 | ---| 1 # SYSERROR 18 | ---| 2 # ERROR 19 | ---| 3 # CRITICAL 20 | ---| 4 # WARNING 21 | ---| 5 # INFO 22 | ---| 6 # VERBOSE 23 | ---| 7 # DEBUG 24 | 25 | ---@alias boxCfglog 26 | ---| 'file: ' 27 | ---| 'pipe: ' 28 | ---| 'syslog:identity= ' 29 | ---| 'syslog:facility= ' 30 | ---| 'syslog:identity= ,facility= ' 31 | ---| 'syslog:server= ' 32 | 33 | ---@alias log_format 34 | ---| 'plain' 35 | ---| 'json' 36 | 37 | ---@alias wal_mode 38 | ---| 'none' # write-ahead log is not maintained. A node with wal_mode = none can’t be replication master 39 | ---| 'write' # fibers wait for their data to be written to the write-ahead log (no fsync(2)) 40 | ---| 'fsync' # fibers wait for their data, fsync(2) follows each write(2) 41 | 42 | ---@class BoxCfg 43 | ---@field background? boolean (default: false) 44 | ---@field checkpoint_count? number (Default: 2) The maximum number of snapshots that may exist on the memtx_dir directory before the checkpoint daemon will delete old snapshots 45 | ---@field checkpoint_interval? number (Default: 3600 (one hour)) The interval between actions by the checkpoint daemon, in seconds. If checkpoint_interval is set to a value greater than zero, and there is activity which causes change to a database, then the checkpoint daemon will call box.snapshot() every checkpoint_interval seconds, creating a new snapshot file each time. If checkpoint_interval is set to zero, then the checkpoint daemon is disabled 46 | ---@field checkpoint_wal_threshold? number (Default: 10^18 (a large number so in effect there is no limit by default)) The threshold for the total size in bytes of all WAL files created since the last checkpoint 47 | ---@field coredump? boolean (Default: false) DEPRECATED, DO NOT USE 48 | ---@field custom_proc_title? string (Default: nil) Add the given string to the server’s process title 49 | ---@field election_mode? election_mode (Default: off) enables RAFT 50 | ---@field feedback_enabled? boolean (Default: true) Whether to send feedback 51 | ---@field feedback_host? string (Default: 'https://feedback.tarantool.io') The address to which the packet is sent. Usually the recipient is Tarantool, but it can be any URL 52 | ---@field feedback_interval? number (Default: 3600) The number of seconds between sendings, usually 3600 (1 hour). 53 | ---@field force_recovery? boolean (Default: false) If force_recovery equals true, Tarantool tries to continue if there is an error while reading a snapshot file (at server instance start) or a write-ahead log file (at server instance start or when applying an update at a replica): skips invalid records, reads as much data as possible and lets the process finish with a warning. Users can prevent the error from recurring by writing to the database and executing box.snapshot() 54 | ---@field hot_standby? boolean (Default: false) Whether to start the server in hot standby mode. Hot standby is a feature which provides a simple form of failover without replication 55 | ---@field instance_uuid? string (Generated automatically) For replication administration purposes, it is possible to set the universally unique identifiers of the instance (instance_uuid) and the replica set (replicaset_uuid), instead of having the system generate the values 56 | ---@field io_collect_interval? number (Default: nil) The instance will sleep for io_collect_interval seconds between iterations of the event loop. Can be used to reduce CPU load in deployments in which the number of client connections is large, but requests are not so frequent (for example, each connection issues just a handful of requests per second) 57 | ---@field iproto_threads? number (Default: 1) The number of network threads 58 | ---@field listen? string|number (Default: nil) URI to bind tarantool 59 | ---@field log? boxCfglog (Default: nil) By default, Tarantool sends the log to the standard error stream (stderr). If log is specified, Tarantool sends the log to a file, or to a pipe, or to the system logger. 60 | ---@field log_format? log_format (Default: 'plain') 61 | ---@field log_level? log_level (Default: 5) What level of detail the log will have 62 | ---@field log_nonblock? boolean (Default: true) If log_nonblock equals true, Tarantool does not block during logging when the system is not ready for writing, and drops the message instead 63 | ---@field memtx_dir? string (Default: '.') path to dir with memtx snapshots 64 | ---@field memtx_max_tuple_size? number (Default: 1024 * 1024) Size of the largest allocation unit, for the memtx storage engine. It can be increased if it is necessary to store large tuples 65 | ---@field memtx_memory? number (Default: 256 * 1024 *1024) How much memory Tarantool allocates to actually store tuples 66 | ---@field memtx_allocator? 'small'|'system' (Default: 'small') 67 | ---@field memtx_min_tuple_size? number (Default: 16) Size of the smallest allocation unit. It can be decreased if most of the tuples are very small 68 | ---@field memtx_use_mvcc_engine? boolean (Default: false) Since version 2.6.1. Enables transactional manager if set to true. 69 | ---@field net_msg_max? number (Default: 768) To handle messages, Tarantool allocates fibers. To prevent fiber overhead from affecting the whole system, Tarantool restricts how many messages the fibers handle, so that some pending requests are blocked 70 | ---@field pid_file? string (Default: nil) Store the process id in this file 71 | ---@field readahead? number (Default: 16320) The size of the read-ahead buffer associated with a client connection 72 | ---@field read_only? boolean (Default: false) should this instance be RO 73 | ---@field replicaset_uuid? string (Generated automatically) 74 | ---@field replication? string[] (Default: nil) list of URI of replicas to connect to 75 | ---@field replication_anon? boolean (Default: false) A Tarantool replica can be anonymous. This type of replica is read-only (but you still can write to temporary and replica-local spaces), and it isn’t present in the _cluster table 76 | ---@field replication_connect_quorum? number (Default: _cluster:len()) required number of connected replicas to start bootstrap 77 | ---@field replication_connect_timeout? number (Default: 30) timeout in seconds to expect replicas in replication to fail bootstrap 78 | ---@field replication_synchro_quorum? string|number (Default: N / 2 + 1. Before version 2.10.0, the default value was 1) number or formula of synchro quorum 79 | ---@field replication_synchro_timeout? number (Default: 5) For synchronous replication only. Tells how many seconds to wait for a synchronous transaction quorum replication until it is declared failed and is rolled back. 80 | ---@field replication_threads? number (Default: 1) The number of threads spawned to decode the incoming replication data. 81 | ---@field replication_skip_conflict? boolean (Default: false) By default, if a replica adds a unique key that another replica has added, replication stops with error = ER_TUPLE_FOUND 82 | ---@field replication_sync_lag? number (Default: 10) The maximum lag allowed for a replica 83 | ---@field replication_sync_timeout? number (Default: 300) The number of seconds that a replica will wait when trying to sync with a master in a cluster, or a quorum of masters, after connecting or during configuration update 84 | ---@field replication_timeout? number (Defailt: 1) If the master has no updates to send to the replicas, it sends heartbeat messages every replication_timeout seconds, and each replica sends an ACK packet back. Both master and replicas are programmed to drop the connection if they get no response in four replication_timeout periods. If the connection is dropped, a replica tries to reconnect to the master 85 | ---@field slab_alloc_factor? number (Default: 1.05) The multiplier for computing the sizes of memory chunks that tuples are stored in. A lower value may result in less wasted memory depending on the total amount of memory available and the distribution of item sizes. Allowed values range from 1 to 2 86 | ---@field snap_io_rate_limit? number (Default: nil) Reduce the throttling effect of box.snapshot() on INSERT/UPDATE/DELETE performance by setting a limit on how many megabytes per second it can write to disk. The same can be achieved by splitting wal_dir and memtx_dir locations and moving snapshots to a separate disk 87 | ---@field sql_cache_size? number (Default: 5242880) The maximum number of bytes in the cache for SQL prepared statements 88 | ---@field strip_core? boolean (Default: true) Whether coredump files should include memory allocated for tuples 89 | ---@field too_long_threshold? number (Default: 0.5) If processing a request takes longer than the given value (in seconds), warn about it in the log. Has effect only if log_level is more than or equal to 4 (WARNING) 90 | ---@field txn_isolation? txn_isolation (Default: best-effort) 91 | ---@field username? string (Default: nil) UNIX user name to switch to after start 92 | ---@field vinyl_bloom_fpr? number (Default: 0.05) Bloom filter false positive rate – the suitable probability of the bloom filter to give a wrong result 93 | ---@field vinyl_cache? number (Default: 128 * 1024 * 1024) The cache size for the vinyl storage engine 94 | ---@field vinyl_dir? string (Default: '.') A directory where vinyl files or subdirectories will be stored. Can be relative to work_dir. If not specified, defaults to work_dir 95 | ---@field vinyl_max_tuple_size? number (Default: 1024 * 1024) Size of the largest allocation unit, for the vinyl storage engine. It can be increased if it is necessary to store large tuples 96 | ---@field vinyl_memory? number (Default: 128 * 1024 * 1024) The maximum number of in-memory bytes that vinyl uses 97 | ---@field vinyl_page_size? number (Default: 8 * 1024) Page size. Page is a read/write unit for vinyl disk operations. The vinyl_page_size setting is a default value for one of the options in the Options for space_object:create_index() chart 98 | ---@field vinyl_range_size? number (Default: nil) The default maximum range size for a vinyl index, in bytes. The maximum range size affects the decision whether to split a range. If vinyl_range_size is not nil and not 0, then it is used as the default value for the range_size option in the Options for space_object:create_index() chart. If vinyl_range_size is nil or 0, and range_size is not specified when the index is created, then Tarantool sets a value later depending on performance considerations. To see the actual value, use index_object:stat().range_size 99 | ---@field vinyl_read_threads? number (Default: 1) The maximum number of read threads that vinyl can use for some concurrent operations, such as I/O and compression 100 | ---@field vinyl_run_count_per_level? number (Default: 2) The maximal number of runs per level in vinyl LSM tree. If this number is exceeded, a new level is created. The vinyl_run_count_per_level setting is a default value for one of the options in the Options for space_object:create_index() chart 101 | ---@field vinyl_run_size_ratio? number (Default: 3.5) Ratio between the sizes of different levels in the LSM tree. The vinyl_run_size_ratio setting is a default value for one of the options in the Options for space_object:create_index() chart 102 | ---@field vinyl_timeout? number (Default: 60) The vinyl storage engine has a scheduler which does compaction. When vinyl is low on available memory, the compaction scheduler may be unable to keep up with incoming update requests. In that situation, queries may time out after vinyl_timeout seconds. This should rarely occur, since normally vinyl would throttle inserts when it is running low on compaction bandwidth. Compaction can also be ordered manually with index_object:compact() 103 | ---@field vinyl_write_threads? number (Default: 4) The maximum number of write threads that vinyl can use for some concurrent operations, such as I/O and compression 104 | ---@field wal_cleanup_delay? number (Default: 14400 seconds) The delay (in seconds) used to prevent the Tarantool garbage collector from immediately removing write-ahead log files after a node restart. 105 | ---@field wal_dir? string (Default: '.') path to dir with xlogs 106 | ---@field wal_dir_rescan_delay? number (Default: 2) Number of seconds between periodic scans of the write-ahead-log file directory, when checking for changes to write-ahead-log files for the sake of replication or hot standby 107 | ---@field wal_max_size? number (Default: 256 * 1024 * 1024) The maximum number of bytes in a single write-ahead log file. When a request would cause an .xlog file to become larger than wal_max_size, Tarantool creates another WAL file 108 | ---@field wal_queue_max_size? number (Default: 16 * 1024 * 1024) The size of the queue (in bytes) used by a replica to submit new transactions to a write-ahead log 109 | ---@field wal_mode? wal_mode (Default: 'write') Specify fiber-WAL-disk synchronization mode as 110 | ---@field worker_pool_threads? number (Default: 4) he maximum number of threads to use during execution of certain internal processes (currently socket.getaddrinfo() and coio_call()) 111 | ---@field work_dir? string (Default: nil) path to work dir of tarantool 112 | box.cfg = {} 113 | -------------------------------------------------------------------------------- /Library/socket.lua: -------------------------------------------------------------------------------- 1 | ---@diagnostic disable: duplicate-set-field 2 | ---@meta 3 | --luacheck: ignore 4 | 5 | ---@class socket 6 | ---@operator call: socket_object 7 | local socket = {} 8 | 9 | ---@class socket_object: table 10 | local socket_object = {} 11 | 12 | ---Returns file descriptor of the socket 13 | ---@return number fd file descriptor 14 | function socket_object:fd() end 15 | 16 | ---Connect a socket to a remote host. 17 | ---@async 18 | ---@param host string URL or IP address 19 | ---@param port number|string? port number string for unix socket 20 | ---@param timeout number? number of seconds to wait 21 | ---@return socket_object 22 | ---@return nil, string error_message 23 | function socket.tcp_connect(host, port, timeout) end 24 | 25 | ---The socket.getaddrinfo() function is useful for finding information about a remote site so that the correct arguments for sock:sysconnect() can be passed. This function may use the worker_pool_threads configuration parameter. 26 | ---@async 27 | ---@overload fun(host: string, port: number|string, options?: { type: string, family: string, flags: any, protocol: string }) 28 | ---@param host string URL or IP address 29 | ---@param port number|string port number as a numeric or string 30 | ---@param timeout? number maximum number of seconds to wait 31 | ---@param options? { type: string, family: string, flags: any, protocol: string } 32 | ---@return {host: string, family: string, type: string, protocol: string, port: number}[]?, string error_message 33 | function socket.getaddrinfo(host, port, timeout, options) end 34 | 35 | 36 | ---@class TCPServerHandler 37 | ---@field handler fun(client: socket_object) client handler, executed once after accept() happens (once per connection) 38 | ---@field prepare fun(server: socket_object): number? it may have parameters = the socket object and a table with client information; it should return either a backlog value or nothing; 39 | ---@field name string 40 | 41 | ---The socket.tcp_server() function makes Tarantool act as a server that can accept connections. 42 | ---@async 43 | ---@param host string host name or IP 44 | ---@param port number host port, may be 0 45 | ---@param handler fun(client: socket_object)|TCPServerHandler what to execute when a connection occurs 46 | ---@param timeout? number host resolving timeout in seconds 47 | ---@return socket_object 48 | ---@return nil, string error_message 49 | function socket.tcp_server(host, port, handler, timeout) end 50 | 51 | ---Bind a socket to the given host/port. 52 | ---@param host string URL or IP address 53 | ---@param port number port number 54 | ---@return socket_object 55 | ---@return nil, string error_message 56 | function socket.bind(host, port) end 57 | 58 | ---Connect an existing socket to a remote host. The argument values are the same as in tcp_connect(). The host must be an IP address. 59 | ---@param host string|number representation of an IPv4 address or an IPv6 address; or “unix/”; or number, 0 (zero), meaning “all local interfaces”; 60 | ---@param port number|string port number; or path to a unix socket.; or If a port number is 0 (zero), the socket will be bound to a random local port. 61 | ---@return boolean success 62 | function socket_object:sysconnect(host, port) end 63 | 64 | ---Send data over a connected socket. 65 | ---@param data string what is to be sent 66 | ---@return number # number of bytes send 67 | ---@return nil # on error 68 | function socket_object:send(data) end 69 | 70 | ---Send data over a connected socket. 71 | ---@param data string what is to be sent 72 | ---@return number # number of bytes send 73 | ---@return nil # on error 74 | function socket_object:write(data) end 75 | 76 | ---Write as much data as possible to the socket buffer if non-blocking. Rarely used. 77 | ---@param data string what is to be sent 78 | ---@return number # number of bytes send 79 | ---@return nil # on error 80 | function socket_object:syswrite(data) end 81 | 82 | 83 | ---Read size bytes from a connected socket. An internal read-ahead buffer is used to reduce the cost of this call. 84 | --- 85 | ---For recv and recvfrom: use the optional size parameter to limit the number of bytes to receive. A fixed size such as 512 is often reasonable; a pre-calculated size that depends on context – such as the message format or the state of the network – is often better. For recvfrom, be aware that a size greater than the Maximum Transmission Unit can cause inefficient transport. For Mac OS X, be aware that the size can be tuned by changing sysctl net.inet.udp.maxdgram. 86 | --- 87 | ---If size is not stated: Tarantool will make an extra call to calculate how many bytes are necessary. This extra call takes time, therefore not stating size may be inefficient. 88 | --- 89 | ---If size is stated: on a UDP socket, excess bytes are discarded. On a TCP socket, excess bytes are not discarded and can be received by the next call. 90 | ---@param size number maximum number of bytes to receive. 91 | ---@return string result string of the requested length on success. 92 | ---@return string empty_string, number status, number errno, string errstr on error 93 | function socket_object:recv(size) end 94 | 95 | 96 | ---Read from a connected socket until some condition is true, and return the bytes that were read 97 | --- 98 | ---Unlike socket_object:recv (which uses an internal read-ahead buffer), socket_object:read depends on the socket’s buffer. 99 | ---@async 100 | ---@param limit number maximum number of bytes to read, for example 50 means “stop after 50 bytes” 101 | ---@param timeout? number maximum number of seconds to wait, for example 50 means “stop after 50 seconds” 102 | ---@return string data in case of success 103 | ---@return string empty_string if there is nothing more to read 104 | ---@return nil # if error 105 | function socket_object:read(limit, timeout) end 106 | 107 | ---Read from a connected socket until some condition is true, and return the bytes that were read 108 | --- 109 | ---Unlike socket_object:recv (which uses an internal read-ahead buffer), socket_object:read depends on the socket’s buffer. 110 | ---@async 111 | ---@param delimeter string separator for example ‘?’ means “stop after a question mark” 112 | ---@param timeout? number maximum number of seconds to wait, for example 50 means “stop after 50 seconds”. 113 | ---@return string data in case of success 114 | ---@return string empty_string if there is nothing more to read 115 | ---@return nil # if error 116 | function socket_object:read(delimeter, timeout) end 117 | 118 | ---Read from a connected socket until some condition is true, and return the bytes that were read 119 | --- 120 | ---Unlike socket_object:recv (which uses an internal read-ahead buffer), socket_object:read depends on the socket’s buffer. 121 | ---@async 122 | ---@param options { chunk: number?, delimeter: string? } chunk=limit and/or delimiter=delimiter, for example {chunk=5,delimiter='x'} 123 | ---@param timeout? number maximum number of seconds to wait, for example 50 means “stop after 50 seconds”. 124 | ---@return string data in case of success 125 | ---@return string empty_string if there is nothing more to read 126 | ---@return nil # if error 127 | function socket_object:read(options, timeout) end 128 | 129 | ---Return data from the socket buffer if non-blocking. In case the socket is blocking, sysread() can block the calling process. Rarely used. 130 | ---@param size number 131 | ---@return string data in case of success 132 | ---@return string empty_string if there is nothing more to read 133 | ---@return nil # if error 134 | function socket_object:sysread(size) end 135 | 136 | ---Bind a socket to the given host/port. 137 | --- 138 | ---A UDP socket after binding can be used to receive data (see socket_object.recvfrom). 139 | --- 140 | ---A TCP socket can be used to accept new connections, after it has been put in listen mode. 141 | ---@param host string URL or IP address 142 | ---@param port number? port number 143 | ---@return boolean success true for success, false for error. If return is false, use socket_object:errno() or socket_object:error() to see details. 144 | function socket_object:bind(host, port) end 145 | 146 | ---Start listening for incoming connections. 147 | ---@param backlog number on Linux the listen backlog backlog may be from /proc/sys/net/core/somaxconn, on BSD the backlog may be SOMAXCONN 148 | ---@return boolean success true for success, false for error. 149 | function socket_object:listen(backlog) end 150 | 151 | ---Accept a new client connection and create a new connected socket. 152 | --- 153 | ---It is good practice to set the socket’s blocking mode explicitly after accepting. 154 | ---@return socket_object client new socket if success. 155 | ---@return nil # if error 156 | function socket_object:accept() end 157 | 158 | ---Send a message on a UDP socket to a specified host. 159 | ---@param host string URL or IP address 160 | ---@param port number port number 161 | ---@param data string what is to be sent 162 | ---@return number bytes the number of bytes sent. 163 | ---@return nil, number? status, number? errno, string? errstr on error, returns nil and may return status, errno, errstr. 164 | function socket_object:sendto(host, port, data) end 165 | 166 | ---Receive a message on a UDP socket. 167 | ---@param size? number maximum number of bytes to receive. 168 | ---@return string message, { host: string, family: string, port: number } source on success 169 | ---@return nil, number status, number errno, string errstr on error 170 | function socket_object:recvfrom(size) end 171 | 172 | ---Shutdown a reading end, a writing end, or both ends of a socket. 173 | ---@param how number socket.SHUT_RD, socket.SHUT_WR, or socket.SHUT_RDWR. 174 | ---@return boolean success 175 | function socket_object:shutdown(how) end 176 | 177 | ---Close (destroy) a socket. 178 | ---A closed socket should not be used any more. 179 | ---A socket is closed automatically when the Lua garbage collector removes its user data. 180 | ---@return boolean success true on success, false on error. For example, if sock is already closed, sock:close() returns false. 181 | function socket_object:close() end 182 | 183 | ---Retrieve information about the last error that occurred on a socket, if any. 184 | ---Errors do not cause throwing of exceptions so these functions are usually necessary. 185 | ---@return number errno if no error 0 is returned 186 | function socket_object:errno() end 187 | 188 | ---Retrieve information about the last error that occurred on a socket, if any. 189 | ---Errors do not cause throwing of exceptions so these functions are usually necessary. 190 | ---@return string errstr 191 | function socket_object:error() end 192 | 193 | ---Set socket flags. 194 | ---@param level any 195 | ---@param name any 196 | ---@param value any 197 | function socket_object:setsockopt(level, name, value) end 198 | 199 | ---Get socket flags. 200 | ---@param level any 201 | ---@param name any 202 | function socket_object:getsockopt(level, name) end 203 | 204 | ---Set or clear the SO_LINGER flag. 205 | ---@param active boolean 206 | function socket_object:linger(active) end 207 | 208 | ---returns the current O_NONBLOCK value. 209 | ---@return boolean nonblock_flag 210 | function socket_object:nonblock() end 211 | 212 | ---sets O_NONBLOCK flag 213 | ---@param flag boolean 214 | ---@return boolean new_flag_value 215 | function socket_object:nonblock(flag) end 216 | 217 | ---Wait until something is readable, or until a timeout value expires. 218 | ---@async 219 | ---@param timeout? number timeout in seconds 220 | ---@return boolean is_readable true if the socket is now readable, false if timeout expired; 221 | function socket_object:readable(timeout) end 222 | 223 | ---Wait until something is writable, or until a timeout value expires. 224 | ---@async 225 | ---@param timeout? number timeout in seconds 226 | ---@return boolean is_writable true if the socket is now writable, false if timeout expired; 227 | function socket_object:writable(timeout) end 228 | 229 | ---Wait until something is either readable or writable, or until a timeout value expires. 230 | ---@async 231 | ---@param timeout? number timeout 232 | ---@return "R"|"W"|"RW"|"" # ‘R’ if the socket is now readable, ‘W’ if the socket is now writable, ‘RW’ if the socket is now both readable and writable, ‘’ (empty string) if timeout expired; 233 | function socket_object:wait(timeout) end 234 | 235 | 236 | ---function is used to get information about the near side of the connection. 237 | --- 238 | ---The equivalent POSIX function is getsockname() 239 | ---@return { host: string, family: string, type: string, protocol: string, port: number } 240 | function socket_object:name() end 241 | 242 | ---function is used to get information about the far side of a connection. 243 | --- 244 | ---The equivalent POSIX function is getpeername(). 245 | ---@return { host: string, family: string, type: string, protocol: string, port: number } 246 | function socket_object:peer() end 247 | 248 | ---function is used to wait until read-or-write activity occurs for a file descriptor. 249 | --- 250 | ---If the fd parameter is nil, then there will be a sleep until the timeout. 251 | ---If the timeout parameter is nil or unspecified, then timeout is infinite. 252 | --- 253 | ---@async 254 | ---@param fd number file descriptor 255 | ---@param read_or_write_flags "R"|"W"|"RW"| 1 | 2 | 3 # ‘R’ or 1 = read, ‘W’ or 2 = write, ‘RW’ or 3 = read|write. 256 | ---@param timeout? number number of seconds to wait 257 | function socket.iowait(fd, read_or_write_flags, timeout) end 258 | 259 | return socket --------------------------------------------------------------------------------