Skip to content
Snippets Groups Projects
  1. Apr 20, 2020
    • Vladislav Shpilevoy's avatar
      error: export error_unref() function · ed217292
      Vladislav Shpilevoy authored
      C struct error objects can be created directly only in C.
      C-side increments their reference counter when pushes to the Lua
      stack.
      
      It is not going to be so convenient soon. error_unpack() function
      will be used in netbox to decode error object via Lua FFI.
      
      Such error object will have 0 refs and no Lua GC callback
      established. Because it won't be pushed on Lua stack natually,
      from Lua C. To make such errors alive their reference counter
      will be incremented and error_unref() will be set as GC callback.
      
      Follow up for #4398
      ed217292
    • Leonid Vasiliev's avatar
      error: add custom error type · b728e7af
      Leonid Vasiliev authored
      
      Co-authored-by: default avatarVladislav <Shpilevoy&lt;v.shpilevoy@tarantool.org>
      
      Part of #4398
      
      @TarantoolBot document
      Title: Custom error types for Lua errors
      
      Errors can be created in 2 ways: `box.error.new()` and `box.error()`.
      
      Both used to take either `code, reason, <reason string args>` or
      `{code = code, reason = reason, ...}` arguments.
      
      Now in the first option instead of code a user can specify a
      string as its own error type. In the second option a user can
      specify both code and type. For example:
      
      ```Lua
      box.error('MyErrorType', 'Message')
      box.error({type = 'MyErrorType', code = 1024, reason = 'Message'})
      ```
      Or no-throw version:
      ```Lua
      box.error.new('MyErrorType', 'Message')
      box.error.new({type = 'MyErrorType', code = 1024, reason = 'Message'})
      ```
      When a custom type is specified, it is shown in `err.type`
      attribute. When it is not specified, `err.type` shows one of
      built-in errors such as 'ClientError', 'OurOfMemory', etc.
      
      Name length limit on the custom type is 63 bytes. All what is
      longer is truncated.
      
      Original error type can be checked using `err.base_type` member,
      although normally it should not be used. For user-defined types
      base type is 'CustomError'.
      
      For example:
      ```
      tarantool> e = box.error.new({type = 'MyErrorType', code = 1024, reason = 'Message'})
      ---
      ...
      
      tarantool> e:unpack()
      ---
      - code: 1024
        trace:
        - file: '[string "e = box.error.new({type = ''MyErrorType'', code..."]'
          line: 1
        type: MyErrorType
        custom_type: MyErrorType
        message: Message
        base_type: CustomError
      ...
      ```
      b728e7af
  2. Apr 14, 2020
    • Vladislav Shpilevoy's avatar
      box: export box_session_push to the public C API · 5d795527
      Vladislav Shpilevoy authored
      API is different from box.session.push() - sync argument was
      removed. It will disappear from Lua API as well, because it just
      is not needed here. Session is omitted as well. Indeed, a user
      can't push to a foreign session, and the current session can be
      obtained inside box_session_push(). And anyway session is not in
      the public C API.
      
      Internally dump into iproto is done using obuf_dup(), just like
      tuple_to_obuf() does. obuf_alloc() would be a bad call here,
      because it wouldn't be able to split the pushed data into several
      obuf chunks, and would cause obuf fragmentation.
      
      Dump into plain text behaves just like a Lua push - it produces a
      YAML formatted text or Lua text depending on output format. But to
      turn MessagePack into YAML or Lua text an intermediate Lua
      representation is used, because there are no a MessagePack -> YAML
      and MessagePack -> Lua text translators yet.
      
      Closes #4734
      
      @TarantoolBot document
      Title: box_session_push() C API
      
      There is a new function in the public C API:
      ```C
          int
          box_session_push(const char *data, const char *data_end);
      ```
      
      It takes raw MessagePack, and behaves just like Lua
      `box.session.push()`.
      5d795527
  3. Apr 13, 2020
    • Chris Sosnin's avatar
      session: store output format in struct session · 9c0e40f9
      Chris Sosnin authored
      box.session.storage is a general-purpose table, which can be
      used by user. Therefore, we shouldn't store any internal details
      in it.
      
      Needed for #4686
      9c0e40f9
    • Serge Petrenko's avatar
      box: add MsgPack encoding/decoding for UUID · d68fc292
      Serge Petrenko authored
      A special format for encoding UUIDs to MsgPack is introduced.
      It is supported by both lua and C encoders/decoders, and it is now
      possible to insert UUIDs into spaces, but only into unindexed fields
      without format for now.
      
      Prerequisite #4268
      
      @TarantoolBot document
      Title: Internals: msgpack format for UUID
      
      UUID values share the MessagePack type with decimals:
      both use MP_EXT. A new subtype is introduced for UUIDs,
      MP_UUID = `0x02`
      UUID is encoded as follows:
      ```
          +--------+---------+-----------+
          | MP_EXT | MP_UUID | UuidValue |
          +--------+---------+-----------+
      ```
      Since UUID is 16 bytes in size, the header, MP_EXT, is always the same:
      `0xd8`. MP_UUID = `0x02` follows. The header is followed by the 16
      bytes of the UuidValue.
      
      UuidValue consists of 11 fields, which are encoded as big endian
      unsigned integers in the following order: `time_low` (4 bytes), `time_mid`
      (2 bytes), `time_hi_and_version` (2 bytes), `clock_seq_hi_and_reserved` (1
      byte), `clock_seq_low` (1 byte), `node[0], ..., node[5]` (1 byte each).
      
      The total size of such a representation is 18 bytes, whereas storing
      uuids as strings requires from 34 (when '-'s are ommitted) to 38 bytes
      per UUID, giving a 2x space usage improvement.
      d68fc292
  4. Apr 07, 2020
    • Nikita Pettik's avatar
      box: introduce stacked diagnostic area · 3b887d04
      Nikita Pettik authored
      In terms of implementation, now struct error objects can be organized
      into double-linked lists. To achieve this pointers to the next and
      previous elements (cause and effect correspondingly) have been added to
      struct error. It is worth mentioning that already existing rlist and
      stailq list implementations are not suitable: rlist is cycled list, as a
      result it is impossible to start iteration over the list from random
      list entry and finish it at the logical end of the list; stailq is
      single-linked list leaving no possibility to remove elements from the
      middle of the list.
      
      As a part of C interface, box_error_add() has been introduced. In
      contrast to box_error_set() it does not replace last raised error, but
      instead it adds error to the list of diagnostic errors having already
      been set. If error is to be deleted (its reference counter hits 0 value)
      it is unlinked from the list it belongs to and destroyed. Meanwhile,
      error destruction leads to decrement of reference counter of its
      previous error and so on.
      
      To organize errors into lists in Lua, table representing error object in
      Lua now has .prev field (corresponding to 'previous' error) and method
      :set_prev(e). The latter accepts error object (i.e. created via
      box.error.new() or box.error.last()) and nil value. Both field .prev and
      :set_prev() method are implemented as ffi functions. Also note that
      cycles are not allowed while organizing errors into lists:
      e1 -> e2 -> e3; e3:set_prev(e1) -- would lead to error.
      
      Part of #1148
      3b887d04
  5. Mar 18, 2020
    • Oleg Babin's avatar
      box: allow to retrieve the last generated value of sequence · 64c69fe0
      Oleg Babin authored
      
      This patch introduces "current" function for sequences.
      It returns the last retrieved value of specified sequence or
      throws an error if no value has been generated yet.
      
      This patch partially reverts 3ff1f1e3
      (box: remove sequence_get) here similar function "get" was removed
      to avoid possible misleading with "currval" function of PosgreSQL
      that returns the last obtained value of the sequence in the scope
      of current session. In contrast "current" returns the last globally
      retrieved value of the sequence.
      
      Closes #4752
      
      Reviewed-by: default avatarVladislav Shpilevoy <v.shpilevoy@tarantool.org>
      Reviewed-by: default avatarNikita Pettik <korablev@tarantool.org>
      
      @TarantoolBot document
      Title: sequence:current()
      
      This patch introduces "current" function for sequences.
      It returns the last retrieved value of specified sequence or
      throws an error if no value has been generated yet ("next"
      has not been called yet or right after "reset" is called).
      
      Lua:
      
      Example:
      
      ```lua
      sq = box.schema.sequence.create('test')
      ---
      ...
      sq:current()
      ---
      - error: Sequence 'test' is not started
      ...
      sq:next()
      ---
      - 1
      ...
      sq:current()
      ---
      - 1
      ...
      sq:set(42)
      ---
      ...
      sq:current()
      ---
      - 42
      ...
      sq:reset()
      ---
      ...
      sq:current()  -- error
      ---
      - error: Sequence 'test' is not started
      ...
      ```
      
      C API:
      
      ```C
      int
      box_sequence_current(uint32_t seq_id, int64_t *result);
      ```
      
      Where:
        * seq_id - sequence identifier;
        * result - pointer to a variable where the current sequence
        value will be stored on success.
      
      Returns 0 on success and -1 otherwise. In case of an error user
      could get it via `box_error_last()`.
      64c69fe0
  6. Mar 05, 2020
  7. Aug 22, 2019
    • Serge Petrenko's avatar
      decimal: allow to encode/decode decimals as MsgPack · 485439e3
      Serge Petrenko authored
      This patch adds the methods necessary to encode and decode decimals to
      MsgPack. MsgPack EXT type (MP_EXT) together with a new extension type
      MP_DECIMAL is used as a record header.
      
      The decimal MsgPack representation looks like this:
      +--------+-------------------+------------+===============+
      | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
      +--------+-------------------+------------+===============+
      The whole record may be encoded and decoded with
      mp_encode_decimal() and mp_decode_decimal(). This is equivalent to
      performing mp_encode_extl()/mp_decode_extl() on the first 3 fields and
      decimal_pack/unpack() on the PackedDecimal field.
      
      It is also possible to decode and encode decimals to msgpack from lua,
      which means you can insert decimals into spaces, but only into unindexed
      fields for now.
      
      Follow up #692
      Part of #4333
      485439e3
  8. Jun 09, 2019
  9. May 21, 2019
    • Vladislav Shpilevoy's avatar
      swim: swim:set_codec() Lua API · 2dc1af75
      Vladislav Shpilevoy authored
      Encryption with an arbitrary algorithm and any mode with a
      configurable private key.
      
      Closes #3234
      2dc1af75
    • Vladislav Shpilevoy's avatar
      swim: cache decoded payload in the Lua module · 8ae88a3f
      Vladislav Shpilevoy authored
      Users of Lua SWIM module likely will use Lua objects as a
      payload. Lua objects are serialized into MessagePack
      automatically, and deserialized back on other instances. But
      deserialization of 1.2Kb payload on each member:payload()
      invocation is quite heavy operation. This commit caches decoded
      payloads to return them again until change.
      
      A microbenchmark showed, that cached payload is returned ~100
      times faster, than it is decoded each time. Even though a tested
      payload was quite small and simple:
      
          s:set_payload({a = 100, b = 200})
      
      Even this payload is returned 100 times faster, and does not
      affect GC.
      
      Part of #3234
      8ae88a3f
    • Vladislav Shpilevoy's avatar
      swim: introduce Lua interface · 407adf40
      Vladislav Shpilevoy authored
      SWIM as a library can be useful not only for server internals,
      but for users as well. This commit exposes Lua bindings to SWIM
      C API. Here only basic bindings are introduced to create, delete,
      quit, check a SWIM instance. With sanity tests.
      
      Part of #3234
      407adf40
    • Vladislav Shpilevoy's avatar
      buffer: port static allocator to Lua · 7fd6c809
      Vladislav Shpilevoy authored
      Static allocator gives memory blocks from cyclic BSS memory
      block of 3 pages 4096 bytes each. It is much faster than
      malloc, when a temporary buffer is needed. Moreover, it does not
      complicate GC job. Despite being faster than malloc, it is still
      slower, than ffi.new() of size <= 128 known in advance (according
      to microbenchmarks).
      
      ffi.new(size<=128) works either much faster or with the same
      speed as static_alloc, because internally FFI allocator library
      caches small blocks and can return them without malloc().
      
      A simple micro benchmark showed, that ffi.new() vs
      buffer.static_alloc() is ~100 times slower on allocations of
      > 128 size,  on <= 128 when size is not inlined.
      
      To better understand what is meant as 'inlined': this
      
          ffi.new('char[?]', < <=128 >)
      
      works ~100 times faster than this:
      
          local size = <= 128
          ffi.new('char[?]', size)
      
      ffi.new() with inlined size <= 128 works faster than light, and
      even static allocator can't beat it.
      7fd6c809
  10. May 15, 2019
  11. Apr 30, 2019
  12. Mar 26, 2019
  13. Feb 21, 2019
    • Michał Durak's avatar
      lua: add 'chars' param to string.strip functions · 16f58830
      Michał Durak authored
      Add optional 'chars' parameter to string.strip, string.lstrip
      and string.rstrip for specifying the unwanted characters.
      Behavior modeled after the equivalent Python built-ins.
      
      Closes: #2977
      
      @TarantoolBot document
      Title: string.strip(inp, chars)
      Update the documentation for string.strip,
      string.lstrip and string.rstrip to reflect
      the addition of the optional param.
      16f58830
  14. Jan 30, 2019
    • Serge Petrenko's avatar
      lua: patch os.exit() to execute on_shutdown triggers. · 6dc4c8d7
      Serge Petrenko authored
      Make os.exit() call tarantool_exit(), just like the signal handler does.
      Now on_shutdown triggers are not run only when a fatal signal is
      received.
      
      Closes #1607
      
      @TarantoolBot document
      Title: Document box.ctl.on_shutdown triggers
      on_shutdown triggers may be set similar to space:on_replace triggers:
      ```
      box.ctl.on_shutdown(new_trigger, old_trigger)
      ```
      The triggers will be run when tarantool exits due to receiving one of
      the signals: `SIGTERM`, `SIGINT`, `SIGHUP` or when user executes
      `os.exit()`.
      
      Note that the triggers will not be run if tarantool receives a fatal
      signal: `SIGSEGV`, `SIGABORT` or any signal causing immediate program
      termination.
      6dc4c8d7
  15. Sep 22, 2018
  16. Aug 21, 2018
    • Konstantin Belyavskiy's avatar
      Add FindICONV and iconv wrapper · dcac64af
      Konstantin Belyavskiy authored
      Fixing build under FreeBSD:
      Undefined symbol "iconv_open"
      Add compile time build check with FindICONV.cmake
      and a wrapper to import relevant symbol names with include file.
      
      Closes #3441
      dcac64af
  17. Aug 15, 2018
    • Eugine Blikh's avatar
      Introduce luaT_tolstring · 01c32701
      Eugine Blikh authored
      `lua_tostring`/`lua_tolstring` ignores metatable/boolean/nil and return NULL,
      but sometimes it's needed to have similar behaviour, like lua functions
      tostring. Lua 5.1 and LuaJIT ignores it by default, Lua 5.2 introduced
      auxilary function luaL_to(l)string with supporting of __tostring. This
      function is backport of Lua 5.1 "lauxlib.h"s luaL_tostring in the luaT
      namespace.
      01c32701
  18. Aug 14, 2018
  19. Jul 13, 2018
  20. Jun 29, 2018
    • AKhatskevich's avatar
      sql: export `sql_current_time` && enable tests · cebe6930
      AKhatskevich authored
      `sql_current_time` is exported only in debug mode and used to check
      builtin datetime sql functions behavior in specific time moments.
      
      Extra changes:
       * table-14.1 test is deleted, as it does not test anything.
         It was testing ddl inside of a transaction. This case is checked
         by 14.2 by now.
      
      Closes #2646
      cebe6930
  21. Apr 04, 2018
  22. Jan 18, 2018
    • Vladimir Davydov's avatar
      Make struct port abstract · d5e479ee
      Vladimir Davydov authored
      So that it can be used not only for serializing a list of tuples, but
      also for serializing a Lua stack that stores output of CALL/EVAL.
      
      Needed for #946
      d5e479ee
  23. Dec 21, 2017
    • Ilya's avatar
      say: Add several loggers support · 6d7437da
      Ilya authored
      * Add struct log
      * Add possibility to add logger configuration to global scope
      * Refactor functions in say to use them with specified config,
       not only global variable
      
       This patch was inspired by need of additional logger in audit log
       Relates #2912
      6d7437da
  24. Oct 12, 2017
    • Ilya's avatar
      log: add json format logging · 33be084e
      Ilya authored
      * Add log_format option to box.cfg{}
      * Add json format in logging
      * Add table converting to json in lua logging
      
      Closes #2795
      33be084e
  25. Oct 09, 2017
  26. Sep 06, 2017
  27. Sep 05, 2017
    • Vladislav Shpilevoy's avatar
      Implement box.savepoint · ff0ff603
      Vladislav Shpilevoy authored
      Savepoint allows to partialy rollback a transaction. After
      savepoint creation a transaction owner can rollback all changes applied
      after the savepoint without rolling back the entire transaction.
      
      Multiple savepoints can be created in each transaction. Rollback to
      a savepoint cancels changes made after the savepoint, and deletes all
      newer savepoints.
      
      It is impossible to rollback to a savepoint from a substatements level,
      different from the savepoint's one. For example, a transaction can not
      rollback to a savepoint, created outside of a trigger, from a trigger body.
      
      Closes #2025
      ff0ff603
  28. Aug 22, 2017
  29. Aug 01, 2017
  30. Jul 14, 2017
  31. Jul 11, 2017
  32. May 25, 2017
    • Georgy Kirichenko's avatar
      Add fiber attributes · 19cda0fc
      Georgy Kirichenko authored
      Fiber attributes are a way to specify parameters that is different
      from the default. When a fiber is created using fiber_new_ex(),
      an attribute object can be specified to configure custom values for
      some options. Attributes are specified only at fiber creation time;
      they cannot be altered while the fiber is being used.
      
      Currently only stack_size attribute is supported. Fibers with
      non-default stack size won't be recycled via fiber pool.
      
      API overview:
      
      * fiber_new_ex() creates a fiber with custom attributes.
      * fiber_attr_new()/fiber_attr_delete() creates/destroys attributes.
      * fiber_attr_setstacksize()/fiber_attr_getstacksize() sets/gets
        the fiber stack size.
      * fiber_self() returns current running fiber.
      
      All new functions are available from public C API for modules.
      
      See #2438
      19cda0fc
  33. May 16, 2017
    • Kirill Yukhin's avatar
      Fix OSX build. · 753c8e30
      Kirill Yukhin authored
      `sql_schema_put` is a static function and should not be exported.
      This routine was exported on early stages of SQL development
      when DDL was non-functional at all and came to the top due to
      patches re-mix.
      753c8e30
  34. May 12, 2017
Loading