Skip to content
Snippets Groups Projects
  1. Mar 24, 2021
    • Vladislav Shpilevoy's avatar
      cord_buf: introduce cord_buf API · ade45685
      Vladislav Shpilevoy authored
      There was a global ibuf object called tarantool_lua_ibuf. It was
      used in all the places working with Lua which didn't have yields,
      and where fiber's region could be potentially slower due to not
      being able to guarantee the allocated memory is contiguous.
      
      Yields during the ibuf usage were prohibited because another fiber
      would take the same ibuf and override its previous content which
      was still used by another fiber.
      
      But it wasn't taken into account that there is Lua GC. It can be
      invoked from any Lua function in Lua C code, and almost on any
      line in the Lua scripts. During GC some deleted objects might have
      GC handlers installed as __gc metamethods. From the handler they
      could call Tarantool functions, including the ones using the
      global ibuf.
      
      Therefore ibuf could be overridden not only at yields, but almost
      in any moment. Because with the Lua GC at hand, the multitasking
      is not strictly "cooperative" anymore.
      
      It is necessary to implement ownership for the global buffer. The
      patch prepares the API for this: the buffer is moved to its own
      file, and has methods take(), put(), and drop().
      
      Take() is supposed to make the current fiber own the buffer. Put()
      makes it available again. Drop() does the same but also clears the
      buffer (frees its memory). The ownership itself is a subject for
      the next patches. Here only the API is prepared.
      
      The patch "hits" performance a little. Previously the get of
      buffer.IBUF_SHARED cost around 1 ns. Now cord_ibuf_take() +
      cord_ibuf_put() cost around 5 ns together. The next patches will
      make it worse, up to 15 ns until #5871 is done.
      
      Part of #5632
      ade45685
    • Vladislav Shpilevoy's avatar
      iconv: take errno before reseting the context · 8c489744
      Vladislav Shpilevoy authored
      In Lua iconv_convert() in case ffi.C.tnt_iconv() with normal
      arguments failed, tried to clear iconv context by calling the
      function again with all arguments NULL. Then it looked at errno.
      
      But the second call could do anything with errno. For instance, it
      could also fail, and change errno.
      
      The patch saves errno into a variable before calling tnt_iconv()
      second time.
      
      It still does not give a perfect protection as it was discovered
      in scope of #5632, but still better.
      
      The patch is mostly motivated by the next patches about #5632
      which will add another call to the error path, and it should
      better be after errno save.
      
      Needed for #5632
      8c489744
    • Vladislav Shpilevoy's avatar
      tuple: pass global ibuf explicitly where possible · fabf0d57
      Vladislav Shpilevoy authored
      Code in lua/tuple.c used global tarantool_lua_ibuf in many places
      relying on it never being changed and not reused by other code
      until a yield.
      
      But it is not so. In fact, as it was discovered in #5632, in any
      Lua function may be started GC. Any GC handler might touch some
      API also using tarantool_lua_ibuf inside.
      
      This makes the first usage in lua/tuple.c invalid - the buffer
      could be reset or reallocated or its wpos/rpos could change during
      GC.
      
      In order to fix this, first of all there should be clear points
      where the buffer is taken, and where it becomes not needed
      anymore.
      
      The patch makes code in lua/tuple.c take tarantool_lua_ibuf when
      it is needed first time. Not during usage. The same is done for
      the fiber region for the API symmetry.
      
      Part of #5632
      fabf0d57
    • Vladislav Shpilevoy's avatar
      test: don't use IBUF_SHARED in the tests · d0f0fc47
      Vladislav Shpilevoy authored
      In msgpack test it is used only to check that 'struct ibuf *' can
      be passed to encode() functions. But soon IBUF_SHARED will be
      deleted, and its alternative won't be yield-tolerant. This means
      it can't be used in this test. There are yields between the buffer
      usages.
      
      In varbinary test it is used in a too complicated way to be able
      to put it back normally. And otherwise its usage does not make
      much sense - without put() it is going to be created from the
      scratch on non-first usage until a yield.
      
      In the module_api test it is used to check if some function works
      with 'struct ibuf *'. Can be done without IBUF_SHARED.
      
      Part of #5632
      d0f0fc47
    • Vladislav Shpilevoy's avatar
      fio: don't use shared buffer in pread() · 24d86294
      Vladislav Shpilevoy authored
      fio:pread() used buffer.IBUF_SHARED, which might be reused after a
      yield. As a result, if pread() was called from 2 different fibers
      or in parallel with something else using IBUF_SHARED, it would
      turn the buffer into garbage for all parallel usages.
      
      The same problem existed for read(), and was fixed in
      c7c24f84 ("fio: Fix race condition
      in fio.read"). But apparently pread() was missed.
      
      What is worse, the original commit's test passed even without the
      fix from that commit. Because it didn't check the results of
      read()s called from 2 fibers.
      
      The patch fixes pread() and adds a test covering both read() and
      pread(). The old test from the original commit is dropped.
      
      Follow up #3187
      24d86294
  2. Mar 22, 2021
  3. Mar 19, 2021
    • Vladislav Shpilevoy's avatar
      lua: separate sched and script diag · f4e248c0
      Vladislav Shpilevoy authored
      When Lua main script was launched, the sched fiber passed its own
      diag to the script's fiber. When the script was finished, it put
      its error into the diag. The sched fiber then checked if the diag
      is empty to detect an error.
      
      But it wasn't really correct. The error could also happen right in
      the scheduler fiber in a libev callback. For example, in one of
      ev_io callbacks in SWIM. Then the process would end with an error
      even if the script was finished successfully.
      
      These errors were not related to the main fiber executing the
      script.
      
      The patch makes so the scheduler fiber's diag no longer is used as
      an indication of an error in the script. Instead, a new diag is
      created on the stack of the scheduler's fiber, where the Lua
      script saves the error.
      
      Closes #5864
      f4e248c0
    • Vladislav Shpilevoy's avatar
      swim: add SO_BROADCAST option · 1844eb6f
      Vladislav Shpilevoy authored
      Swim node couldn't talk to broadcast network interfaces because
      the option SO_BROADCAST wasn't set.
      
      It worked fine for localhost broadcast, but failed for all the
      other IPs. There is no a test, because the tests work for the
      localhost only anyway.
      
      It still fails on Mac though in case the swim node was bound to
      127.0.0.1. Then somewhy sendto() raises EADDRNOTAVAIL on attempt
      to broadcast beyond the local machine. It happens on Linux too,
      but with EINVAL error. These errors are ignored because are not
      critical.
      
      Part of #5864
      1844eb6f
    • Sergey Nikiforov's avatar
      base64: fix decoder output buffer overrun (reads) · 778d34e8
      Sergey Nikiforov authored
      Was caught by base64 test with enabled ASAN.
      
      It also caused data corruption - garbage instead of "extra bits" was
      saved into state->result if there was no space in output buffer.
      
      Decode state removed along with helper functions.
      
      Added test for "zero-sized output buffer" case.
      
      Fixes: #3069
      (cherry picked from commit 7214add2c7f2a86265a5e08f2184029a19fc184d)
      778d34e8
    • Serge Petrenko's avatar
      wal: introduce limits on simultaneous writes · de93b448
      Serge Petrenko authored
      Since the introduction of asynchronous commit, which doesn't wait for a
      WAL write to succeed, it's quite easy to clog WAL with huge amounts
      write requests. For now, it's only possible from an applier, since it's
      the only user of async commit at the moment.
      
      This happens when replica is syncing with master and reads new
      transactions at a pace higher than it can write them to WAL (see docbot
      request for detailed explanation).
      
      To ameliorate such behavior, we need to introduce some limit on
      not-yet-finished WAL write requests. This is what this commit is trying
      to do.
      A new counter is added to wal writer: queue_size (in bytes) together with a
      corresponding configuration setting: `wal_queue_max_size`.
      The counter is increased on every new submitted request, and decreased once
      the tx thread receives a confirmation that a specific request was written.
      
      Actually, the limit is added to an abstract journal queue, but
      currently works only for wal writer, since it's the only possible journal
      when applier is working.
      
      Once size reaches its maximum value, applier is blocked until
      some of the write requests are finished.
      
      The size limit isn't strict, i.e. if there's at least one free byte, the
      whole write request fits and no blocking is involved.
      
      The feature is ready for `box.commit{is_async=true}`. Once it's
      implemented, it should check whether the queue is full and let the user
      decide what to do next. Either wait or roll the tx back.
      
      Closes #5536
      
      @TarantoolBot document
      Title: new configuration option: 'wal_queue_max_size'
      
      `wal_queue_max_size` puts a limit on the amount of concurrent write requests
      submitted to WAL.
      `wal_queue_max_size` is measured in number of bytes to be written (0
      means unlimited, which was the default behaviour before).
      The option only affects replica behaviour at the moment, and defaults
      to 16 megabytes. The option limits the pace at which replica reads new
      transactions from master.
      
      Here's when the option comes in handy:
      
      Before this option was introduced such a situation could be possible:
      there are 2 servers, a master and a replica, and the replica is down for
      some period of time. While the replica is down, master serves requests
      at a reasonable pace, possibly close to its WAL throughput limit. Once the
      replica reconnects, it has to receive all the data master has piled up and
      there's no limit in speed at which master sends the data to replica, and,
      without the option, there was no limit in speed at which replica submitted
      corresponding write requests to WAL.
      
      This lead to a situation when replica's WAL was never in time to serve the
      requests and the amount of pending requests was constantly growing.
      There was no limit for memory WAL write requests take, and this clogging
      of WAL write queue could even lead to replica using up all the available
      memory.
      
      Now, when `wal_queue_max_size` is set, appliers will stop reading new
      transactions once the limit is reached. This will let WAL process all the
      requests that have piled up and free all the excess memory.
      de93b448
    • mechanik20051988's avatar
      Implement on_shutdown API · 3010f024
      mechanik20051988 authored
      Implemented on_shutdown API, which allows to register functions
      that will be called when the tarantool stopped. Functions will
      be called in the reverse order they are registered. So the module
      developer registers one fuction that starts module termination and
      waits for its competition. This function should be fast or used an
      asynchronous waiting mechanism (coio_wait or cord_cojoin for example).
      
      Closes #5723
      
      @TarantoolBot document
      Title: Implement on_shutdown API
      Implemented on_shutdown API, which allows to register functions
      that will be called when the tarantool stopped. Functions will
      be called in the reverse order they are registered. So the module
      developer registers one fuction that starts module termination and
      waits for its competition. This function should be fast or used an
      asynchronous waiting mechanism (coio_wait or cord_cojoin for example).
      3010f024
    • mechanik20051988's avatar
      lua: change on_shutdown triggers behaviour · 357f1551
      mechanik20051988 authored
      Previously lua on_shutdown triggers were started sequentially, now
      each of triggers starts in a separate fiber. Tarantool waits for 3.0
      seconds to their completion by default. User has the option to change
      this value using new implemented box.ctl.set_on_shutdown_timeout function.
      If timeout has expired, tarantool immediately stops, without waiting for
      other triggers completion.
      Also moved ev_break from trigger to the on_shutdown_f function, after
      calling all on_shutdown lua triggers, because now all triggers are
      started asynchronously in fibers, and we should call ev_break only
      after all triggers are finished.
      
      Part of #5723
      
      @TarantoolBot document
      Title: Changed Lua on_shutdown triggers behaviour.
      Previously lua on_shutdown triggers were started sequentially, now
      each of triggers starts in a separate fiber. Tarantool waits for 3.0
      seconds to their completion by default. User has the option to change
      this value using new implemented box.ctl.set_on_shutdown_timeout function.
      If timeout has expired, tarantool immediately stops, without waiting for
      other triggers completion.
      357f1551
    • mechanik20051988's avatar
      Rename on_shutdown triggers list head · 3b7fe7d6
      mechanik20051988 authored
      Since the function for registering on_shutdown triggers for
      tarantool modules was decided to be named box_on_shutdown,
      the head of the trigger list with a similar name was renamed.
      
      Part of #5723
      3b7fe7d6
    • mechanik20051988's avatar
      Implement trigger_fiber_run function · c1020a69
      mechanik20051988 authored
      Implemented function for starting a chain of triggers
      in separate fibers, which is required for on_shutdown
      API implementation.
      
      Part of #5723
      c1020a69
    • mechanik20051988's avatar
      Implement fiber_join_timeout function · 4ac5a3cb
      mechanik20051988 authored
      Implemented fiber_join_timeout function, which allows to wait
      for the completion of the fiber for a specified period of time.
      Function returns fiber execution status to the caller or -1
      if the timeout exceeded and set diag. Needed for further
      on_shutdown API implementation.
      
      Part of #5723
      4ac5a3cb
    • mechanik20051988's avatar
      box: rename granularity option in box.cfg{} to slab_alloc_granularity · 501da2bf
      mechanik20051988 authored
      Renamed granularity option to slab_alloc_granularity, according
      to the name of the other options for small allocator.
      
      Follow-up #5518
      501da2bf
  4. Mar 18, 2021
  5. Mar 17, 2021
    • Sergey Kaplun's avatar
      luajit: bump new version · a0ade206
      Sergey Kaplun authored
      LuaJIT submodule is bumped to introduce the following changes:
      * test: disable LuaJIT CLI tests in lua-Harness suite
      * test: set USERNAME env var for lua-Harness suite
      * test: adjust lua-Harness tests that use dofile
      * test: adjust lua-Harness suite to CMake machinery
      * test: add lua-Harness test suite
      
      Within this changeset lua-Harness suite[1] is added to Tarantool
      testing. Considering Tarantool specific changes in runtime the suite
      itself is adjusted in LuaJIT submodule.
      
      However, Tarantool provides and unconditionally loads TAP module
      conflicting with the one used in the new suite. Hence, the Tarantool
      built-in module is "unloaded" in test/luajit-test-init.lua.
      
      Furthermore, Tarantool provides UTF-8 support via another built-in
      module. Its interfaces differ from the ones implemented in Lua5.3 and
      moonjit. At the same time our LuaJIT fork provides no UTF-8 support, so
      lua-Harness UTF-8 detector is simply confused with non-nil utf8 global
      variable. As a result, utf8 is set to nil in test/luajit-test-init.lua.
      
      There are also some tests launching Lua interpreter, so strict need to
      be disabled for their child tests too. Hence `strict.off()` is added to
      `progname` (i.e. arg[-1] considering the way Tarantool parses its CLI
      arguments) command used in these tests.
      
      [1]: https://framagit.org/fperrad/lua-Harness/tree/a74be27/test_lua
      
      
      
      Closes #5844
      Part of #4473
      
      Reviewed-by: default avatarSergey Ostanevich <sergos@tarantool.org>
      Reviewed-by: default avatarIgor Munkin <imun@tarantool.org>
      Signed-off-by: default avatarIgor Munkin <imun@tarantool.org>
      a0ade206
    • Nikita Pettik's avatar
      xlog: fix xdir_say_gc() usage in xdir_collect_garbage() · b2e57ac5
      Nikita Pettik authored
      xdir_say_gc() takes errno and return code of unlink() sys call. If RC
      is negative (meaning that unlink failed) we reset errno to given value
      and log corresponding error message (it is done this way since eio saves
      errno to internal structure so we have to restore it manually). Before
      this patch, unlink() call was "in-place" of argument. However, the order
      of argument evaluation is unspecified. So it may turn out that we assign
      errno to the previous value, which is obviously wrong. To fix it let's
      firstly invoke unlink() and then pass the result of call to
      xdir_say_gc().
      b2e57ac5
    • Alexander V. Tikhonov's avatar
      github-ci: add manual run ability to workflows · 5f0bbe12
      Alexander V. Tikhonov authored
      Added manual and backend triggers to run test workflows. It will
      give the ability to run missed/needed workflows in Github Actions
      and to use standalone backend scripts to run test workflows.
      5f0bbe12
  6. Mar 16, 2021
  7. Mar 15, 2021
  8. Mar 12, 2021
    • Artem Starshov's avatar
      lua: fix tarantool -e always enters interactive mode · 0787483c
      Artem Starshov authored
      The reason why tarantool -e always enters interactive mode is that
      statement after option -e isn't considered as a script.
      
      In man PUC-Rio lua there are different names for statement -e (stat)
      and script, but they have the same behavior regarding interactive
      mode. (Also cases, when interpreter loads stdin, have the same behaviour).
      
      NOTE: test for this code fix uses errinjs, and the last one  should work only
      in debug mode, so added `release_disabled` in suite.ini. But there is a bug in
      test-run: `release_disable` disables tests at each build type. Partially this
      problem is descripted in tarantool/test-run#199.
      
      Fixes #5040
      0787483c
    • Artem Starshov's avatar
      core: add setting error injections via env · 80f306e6
      Artem Starshov authored
      Sometimes, it's useful to set error injections via environment
      variables and this commit adds this opportunity.
      
      e.g: `ERRINJ_WAL_WRITE=true tarantool` will be launched with
      ERRINJ_WAL_WRITE setted to true.
      
      Errinjs with bool parameters can be set to "true", "false",
      "True", "False", "TRUE", "FALSE", etc. (case-insensitive variable).
      
      Errinjs with int or double parameters should be whole valid ("123s" is invalid).
      e.g. for int or double: "123", "-1", "2.34", "+2.34".
      
      NOTE: errinjs should work only in debug mode, so added `release_disabled` in
      suite.ini. But there is a bug in test-run: `release_disable` disables tests at
      each build type. Partially this problem is descripted in tarantool/test-run#199.
      
      Part of #5040
      80f306e6
  9. Mar 11, 2021
Loading