Skip to content
Snippets Groups Projects
  1. Sep 13, 2019
    • Vladimir Davydov's avatar
      relay: join new replicas off read view · 6332aca6
      Vladimir Davydov authored
      Historically, we join a new replica off the last checkpoint. As a
      result, we must always keep the last memtx snapshot and all vinyl data
      files corresponding to it. Actually, there's no need to use the last
      checkpoint for joining a replica. Instead we can use the current read
      view as both memtx and vinyl support it. This should speed up the
      process of joining a new replica, because we don't need to replay all
      xlogs written after the last checkpoint, only those that are accumulated
      while we are relaying the current read view. This should also allow us
      to avoid creating a snapshot file on bootstrap, because the only reason
      why we need it is allowing joining replicas. Besides, this is a step
      towards decoupling the vinyl metadata log from checkpointing in
      particular and from xlogs in general.
      
      Closes #1271
      6332aca6
    • Alexander Turenko's avatar
      lua: pwd: split data fetch from deserialization · 6c5d3f06
      Alexander Turenko authored
      This commit does not change a user visible behaviour. It refactors pwd
      module to explicitly divide code that fetches data from passwd / group
      databases from code that performs deserialization of the data to Lua
      tables.
      
      The idea of splitting of those actions appears when it was observed that
      a call of getpw() / getgr() leads to problems on some systems when it is
      invoked during passwd / group database traveral.
      
      Now it is more obvious that we don't call getpw() during passwd
      traversal and getgr() during group traveral.
      
      Follows up #4428 and #4447.
      6c5d3f06
    • Kirill Shcherbatov's avatar
      box: fix compilation with old gcc · 97012004
      Kirill Shcherbatov authored
      LTO build fails on warning message:
      In file included from /tarantool/src/lib/core/diag.h:33:0,
                       from /tarantool/src/box/engine.h:36,
                       from /tarantool/src/box/memtx_engine.h:40,
                       from /tarantool/src/box/memtx_engine.c:31:
      /tarantool/src/box/memtx_engine.c: In function
      'metmx_tuple_chunk_delete':
      /tarantool/src/trivia/util.h:201:49: error: initialization from
      incompatible pointer type [-Werror]
        const typeof( ((type *)0)->member  ) *__mptr = (ptr); \
                                                       ^
      /tarantool/src/box/memtx_engine.c:1115:3: note: in expansion of macro
      'container_of'
         container_of((typeof(tuple_chunk->data) *)data,
         ^
      /tarantool/src/trivia/util.h:201:49: error: (near initialization for
      'tuple_chunk') [-Werror]
        const typeof( ((type *)0)->member  ) *__mptr = (ptr); \
                                                       ^
      /tarantool/src/box/memtx_engine.c:1115:3: note: in expansion of macro
      'container_of'
         container_of((typeof(tuple_chunk->data) *)data,
      
      Closes #4438
      97012004
  2. Sep 12, 2019
    • Serge Petrenko's avatar
      replication: disallow bootstrap of read-only masters · 037bd58c
      Serge Petrenko authored
      In a configuration with several read-only and read-write instances, if
      replication_connect_quorum is not greater than the amount of read-only
      instances and replication_connect_timeout happens to be small enough
      for some read-only instances to form a quorum and exceed the timeout
      before any of the read-write instaces start, all these read-only
      instances will choose themselves a read-only bootstrap leader.
      This 'leader' will successfully bootstrap itself, but will fail to
      register any of the other instances in _cluster table, since it isn't
      writeable. As a result, some of the read-only instances will just die
      unable to bootstrap from a read-only bootstrap leader, and when the
      read-write instances are finally up, they'll see a single read-only
      instance which managed to bootstrap itself and now gets a
      REPLICASET_UUID_MISMATCH error, since no read-write instance will
      choose it as bootstrap leader, and will rather bootstrap from one of
      its read-write mates.
      
      The described situation is clearly not what user has hoped for, so
      throw an error, when a read-only instance tries to initiate the
      bootstrap. The error will give the user a cue that he should increase
      replication_connect_timeout.
      
      Closes #4321
      
      @TarantoolBot document
      Title: replication: forbid to bootstrap read-only masters.
      
      It is no longer possible to bootstrap a read-only instance in an emply
      data directory as a master. You will see the following error trying to
      do so:
      ```
      ER_BOOTSTRAP_READONLY: Trying to bootstrap a local read-only instance as master
      ```
      Now if you have a fresh instance, which has
      `read_only=true` in an initial `box.cfg` call, you need to set up
      replication from an instance which is either read-write, or has your
      local instance's uuid in its `_cluster` table.
      
      In case you have multiple read-only and read-write instances with
      replication set up, and you still see the aforementioned error message,
      this means that none of your read-write instances managed to start
      listening on their port before read_only instances have exceeded the
      `replication_connect_timeout`. In this case you should raise
      `replication_connect_timeout` to a greater value.
      037bd58c
  3. Sep 10, 2019
  4. Sep 09, 2019
    • Mike Siomkin's avatar
      httpc: add proxy server options for curl · a1814bb6
      Mike Siomkin authored
      Added support for the following curl options:
      * CURLOPT_PROXY
      * CURLOPT_PROXYPORT
      * CURLOPT_PROXYUSERPWD
      * CURLOPT_NOPROXY
      
      @TarantoolBot document
      Title: httpc: proxy server options
      
      Use 'proxy' option to specify the proxy server host or IP-address
      (optionally may be prefixed with a scheme - e.g. http:// or https://).
      'proxy_port' and 'proxy_user_pwd' options may be used to specify the
      proxy port (443 for https proxy and 1080 for others by default) and
      user credentials (format: [user name]:[password]) respectively.
      
      If 'proxy' option is not set a value from the corresponding
      environment variable will be used. Environment variable names are:
      'http_proxy', 'https_proxy', 'ftp_proxy' etc. 'all_proxy' variable
      is used if no protocol specific proxy was set.
      
      Setting 'proxy' option to an empty string will explicitly disable the
      use of a proxy, even if there is an environment variable set for it.
      
      Set 'no_proxy' option to specify a comma separated list of hosts that
      do not require a proxy to get reached, even if one is specified by
      'proxy' option (or the corresponding environment variable). The only
      wildcard available is a single * character, which matches all hosts,
      and effectively disables the proxy. 'no_proxy' environment variable
      will be used if this option is not set.
      
      Setting 'no_proxy' option to an empty string will explicitly enable
      the proxy for all host names, even if there is an environment variable
      set for it.
      
      See:
      https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html
      https://curl.haxx.se/libcurl/c/CURLOPT_PROXYPORT.html
      https://curl.haxx.se/libcurl/c/CURLOPT_USERPWD.html
      https://curl.haxx.se/libcurl/c/CURLOPT_NOPROXY.html
      a1814bb6
  5. Aug 29, 2019
    • Cyrill Gorcunov's avatar
      box/memtx: strip_core -- Warn on linux only · 51d8e4c3
      Cyrill Gorcunov authored
      We know that madvise(MADV_DONTDUMP) is present
      on linux based platforms only (macos doesn't
      support it at all, freebsd requires MADV_NOCORE
      or similar which is unsupported by now) thus
      we should not print a warning on other systems
      to not spam users.
      
      Fixes #4464
      51d8e4c3
    • Kirill Shcherbatov's avatar
      sql: support user-defined functions in SQL · d4a7459e
      Kirill Shcherbatov authored
      Closes #2200
      Closes #4113
      Closes #2233
      
      @TarantoolBot document
      Title: The box.internal.sql_function_create is forbidden
      Legacy mechanism box.internal.sql_function_create to make some
      Lua function available in SQL is forbidden now.
      
      To make some function available in SQL you need to use
      box.schema.func.create() mechanism: you need to specify
      1) function language and language-specific options(e.g. you
         are able to define a persistent Lua function)
      2) whether this function is_deterministic or not: deterministic
         functions allows to generate more efficient SQL VDBE bytecode
         so you better specify it when it is true
      3) the function returns type: a Tarantool type string describes
         a type of value returned by function
      4) param_list - a table of Tarantool's types strings desccribe
         function argument types
      5) exports - a table of Tarantool's frontends where this function
         should be available ('LUA' by default). You need to specify
         {'LUA', 'SQL'} to make function available both in SQL requests
         and visible in box.func folder
      
      Example:
      -- Case1: C function
      -- function1.so has int divide() symbol
      box.schema.func.create("function1.divide", {language = 'C',
      			returns = 'number',
      			param_list = {'number', 'number'},
      			is_deterministic = true,
      			exports = {'LUA', 'SQL'}})
      box.execute('SELECT "function1.divide"(6, 3)')
      - metadata:
        - name: '"function1.divide"(6, 3)'
          type: number
        rows:
        - [2]
      box.schema.func.drop("function1.divide")
      
      -- Case2: Persistent Lua function
      box.schema.func.create("SUMMARIZE", {language = 'LUA',
      			returns = 'number',
      			body = 'function (a, b) return a + b end',
      			param_list = {'number', 'number'},
      			is_deterministic = true,
      			exports = {'LUA', 'SQL'}})
      box.execute('SELECT summarize(1, 2)')
      - metadata:
        - name: summarize(1, 2)
          type: number
        rows:
        - [3]
      box.schema.func.drop("summarize")
      
      Moreover there is a special predefined Lua function LUA that
      allows to evaluate a custom Lua expressions in SQL.
      You need to pass a string in form "return ...." to LUA function
      that returns more than one value of any type.
      
      Example:
      box.execute('SELECT lua(\'return 1 + 1\')')
      - metadata:
        - name: lua('return 1 + 1')
          type: any
        rows:
        - [2]
      box.execute('SELECT lua(\'return box.cfg.memtx_memory\')')
      - metadata:
        - name: lua('return box.cfg.memtx_memory')
          type: any
        rows:
        - [268435456]
      d4a7459e
    • Kirill Shcherbatov's avatar
      sql: get rid of FuncDef function hash · 45396002
      Kirill Shcherbatov authored
      Now it is possible to move all SQL builtin functions to
      Tarantool's function hash. An existent FuncDef function
      representation was replaced with func_sql_builtin class.
      It has a sql-specific method :call and :finalize, while
      port API call is not supported and protected with stubs.
      
      This patch removes FuncDef hash and sql_function_create endpoint,
      but doesn't introduce something instead. Therefore few affected
      tests are disabled. A required functionality would be fixed in
      the next patch.
      
      Following tests using sql_create_function are broken now.
      They are going to be fixed in the next commit:
       sql-tap/alias.test.lua sql-tap/check.test.lua
       sql-tap/func5.test.lua sql-tap/lua_sql.test.lua
       sql-tap/subquery.test.lua sql-tap/trigger9.test.lua
       sql/errinj.result sql/errinj.test.lua
       sql/func-recreate.test.lua
      
      Part of #2200, #4113, #2233
      
      @TarantoolBot document
      Title: SQL builtins priveleges
      
      All SQL built-ins are executed on SQL privilege level that is
      undefined yet.
      45396002
    • Kirill Shcherbatov's avatar
      sql: remove name overloading for SQL builtins · 5b8aebd6
      Kirill Shcherbatov authored
      Now all SQL builtins are unique, i.e. each function has the only
      hash table entry. This technique requires to remove static argc
      checks for some builtins(substr, round, like, trim, count,
      group_concat). Now they raise a runtime error in case of invalid
      usage.
      
      Updated error messages correspondingly, to provide more
      informative messages in such cases. Taking into account upcoming
      changes, all built-in functions names are uppercased.
      
      Needed for #2200, #4113, #2233
      5b8aebd6
    • Kirill Shcherbatov's avatar
      sql: replace flag MINMAX with flags MIN and MAX · ddc83e04
      Kirill Shcherbatov authored
      Replaced sql function flag SQL_FUNC_MINMAX with couple new flags
      SQL_FUNC_MIN and SQL_FUNC_MAX. This allows to distinguish MIN and
      MAX function by flag instead of using user_data context.
      
      This allows to delete user_data field in FundDef object in
      further refactoring.
      
      Needed for #2200, #4113, #2233
      ddc83e04
    • Kirill Shcherbatov's avatar
      sql: rename sql_vdbe_mem_alloc_region helper · 025f79bd
      Kirill Shcherbatov authored
      Changed sql_vdbe_mem_alloc_region routine name to the
      vdbe_mem_alloc_blob_region because we are going to introduce
      a new function with a really similar (but more appropriate) name
      vdbemem_alloc_on_region in following patch. Due to the fact that
      the function used only in vdbe.c module it has been moved there
      and has been marked as "static".
      
      Needed for #2200, #4113, #2233
      025f79bd
    • Nikita Pettik's avatar
      sql: make GREATEST/LEAST built-ins accept at least two args · 4125c4ef
      Nikita Pettik authored
      Before a46b5200 SQL implementation featured min()/max() functions
      overloading: if one argument was passed, then aggregate version would be
      invoked; otherwise - scalar one. We decided to get rid of it and rename
      scalar version to LEAST()/GREATEST() correspondingly. However, assertion
      inside their implementations has been remained: it verifies that number
      of passed arguments is greater than 1. On the other hand, now one can
      pass literally any number of arguments to this function, including one
      (which results in fired mentioned assertion) and zero (which leads to
      NULL dereference in expr.c: these functions are marked with
      SQL_FUNC_NEEDCOLL flag, and as a consequence they are assumed to have at
      least one argument). Firstly, let's place check that number of passed
      arguments more than one. Secondly, let's not assume that functions with
      SQL_FUNC_NEEDCOLL must have any arguments.
      
      Closes #4453
      4125c4ef
    • Georgy Kirichenko's avatar
      Destroy port after iproto eval if transaction isn't finished · ff14626d
      Georgy Kirichenko authored
      This is a followup for 7691154a
      ff14626d
    • Maria Khaydich's avatar
      Iproto call won't leak if transaction isn't committed · 7691154a
      Maria Khaydich authored
      In case of throwing client error because of inactive function
      we did not destroy used port. It could possibly cause huge
      memory leaks as could be seen with top or its analogues when
      performing net.box test run in a loop.
      
      Closes #4388
      7691154a
  6. Aug 28, 2019
    • Serge Petrenko's avatar
      replication: enter orphan mode on manual replication configuration chage · 5a0cfe02
      Serge Petrenko authored
      Currently we only enter orphan mode when instance fails to connect to
      replication_connect_quorum remote instances during local recovery.
      On bootstrap and manual replication configuration change an error is
      thrown. We better enter orphan mode on manual config change, and leave
      it only in case we managed to sync with replication_connect_quorum
      instances.
      
      Closes #4424
      
      @TarantoolBot document
      Title: document reaction on error in replication configuration change.
      
      Now when issuing `box.cfg{replication={uri1, uri2, ...}}` and failing to
      sync with replication_connect_quorum remote instances, the server will
      throw an error, if it is bootstrapping, and just set its state to orphan
      in all other cases (recovering from existing xlog/snap files or manually
      changing box.cfg.replication on the fly). To leave orphan mode, you may
      wait until the server manages to sync with replication_connect_quorum
      instances.
      In order to leave orphan mode you need to make the server sync with
      enough instances. To do so, you may either:
      1) set replication_connect_quorum to a lower value
      2) reset box.cfg.replication to exclude instances that cannot
         be reached or synced with
      3) just set box.cfg.replication to "" (empty string)
      5a0cfe02
    • Konstantin Osipov's avatar
      replication: do not abort replication on ER_UNKNOWN_REPLICA · a850acfd
      Konstantin Osipov authored
      In 3-node replica-set, registering with the leader node
      does not guarantee the registration record arrives to the second
      peer immediately. The joining node may bootstrap faster than
      the registration record arrives to the second peer, in which
      case replication will fail to create a full mesh.
      a850acfd
    • Konstantin Osipov's avatar
      systemd: Do nothing if NOTIFY_SOCKET env variable is not set. · 83ef5a17
      Konstantin Osipov authored
      A follow up on gh-4305, fix failing args.test.py
      83ef5a17
    • Konstantin Osipov's avatar
      Fix build failure on Linux. · ef14050f
      Konstantin Osipov authored
      ef14050f
  7. Aug 27, 2019
    • Max Melentiev's avatar
      Enable support for NOTIFY_SOCKET in envs without systemd · 1e509dde
      Max Melentiev authored
      To make it possible to develop and test related features on
      systems without systemd.
      
      WITH_SYSTEMD cmake flag is used to generate systemd related files:
      unit, generator script, etc. To keep this behavior and make it possible
      to use NOTIFY_SOCKET without other systemd-related stuff,
      I added WITH_NOTIFY_SOCKET cmake flag.
      
      It also required some changes to support other OS:
      
      SOCK_CLOEXEC (not available on macOS) flag for socket()
      is replaced with `fcntl(fd, F_SETFD, FD_CLOEXEC)` which has the same effect.
      
      MSG_NOSIGNAL flag for sendmsg is also not available on macOS.
      However it has SO_NOSIGPIPE flag for setsockopt which disables SIGPIPE.
      So it requires different solution for different OS. Inspired by
      https://nwat.xyz/blog/2014/01/16/porting-msg_more-and-msg_nosigpipe-to-osx/
      
      Have to reduce send-buffer size to 4MB because larger values
      are not supported on macOS by default. This value should be enough
      for all systems because notification messages are usually less than 1KB.
      
      Fixes #4436
      1e509dde
    • Vladislav Shpilevoy's avatar
      tuple: implement update by field name · 9ee5cf82
      Vladislav Shpilevoy authored
      Tuple fields can be named, accessed by name, indexed by name, but
      till this commit field names couldn't be used in update
      operations. Now it is possible.
      
      This patch is a teaser of updates by JSON path.
      
      Part of #1261
      9ee5cf82
    • Vladislav Shpilevoy's avatar
      int96: add a missing header · 6d4430d0
      Vladislav Shpilevoy authored
      6d4430d0
    • Vladislav Shpilevoy's avatar
      tuple: relax struct tuple_update dependency on rope · 74ae6780
      Vladislav Shpilevoy authored
      Rope will not be used by tuple_update directly in
      next patches.
      74ae6780
    • Vladislav Shpilevoy's avatar
      rope: make rope library macro template · baa4659c
      Vladislav Shpilevoy authored
      Rope library stores alloc, split and free functions by pointer,
      that is a huge slog at performance, as any other virtual
      function call. There is no reason, why the rope library may not
      become a template, except historical ones.
      
      The patch not only removes virtual functions, but also makes rope
      deletion almost no-op in case if free() function is not defined.
      
      A second motivation point of that patch is that original rope
      structure was too big. Again, because it stored several pointers
      to functions. In forthcoming patches on #1261 multiple ropes can
      be created per each update, so it makes sense to reduce size of
      this structure.
      baa4659c
    • Vladislav Shpilevoy's avatar
      tuple: remove alloc and alloc_ctx args from update() · dba9dba7
      Vladislav Shpilevoy authored
      They are always region_aligned_alloc and region pointer. Lets use
      them always inside tuple_update.c, with no necessity to pass
      explicitly.
      
      The patch is motivated by forthcoming updates by JSON path, which
      will strongly complicate and perhaps slow down the tuple_update.c
      code. The present patch as well as some next ones should smooth
      these problems.
      dba9dba7
    • Serge Petrenko's avatar
      lua: fix decimal comparison with box.NULL · 24e75aa8
      Serge Petrenko authored
      This problem is similar to the one fixed in commit
      3c6c1cc9 (lua:fix decimal comparison
      with nil)
      We should handle box.NULL the same way.
      
      Closes #4454
      24e75aa8
  8. Aug 26, 2019
    • Alexander Turenko's avatar
      lua: pwd: fix passwd and group traversal · 7753d350
      Alexander Turenko authored
      CentOS 6 and FreeBSD 12 implementations of getpwuid() rewind
      setpwent()-{getpwent()}-endpwent() loop to a start that leads to a hang
      during pwd.getpwall() invoke. The same is true for a getgrgid() call
      during setgrent()-{getgrent()}-endgrent() loop.
      
      The commit modifies pwd module to avoid getpwuid() calls during passwd
      database traversal and to avoid getgrgid() calls when traversing groups.
      
      The commit also fixes the important regression on CentOS 6 after
      f5d8331e ('lua: workaround
      pwd.getpwall() issue on Fedora 29'): tarantool hungs during startup due
      to added getpwall() call. This made tarantool unusable on CentOS 6 at
      all.
      
      Aside of that the commit fixes another pwd.getgrall() problem: the
      function gaves password entries instead of group entries.
      
      Fixes #4428.
      Fixes #4447.
      Part of #4271.
      7753d350
  9. Aug 22, 2019
    • Yaroslav Dynnikov's avatar
      feedback: unify payload generation logic · 5b9f207d
      Yaroslav Dynnikov authored
      This change is related to #4391. The objective was to collect additional
      information about modules, but it's hard to do without changing API.
      
      This patch will allow to monkey-patch report generation and achieve the
      same results without interfering the daemon behavior.
      5b9f207d
    • Max Melentiev's avatar
      systemd: replace sendmsg with sendto shortcut · 89aae30c
      Max Melentiev authored
      There is a problem with calculating .msg_namelen field
      of msghdr struct. Instead of
      
          .msg_name   = &sa,
          .msg_namelen = sizeof(sa.sun_family) + strlen(sd_unix_path),
      
      it must set as
      
          .msg_namelen = sizeof(sa) // larger value than current invalid one
      
      It works on linux but when I tried to enable this feature for macOS
      it didn't (maybe because of different order of fields in the struct).
      
      Instead of fixing calculation, I've replaced original sendmsg call
      with sendto, because it's a convenient shortcut which
      simplifies code and can prevent such mistakes.
      
      Required for #4436
      89aae30c
    • Nikita Pettik's avatar
      Move mp_compare_double_uint64() to trivia/util.h · 72dbeb0e
      Nikita Pettik authored
      This function implements common way of precise comparison between
      unsigned integer and floating point values (doubles). Currently, it is
      used in tuple comparators, but we need the same thing in SQL. Hence,
      let's move it to header containing set of utilities.
      72dbeb0e
    • Nikita Pettik's avatar
      sql: use double_compare_uint64() for int<->float cmp · 73a4a525
      Nikita Pettik authored
      To compare floating point values and integers in SQL functions
      compare_uint_float() and compare_int_float() are used. Unfortunately,
      they contain bug connected with checking border case: that's not correct
      to cast UINT64_MAX (2^64 - 1) to double. Proper way is to use exp2(2^64)
      or predefined floating point constant. To not bother fixing function
      which in turn may contain other tricky places, let's use instead already
      verified double_compare_uint64(). So that we have unified way of
      integer<->float comparison.
      73a4a525
    • Nikita Pettik's avatar
      sql: allow to specify engine in CREATE TABLE stmt · 1013a744
      Nikita Pettik authored
      Closes #4422
      
      @TarantoolBot document
      Title: Introduce <WITH ENGINE> clause for CREATE TABLE statement
      
      To allow user to specify engine as per table option, CREATE TABLE
      statement has been extended with optional <WITH ENGINE = engine_name>
      clause. This clause comes at the end of CREATE TABLE statement.
      For instance:
      
      CREATE TABLE t_vinyl (id INT PRIMARY KEY) WITH ENGINE = 'vinyl';
      
      Name of engine is considered to be string literal ergo should be
      enclosed in single quotation marks and be lower-cased. Note that engine
      specified in WITH ENGINE clause overwrites default engine, which is set
      via 'pragma sql_default_engine'.
      1013a744
    • Nikita Pettik's avatar
      Do not log error in engine_find() · 35177fe0
      Nikita Pettik authored
      Error logging in engine_find() seems to be redundant: error message is
      displayed twice (since its callers always push error on the top).  Let's
      remove this duplication.
      35177fe0
    • Nikita Pettik's avatar
      txn: erase old savepoint in case of name collision · 8b8b6895
      Nikita Pettik authored
      Name duplicates are allowed for savepoints (both in our SQL
      implementation and in ANSI specification). ANSI SQL states that previous
      savepoint should be deleted. What is more, our doc confirms this fact
      and says that "...it is released before the new savepoint is set."
      Unfortunately, it's not true - currently old savepoint remains in the
      list. For instance:
      
      SAVEPOINT t;
      SAVEPOINT t;
      RELEASE SAVEPOINT t;
      RELEASE SAVEPOINT t; -- no error is raised
      
      Let's fix this and remove old savepoint from the list.
      8b8b6895
    • Nikita Pettik's avatar
      sql: use struct txn_savepoint as anonymous savepoint · 0a92ec7e
      Nikita Pettik authored
      This allows us to completely remove SQL specific struct Savepoint and
      use instead original struct txn_savepoint.
      0a92ec7e
    • Nikita Pettik's avatar
      txn: merge struct sql_txn into struct txn · 56096ff2
      Nikita Pettik authored
      This procedure is processed in several steps. Firstly, we add name
      to struct txn_savepoint since we should be capable of operating on named
      savepoints (which in turn is SQL feature). Still, anonymous (in the sense
      of name absence) savepoints are also valid. Then, we add list (as
      implementation of stailq) of savepoints to struct txn: it allows us to
      find savepoint by its name. Finally, we patch rollback to/release
      savepoint routines: for rollback tail of the list containing savepoints
      is cut (but subject of rollback routine remains in the list); for
      release routine we cut tail including node being released.
      56096ff2
    • Nikita Pettik's avatar
      txn: move fk_deferred_count from psql_txn to txn · 5259274d
      Nikita Pettik authored
      We are going to merge struct psql_txn with struct txn as a part of SQL
      integration into NoSQL, so let's move counter of deferred foreign key
      violations directly to struct txn.
      5259274d
    • Serge Petrenko's avatar
      box: add support for decimals in update ops · 8317189a
      Serge Petrenko authored
      Closes #4413
      
      @TarantoolBot document
      Title: update operations on decimal fields.
      
      tuple:update and space:update now support deicmal operands for
      arithmetic operations ('+' and '-'). The syntax is as usual:
      ```
      d = box.tuple.new(decimal.new('1'))
      ---
      ...
      d:update{{'+', 1, decimal.new('0.5')}}
      ---
      - [1.5]
      ...
      ```
      
      Insertion ('!') and assignment ('=') are also supported:
      ```
      a = decimal.new('1')
      ---
      ...
      b = decimal.new('1e10')
      ---
      ...
      c = decimal.new('1e-10')
      ---
      ...
      d = box.tuple.new{5, a, 6, b, 7, c, "string"}
      ---
      ...
      d
      ---
      - [5, 1, 6, 10000000000, 7, 0.0000000001, 'string']
      ...
      
      d:update{{'!', 3, dec.new('1234.5678')}}
      ---
      - [5, 1, 1234.5678, 6, 10000000000, 7, 0.0000000001, 'string']
      ...
      d:update{{'=', -1, dec.new('0.12345678910111213')}}
      ---
      - [5, 1, 6, 10000000000, 7, 0.0000000001, 0.12345678910111213]
      
      When performing an arithmetic operation ('+', '-'), where either the
      updated field or the operand is decimal, the result will be decimal.
      
      When both the updated field and the operand are decimal, the result
      will, of course, be decimal.
      
      ...
      ```
      8317189a
    • Serge Petrenko's avatar
      decimal: allow to index decimals · 8ba72670
      Serge Petrenko authored
      Closes #4333
      
      @TarantoolBot document
      Title: Document decimal field type.
      
      Decimals may now be stored in spaces. A corresponding field type is
      introduced: 'decimal'. Decimal values are also allowed in 'scalar',
      'any' and 'number' fields.
      
      'decimal' field type is appropriate for both memtx HASH and TREE
      indices, as well as for vinyl TREE index.
      
      ```
      To create an index 'pk' over a decimal field, say
      ```
      tarantool> box.space.test:create_index('pk', {parts={1, 'decimal'}})
      ---
      - unique: true
        parts:
        - type: decimal
          is_nullable: false
          fieldno: 1
        id: 0
        space_id: 512
        type: TREE
        name: pk
      ...
      ```
      Now you can insert some decimal values:
      ```
      tarantool> for i = 1,10 do
               > box.space.test:insert{decimal.new((i-5)/10)}
               > end
      ---
      ...
      ```
      tarantool> box.space.test:select{}
      ---
      - - [-0.4]
        - [-0.3]
        - [-0.2]
        - [-0.1]
        - [0]
        - [0.1]
        - [0.2]
        - [0.3]
        - [0.4]
        - [0.5]
      ...
      ```
      Decimals may alse be inserted into `scalar` and `number` fields. In this
      case all the number values are sorted correctly:
      ```
      tarantool> box.schema.space.create('test')
      tarantool> box.space.test:create_index('pk', {parts={1, 'number'}})
      tarantool> box.space.test:insert{-1.0001, 'number'}
      ---
      - [-1.0001, 'number']
      ...
      
      tarantool> box.space.test:insert{decimal.new(-1.00001), 'decimal'}
      ---
      - [-1.00001, 'decimal']
      ...
      
      tarantool> box.space.test:insert{-1, 'number'}
      ---
      - [-1, 'number']
      ...
      
      tarantool> box.space.test:insert{decimal.new(-0.999), 'decimal'}
      ---
      - [-0.999, 'decimal']
      ...
      
      tarantool> box.space.test:insert{-0.998, 'number'}
      ---
      - [-0.998, 'number']
      ...
      
      tarantool> box.space.test:insert{-0.9, 'number'}
      ---
      - [-0.9, 'number']
      ...
      
      tarantool> box.space.test:insert{-0.95, 'number'}
      ---
      - [-0.95, 'number']
      ...
      
      tarantool> box.space.test:insert{decimal.new(-0.92), 'decimal'}
      ---
      - [-0.92, 'decimal']
      ...
      
      tarantool> box.space.test:insert{decimal.new(-0.971), 'decimal'}
      ---
      - [-0.971, 'decimal']
      ...
      
      tarantool> box.space.test:select{}
      ---
      - - [-1.0001, 'number']
        - [-1.00001, 'decimal']
        - [-1, 'number']
        - [-0.999, 'decimal']
        - [-0.998, 'number']
        - [-0.971, 'decimal']
        - [-0.95, 'number']
        - [-0.92, 'decimal']
        - [-0.9, 'number']
      ...
      
      ```
      Uniqueness is also preserved between decimals and other number types:
      ```
      tarantool> box.space.test:insert{-0.92}
      ---
      - error: Duplicate key exists in unique index 'pk' in space 'test'
      ...
      
      tarantool> box.space.test:insert{decimal.new(-0.9)}
      ---
      - error: Duplicate key exists in unique index 'pk' in space 'test'
      ...
      
      ```
      
      You can also set decimal fields in space format:
      ```
      tarantool> _ = box.schema.space.create('test')
      ---
      ...
      
      tarantool> _ = box.space.test:create_index('pk')
      ---
      ...
      
      tarantool> box.space.test:format{{name='id', type='unsigned'}, {name='balance', type='decimal'}}
      ---
      ...
      
      tarantool> box.space.test:insert{1}
      ---
      - error: Tuple field 2 required by space format is missing
      ...
      
      tarantool> box.space.test:insert{1, 'string'}
      ---
      - error: 'Tuple field 2 type does not match one required by operation: expected decimal'
      ...
      
      tarantool> box.space.test:insert{1, 1.2345}
      ---
      - error: 'Tuple field 2 type does not match one required by operation: expected decimal'
      ...
      
      tarantool> box.space.test:insert{1, decimal.new('1337.420')}
      ---
      - [1, 1337.420]
      ...
      
      ```
      8ba72670
    • Serge Petrenko's avatar
      decimal: add conversions to (u)int64_t · 8d2e7839
      Serge Petrenko authored
      Update decNumber library, add methods to convert decimals to uint64_t
      and int64_t, add unit tests.
      Also replace decimal_round() function with decimal_round_with_mode() to
      allow setting rounding mode.
      We need to round with mode DEC_ROUND_DOWN in to_int64 conversions in
      order to be consistent with double to int conversions.
      It will be needed to compute hints for decimal fields.
      
      Prerequisite #4333
      8d2e7839
Loading