1. 21 Jul, 2021 4 commits
    • Oran Agra's avatar
      Fix race in client side tracking (#9116) · d80c8711
      Oran Agra authored
      The `Tracking gets notification of expired keys` test in tracking.tcl
      used to hung in valgrind CI quite a lot.
      
      It turns out the reason is that with valgrind and a busy machine, the
      server cron active expire cycle could easily run in the same event loop
      as the command that created `mykey`, so that when they key got expired,
      there were two change events to broadcast, one that set the key and one
      that expired it, but since we used raxTryInsert, the client that was
      associated with the "last" change was the one that created the key, so
      the NOLOOP filtered that event.
      
      This commit adds a test that reproduces the problem by using lazy expire
      in a multi-exec which makes sure the key expires in the same event loop
      as the one that added it.
      
      (cherry picked from commit 9b564b52)
      d80c8711
    • YaacovHazan's avatar
      unregister AE_READABLE from the read pipe in backgroundSaveDoneHandlerSocket (#8991) · da127ed3
      YaacovHazan authored
      In diskless replication, we create a read pipe for the RDB, between the child and the parent.
      When we close this pipe (fd), the read handler also needs to be removed from the event loop (if it still registered).
      Otherwise, next time we will use the same fd, the registration will be fail (panic), because
      we will use EPOLL_CTL_MOD (the fd still register in the event loop), on fd that already removed from epoll_ctl
      
      (cherry picked from commit 501d7755)
      da127ed3
    • guybe7's avatar
      Add a timeout mechanism for replicas stuck in fullsync (#8762) · ea0a3764
      guybe7 authored
      Starting redis 6.0 (part of the TLS feature), diskless master uses pipe from the fork
      child so that the parent is the one sending data to the replicas.
      This mechanism has an issue in which a hung replica will cause the master to wait
      for it to read the data sent to it forever, thus preventing the fork child from terminating
      and preventing the creations of any other forks.
      
      This PR adds a timeout mechanism, much like the ACK-based timeout,
      we disconnect replicas that aren't reading the RDB file fast enough.
      
      (cherry picked from commit d63d0260)
      ea0a3764
    • Oran Agra's avatar
      if diskless repl child is killed, make sure to reap the pid (#7742) · 18429ce5
      Oran Agra authored
      Starting redis 6.0 and the changes we made to the diskless master to be
      suitable for TLS, I made the master avoid reaping (wait3) the pid of the
      child until we know all replicas are done reading their rdb.
      
      I did that in order to avoid a state where the rdb_child_pid is -1 but
      we don't yet want to start another fork (still busy serving that data to
      replicas).
      
      It turns out that the solution used so far was problematic in case the
      fork child was being killed (e.g. by the kernel OOM killer), in that
      case there's a chance that we currently disabled the read event on the
      rdb pipe, since we're waiting for a replica to become writable again.
      and in that scenario the master would have never realized the child
      exited, and the replica will remain hung too.
      Note that there's no mechanism to detect a hung replica while it's in
      rdb transfer state.
      
      The solution here is to add another pipe which is used by the parent to
      tell the child it is safe to exit. this mean that when the child exits,
      for whatever reason, it is safe to reap it.
      
      Besides that, i'm re-introducing an adjustment to REPLCONF ACK which was
      part of #6271 (Accelerate diskless master connections) but was dropped
      when that PR was rebased after the TLS fork/pipe changes (5a477946).
      Now that RdbPipeCleanup no longer calls checkChildrenDone, and the ACK
      has chance to detect that the child exited, it should be the one to call
      it so that we don't have to wait for cron (server.hz) to do that.
      
      (cherry picked from commit 573246f7)
      18429ce5
  2. 02 Mar, 2021 2 commits
    • Yossi Gottlieb's avatar
      Fix failed tests on Linux Alpine and add a CI job. (#8532) · d0762100
      Yossi Gottlieb authored
      * Remove linux/version.h dependency.
      
      This introduces unnecessary dependencies, and generally not a good idea
      as the platform we build on may be different than the platform we run
      on.
      
      To determine if sync_file_range exists we can simply rely on header file
      hints.
      
      * Fix setproctitle() on libmusl.
      
      The previous ifdef checks were a bit too strict for no apparent
      reason.
      
      * Fix tests failure on Linux with no backtrace.
      
      * Add alpine daily CI job.
      
      (cherry picked from commit 95ea7454)
      d0762100
    • sundb's avatar
      Fix timing error oom-score-adj test (#8513) · 40ec7a27
      sundb authored
      fixes timing issue, fork didn't always get to set the oom score before the test verified it.
      
      (cherry picked from commit 46346e9e)
      40ec7a27
  3. 22 Feb, 2021 1 commit
    • Viktor Söderqvist's avatar
      RM_ZsetRem: Delete key if empty (#8453) · 17c3ac89
      Viktor Söderqvist authored
      Without this fix, RM_ZsetRem can leave empty sorted sets which are
      not allowed to exist.
      
      Removing from a sorted set while iterating seems to work (while
      inserting causes failed assetions). RM_ZsetRangeEndReached is
      modified to return 1 if the key doesn't exist, to terminate
      iteration when the last element has been removed.
      
      (cherry picked from commit aea6e71e)
      17c3ac89
  4. 12 Jan, 2021 12 commits
    • Oran Agra's avatar
      Improve stability of new CSC eviction test (#8160) · 5745b469
      Oran Agra authored
      c4fdf09c added a test that now fails with valgrind
      it fails for two resons:
      1) the test samples the used memory and then limits the maxmemory to
         that value, but it turns out this is not atomic and on slow machines
         the background cron process that clean out old query buffers reduces
         the memory so that the setting doesn't cause eviction.
      2) the dbsize was tested late, after reading some invalidation messages
         by that time more and more keys got evicted, partially draining the
         db. this is not the focus of this fix (still a known limitation)
      
      (cherry picked from commit a102b21d)
      5745b469
    • Oran Agra's avatar
      fix race in cluster transactions test (#8312) · a11c842e
      Oran Agra authored
      we didn't wait for the commands executed on the master to reach the replica.
      
      (cherry picked from commit 4f8458d8)
      a11c842e
    • Oran Agra's avatar
      Fix cluster diskless load swapdb test (#8308) · 615eb0db
      Oran Agra authored
      The test was trying to wait for the replica to start loading the rdb
      from the master before it kills the master, but it was actually waiting
      for ROLE to be in "sync" mode, which corresponds to REPL_STATE_TRANSFER
      that starts before the actual loading starts.
      now instead it waits for the loading flag to be set.
      
      Besides, the test was dependent on the previous configuration of the
      servers, relying on the fact the replica is configured to persist
      (either RDB of AOF), now it is set explicitly.
      
      (cherry picked from commit 26495387)
      615eb0db
    • Meir Shpilraien (Spielrein)'s avatar
      Moved RMAPI_FUNC_SUPPORTED location such that it will be visible to modules (#8037) · fb86ecb8
      Meir Shpilraien (Spielrein) authored
      The RMAPI_FUNC_SUPPORTED was defined in the wrong place on redismodule.h
      and was not visible to modules.
      
      (cherry picked from commit 97d647a1)
      fb86ecb8
    • Oran Agra's avatar
      prevent client tracking from causing feedback loop in performEvictions (#8100) · f2f57eb4
      Oran Agra authored
      When client tracking is enabled signalModifiedKey can increase memory usage,
      this can cause the loop in performEvictions to keep running since it was measuring
      the memory usage impact of signalModifiedKey.
      
      The section that measures the memory impact of the eviction should be just on dbDelete,
      excluding keyspace notification, client tracking, and propagation to AOF and replicas.
      
      This resolves part of the problem described in #8069
      p.s. fix took 1 minute, test took about 3 hours to write.
      
      (cherry picked from commit c4fdf09c)
      f2f57eb4
    • Madelyn Olson's avatar
      Further improved ACL algorithm for picking categories · e664f381
      Madelyn Olson authored
      (cherry picked from commit 411bcf1a)
      e664f381
    • Yang Bodong's avatar
      Swapdb should make transaction fail if there is any client watching keys (#8239) · f464cf23
      Yang Bodong authored
      
      
      This PR not only fixes the problem that swapdb does not make the
      transaction fail, but also optimizes the FLUSHALL and FLUSHDB command to
      set the CLIENT_DIRTY_CAS flag to avoid unnecessary traversal of clients.
      
      FLUSHDB was changed to first iterate on all watched keys, and then on the
      clients watching each key.
      Instead of iterating though all clients, and for each iterate on watched keys.
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit 10f94b0a)
      f464cf23
    • Oran Agra's avatar
      Fix wrong order of key/value in Lua map response (#8266) · ec56906b
      Oran Agra authored
      When a Lua script returns a map to redis (a feature which was added in
      redis 6 together with RESP3), it would have returned the value first and
      the key second.
      
      If the client was using RESP2, it was getting them out of order, and if
      the client was in RESP3, it was getting a map of value => key.
      This was happening regardless of the Lua script using redis.setresp(3)
      or not.
      
      This also affects a case where the script was returning a map which it got
      from from redis by doing something like: redis.setresp(3); return redis.call()
      
      This fix is a breaking change for redis 6.0 users who happened to rely
      on the wrong order (either ones that used redis.setresp(3), or ones that
      returned a map explicitly).
      
      This commit also includes other two changes in the tests:
      1. The test suite now handles RESP3 maps as dicts rather than nested
         lists
      2. Remove some redundant (duplicate) tests from tracking.tcl
      
      (cherry picked from commit 2017407b)
      ec56906b
    • Oran Agra's avatar
      Handle output buffer limits for Module blocked clients (#8141) · ec74ae7e
      Oran Agra authored
      Module blocked clients cache the response in a temporary client,
      the reply list in this client would be affected by the recent fix
      in #7202, but when the reply is later copied into the real client,
      it would have bypassed all the checks for output buffer limit, which
      would have resulted in both: responding with a partial response to
      the client, and also not disconnecting it at all.
      
      (cherry picked from commit 48efc25f)
      ec74ae7e
    • Wang Yuan's avatar
      Backup keys to slots map and restore when fail to sync if diskless-load type... · a60ed4a5
      Wang Yuan authored
      
      Backup keys to slots map and restore when fail to sync if diskless-load type is swapdb in cluster mode (#8108)
      
      When replica diskless-load type is swapdb in cluster mode, we didn't backup
      keys to slots map, so we will lose keys to slots map if fail to sync.
      Now we backup keys to slots map at first, and restore it properly when fail.
      
      This commit includes a refactory/cleanup of the backups mechanism (moving it to db.c and re-structuring it a bit).
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit b55a827e)
      a60ed4a5
    • guybe7's avatar
      EXISTS should not alter LRU, OBJECT should not reveal expired keys on replica (#8016) · 4b37eb13
      guybe7 authored
      The bug was introduced by #5021 which only attempted avoid EXIST on an
      already expired key from returning 1 on a replica.
      
      Before that commit, dbExists was used instead of
      lookupKeyRead (which had an undesired effect to "touch" the LRU/LFU)
      
      Other than that, this commit fixes OBJECT to also come empty handed on
      expired keys in replica.
      
      And DEBUG DIGEST-VALUE to behave like DEBUG OBJECT (get the data from
      the key regardless of it's expired state)
      
      (cherry picked from commit f8ae9917)
      4b37eb13
    • Wang Yuan's avatar
      Disable rehash when redis has child process (#8007) · 3a13c654
      Wang Yuan authored
      In redisFork(), we don't set child pid, so updateDictResizePolicy()
      doesn't take effect, that isn't friendly for copy-on-write.
      
      The bug was introduced this in redis 6.0: 56258c6b
      
      (cherry picked from commit 89c78a98)
      3a13c654
  5. 27 Oct, 2020 21 commits
    • Oran Agra's avatar
      Attempt to fix sporadic test failures due to wait_for_log_messages (#7955) · de0919cd
      Oran Agra authored
      The tests sometimes fail to find a log message.
      Recently i added a print that shows the log files that are searched
      and it shows that the message was in deed there.
      The only reason i can't think of for this seach to fail, is we we
      happened to read an incomplete line, which didn't match our pattern and
      then on the next iteration we would continue reading from the line after
      it.
      
      The fix is to always re-evaluation the previous line.
      
      (cherry picked from commit 4e2e5be2)
      de0919cd
    • Zach Fewtrell's avatar
      fix invalid 'failover' identifier in cluster slave selection test (#7942) · 3988e32f
      Zach Fewtrell authored
      
      (cherry picked from commit ebfa7699)
      3988e32f
    • Qu Chen's avatar
      WATCH no longer ignores keys which have expired for MULTI/EXEC. (#7920) · cebc1f26
      Qu Chen authored
      This wrong behavior was backed by a test, and also documentation, and dates back to 2010.
      But it makes no sense to anyone involved so it was decided to change that.
      
      Note that 20eeddfb (invalidate watch on expire on access) was released in 6.0 RC2
      and 2d1968f8 released in in 6.0.0 GA (invalidate watch when key is evicted).
      both of which do similar changes.
      
      (cherry picked from commit 556acefe)
      cebc1f26
    • Oran Agra's avatar
      improve verbose logging on failed test. print log file lines (#7938) · 56d8ad93
      Oran Agra authored
      
      (cherry picked from commit c96ece9f)
      56d8ad93
    • Yossi Gottlieb's avatar
      Add a --no-latency tests flag. (#7939) · 0103dc09
      Yossi Gottlieb authored
      Useful for running tests on systems which may be way slower than usual.
      
      (cherry picked from commit 843a13e8)
      0103dc09
    • Yossi Gottlieb's avatar
      Fix tests failure on busybox systems. (#7916) · 79e6ab31
      Yossi Gottlieb authored
      
      (cherry picked from commit ef92f507)
      79e6ab31
    • Yossi Gottlieb's avatar
      Modules: fix RM_GetCommandKeys API. (#7901) · 9c475272
      Yossi Gottlieb authored
      This cleans up and simplifies the API by passing the command name as the
      first argument. Previously the command name was specified explicitly,
      but was still included in the argv.
      
      (cherry picked from commit 056a43e1)
      9c475272
    • Meir Shpilraien (Spielrein)'s avatar
      Add Module API for version and compatibility checks (#7865) · 6f2c894d
      Meir Shpilraien (Spielrein) authored
      
      
      * Introduce a new API's: RM_GetContextFlagsAll, and
      RM_GetKeyspaceNotificationFlagsAll that will return the
      full flags mask of each feature. The module writer can
      check base on this value if the Flags he needs are
      supported or not.
      
      * For each flag, introduce a new value on redismodule.h,
      this value represents the LAST value and should be there
      as a reminder to update it when a new value is added,
      also it will be used in the code to calculate the full
      flags mask (assuming flags are incrementally increasing).
      In addition, stated that the module writer should not use
      the LAST flag directly and he should use the GetFlagAll API's.
      
      * Introduce a new API: RM_IsSubEventSupported, that returns for a given
      event and subevent, whether or not the subevent supported.
      
      * Introduce a new macro RMAPI_FUNC_SUPPORTED(func) that returns whether
      or not a function API is supported by comparing it to NULL.
      
      * Introduce a new API: int RM_GetServerVersion();, that will return the
      current Redis version in the format 0x00MMmmpp; e.g. 0x00060008;
      
      * Changed unstable version from 999.999.999 to 255.255.255
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      Co-authored-by: default avatarYossi Gottlieb <yossigo@gmail.com>
      (cherry picked from commit adc3183c)
      6f2c894d
    • Yossi Gottlieb's avatar
      Module API: Add RM_GetClientCertificate(). (#7866) · 4147a220
      Yossi Gottlieb authored
      This API function makes it possible to retrieve the X.509 certificate
      used by clients to authenticate TLS connections.
      
      (cherry picked from commit 0aec98dc)
      4147a220
    • Yossi Gottlieb's avatar
      Modules: Add RM_GetDetachedThreadSafeContext(). (#7886) · 28d1fe67
      Yossi Gottlieb authored
      The main motivation here is to provide a way for modules to create a
      single, global context that can be used for logging.
      
      Currently, it is possible to obtain a thread-safe context that is not
      attached to any blocked client by using `RM_GetThreadSafeContext`.
      However, the attached context is not linked to the module identity so
      log messages produced are not tagged with the module name.
      
      Ideally we'd fix this in `RM_GetThreadSafeContext` itself but as it
      doesn't accept the current context as an argument there's no way to do
      that in a backwards compatible manner.
      
      (cherry picked from commit 907da058)
      28d1fe67
    • Yossi Gottlieb's avatar
      Modules: add RM_GetCommandKeys(). · 116a2042
      Yossi Gottlieb authored
      This is essentially the same as calling COMMAND GETKEYS but provides a
      more efficient interface that can be used in every context (i.e. not a
      Redis command).
      
      (cherry picked from commit 7d117d75)
      116a2042
    • Madelyn Olson's avatar
      Fixed excessive categories being displayed from acls (#7889) · e7c8002b
      Madelyn Olson authored
      
      (cherry picked from commit 2127f7c8)
      e7c8002b
    • Oran Agra's avatar
      Allow blocked XREAD on a cluster replica (#7881) · bab83457
      Oran Agra authored
      I suppose that it was overlooked, since till recently none of the blocked commands were readonly.
      
      other changes:
      - add test for the above.
      - add better support for additional (and deferring) clients for
        cluster tests
      - improve a test which left the client in MULTI state.
      
      (cherry picked from commit 216c1106)
      bab83457
    • Oran Agra's avatar
      memory reporting of clients argv (#7874) · 76f3a63d
      Oran Agra authored
      track and report memory used by clients argv.
      this is very usaful in case clients started sending a command and didn't
      complete it. in which case the first args of the command are already
      trimmed from the query buffer.
      
      in an effort to avoid cache misses and overheads while keeping track of
      these, i avoid calling sdsZmallocSize and instead use the sdslen /
      bulk-len which can at least give some insight into the problem.
      
      This memory is now added to the total clients memory usage, as well as
      the client list.
      
      (cherry picked from commit bea40e6a)
      76f3a63d
    • Oran Agra's avatar
      Fix crash in script timeout during AOF loading (#7870) · c80f6219
      Oran Agra authored
      
      (cherry picked from commit dc803d25)
      c80f6219
    • nitaicaro's avatar
      Fixed Tracking test “The other connection is able to get invalidations” (#7871) · a7b95b7c
      nitaicaro authored
      
      
      PROBLEM:
      
      [$rd1 read] reads invalidation messages one by one, so it's never going to see the second invalidation message produced after INCR b, whether or not it exists. Adding another read will block incase no invalidation message is produced.
      
      FIX:
      
      We switch the order of "INCR a" and "INCR b" - now "INCR b" comes first. We still only read the first invalidation message produces. If an invalidation message is wrongly produces for b - then it will be produced before that of a, since "INCR b" comes before "INCR a".
      Co-authored-by: default avatarNitai Caro <caronita@amazon.com>
      (cherry picked from commit 8fb89a57)
      a7b95b7c
    • Oran Agra's avatar
      Fix new obuf-limits tests to work with TLS (#7848) · 120c6b43
      Oran Agra authored
      Also stabilize new shutdown tests on slow machines (valgrind)
      
      (cherry picked from commit 8aa083bd)
      120c6b43
    • Wang Yuan's avatar
      Don't write replies if close the client ASAP (#7202) · 757ad7cd
      Wang Yuan authored
      
      
      Before this commit, we would have continued to add replies to the reply buffer even if client
      output buffer limit is reached, so the used memory would keep increasing over the configured limit.
      What's more, we shouldn’t write any reply to the client if it is set 'CLIENT_CLOSE_ASAP' flag
      because that doesn't conform to its definition and we will close all clients flagged with
      'CLIENT_CLOSE_ASAP' in ‘beforeSleep’.
      
      Because of code execution order, before this, we may firstly write to part of the replies to
      the socket before disconnecting it, but in fact, we may can’t send the full replies to clients
      since OS socket buffer is limited. But this unexpected behavior makes some commands work well,
      for instance ACL DELUSER, if the client deletes the current user, we need to send reply to client
      and close the connection, but before, we close the client firstly and write the reply to reply
      buffer. secondly, we shouldn't do this despite the fact it works well in most cases.
      
      We add a flag 'CLIENT_CLOSE_AFTER_COMMAND' to mark clients, this flag means we will close the
      client after executing commands and send all entire replies, so that we can write replies to
      reply buffer during executing commands, send replies to clients, and close them later.
      
      We also fix some implicit problems. If client output buffer limit is enforced in 'multi/exec',
      all commands will be executed completely in redis and clients will not read any reply instead of
      partial replies. Even more, if the client executes 'ACL deluser' the using user in 'multi/exec',
      it will not read the replies after 'ACL deluser' just like before executing 'client kill' itself
      in 'multi/exec'.
      
      We added some tests for output buffer limit breach during multi-exec and using a pipeline of
      many small commands rather than one with big response.
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit 57709c4b)
      757ad7cd
    • Wen Hui's avatar
      Add Swapdb Module Event (#7804) · 88441019
      Wen Hui authored
      
      (cherry picked from commit dfe9714c)
      88441019
    • Wang Yuan's avatar
      Remove tmp rdb file in background thread (#7762) · 0bdddd3c
      Wang Yuan authored
      We're already using bg_unlink in several places to delete the rdb file in the background,
      and avoid paying the cost of the deletion from our main thread.
      This commit uses bg_unlink to remove the temporary rdb file in the background too.
      
      However, in case we delete that rdb file just before exiting, we don't actually wait for the
      background thread or the main thread to delete it, and just let the OS clean up after us.
      i.e. we open the file, unlink it and exit with the fd still open.
      
      Furthermore, rdbRemoveTempFile can be called from a thread and was using snprintf which is
      not async-signal-safe, we now use ll2string instead.
      
      (cherry picked from commit b002d2b4)
      0bdddd3c
    • WuYunlong's avatar
      Clarify help text of tcl scripts. (#7798) · 405f041e
      WuYunlong authored
      Before this commit, following command did not show --tls option:
      ./runtest-cluster --help
      ./runtest-sentinel --help
      
      (cherry picked from commit 98c8ac0d)
      405f041e