9430 Commits

Author SHA1 Message Date
Meir Shpilraien (Spielrein)
58c00320e3 Moved RMAPI_FUNC_SUPPORTED location such that it will be visible to modules (#8037)
The RMAPI_FUNC_SUPPORTED was defined in the wrong place on redismodule.h
and was not visible to modules.

(cherry picked from commit 560d2dc0081bc35b81b6a64d25c4077fa2e69ad9)
2021-01-12 16:25:37 +02:00
David CARLIER
010223a7f4 raspberry build fix. (#8095)
__ILP32__ is 32 bits ABI and does not imply x86, this patch resolves this. 

(cherry picked from commit 6e44f74dbc1e18383e53c6e86aa72e327c8f47c8)
2021-01-12 16:25:37 +02:00
Yossi Gottlieb
1167967014 Fix crash log output on ARM. (#8020)
(cherry picked from commit 43c07a877cd67ede008c51d227723cfc6c7fd896)
2021-01-12 16:25:37 +02:00
Oran Agra
df32c5a812 Fix cluster access to unaligned memory (SIGBUS on old ARM) (#7958)
Turns out this was broken since version 4.0 when we added sds size
classes.
The cluster code uses sds for the receive buffer, and then casts it to a
struct and accesses a 64 bit variable.
This commit replaces the use of sds with a simple reallocated buffer.

(cherry picked from commit b71d06c269878887eed85b63a731c3d4ad7a8b12)
2021-01-12 16:25:37 +02:00
Oran Agra
39ac9ba73f prevent client tracking from causing feedback loop in performEvictions (#8100)
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 b640e2944e42759412ac67228cf64c43dfbed9c3)
2021-01-12 16:25:37 +02:00
Madelyn Olson
b3f7166eb5 White space tweaks and skip categories already applied
(cherry picked from commit b9b8ef113088c56808c47dd4d1c0371bc850198c)
2021-01-12 16:25:37 +02:00
Madelyn Olson
a3806ed216 Further improved ACL algorithm for picking categories
(cherry picked from commit 2eae7756fd77824806b7d5c602c7587b0f4e34c7)
2021-01-12 16:25:37 +02:00
Yang Bodong
356e8f1afb Swapdb should make transaction fail if there is any client watching keys (#8239)
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: Oran Agra <oran@redislabs.com>
(cherry picked from commit f571f8467cecb69a1c7c6810a445addfb802d85a)
2021-01-12 16:25:37 +02:00
Itamar Haber
eeede65172 Adds 'use-memory' to GEORADIUS[BYMEMBER] (#8107)
Partial resolution for #6860, item 7

(cherry picked from commit 872a6c09e16eab903205d85890f59aa028a490d2)
2021-01-12 16:25:37 +02:00
Oran Agra
426a976a29 fix valgrind warning created by recent pidfile fix (#8235)
This isn't a leak, just an warning due to unreachable
allocation on the fork child.
Problem created by 4192faa

(cherry picked from commit 997c2dc7ec652ac49a6f1a3a5bb79627aff1a545)
2021-01-12 16:25:37 +02:00
Meir Shpilraien (Spielrein)
b0a00784da Fix issue where fork process deletes the parent pidfile (#8231)
Turns out that when the fork child crashes, the crash log was deleting
the pidfile from the disk (although the parent is still running.

Now we set the pidfile of the fork process to NULL so the fork process
will never deletes it.

(cherry picked from commit 4192faa9821aa4c19be3bd245d8366a1bc1b0332)
2021-01-12 16:25:37 +02:00
Wen Hui
2355a7056f Sentinel: add missing calls for sentinelflushconfig when config master at runtime (#8229)
(cherry picked from commit 84a2084d0734052ed05df5b8d67f26d62c02ec67)
2021-01-12 16:25:37 +02:00
Wen Hui
a93d343902 fix memory leak in processInlineBuffer error handling code (#8295)
This code path is normally executed only when v6.0 and above replicates from v2.4

(cherry picked from commit 138ecf1de7e62c060365ee339c1599ac1b6a3c03)
2021-01-12 16:25:37 +02:00
huangzhw
277f92284c sdscatfmt call sdsMakeRoomFor, asked for more space than intended (#8286)
instead of asking for the extra new space it wanted, it asked to grow the
string by the size it already has too.
i.e. a string of 1000 bytes, needing to grow by 10 bytes, would have been
asking for an **additional** 1010 bytes.

(cherry picked from commit f2bde2268a5420ed2d481fc0141cb73de0b1f200)
2021-01-12 16:25:37 +02:00
huangzhw
02fe0138fe sort Command lookupKeyRead and lookupKeyWrite are used on the opposite (#8283)
This is a recent problem, introduced by 9b2a426 (redis 6.0)

The implications are:
The sole difference between LookupKeyRead and LookupKeyWrite is for command
executed on a replica, which are not received from its master client. (for the master,
and for the master client on the replica, these two functions behave the same)!

Since SORT is a write command, this bug only implicates a writable-replica.
And these are its implications:

- SORT STORE will behave as it did before the above mentioned commit (like before
  redis 6.0). on a writable-replica an already logically expired the key would have
  appeared missing. (store dest key would be deleted, instead of being populated
  with the data from the already logically expired key)
- SORT (the non store variant, which in theory could have been executed on
  read-only-replica if it weren't for the write flag), will (in redis 6.0) have a new bug
  and return the data from the already logically expired key instead of empty response.

(cherry picked from commit 6230ba081109beaf367d8fe3552bc848dc3896f4)
2021-01-12 16:25:37 +02:00
Oran Agra
1ba383e8e7 Fix rdb checksum / crc64 on bigendian (#8270)
Turns out the RDB checksum in Redis 6.0 on bigendian is broken.
It always returned 0, so the RDB files are generated as if checksum is
disabled, and will be loaded ok on littleendian, and on bigendian.
But it'll not be able to load RDB files generated on littleendian or older versions.

Similarly DUMP and RESTORE will work on the same version (0==0),
but will be unable to exchange dump payloads with littleendian or old versions.

(cherry picked from commit a67621f495762dfe09f9a7e28d12b0729a7b0d12)
2021-01-12 16:25:37 +02:00
Oran Agra
ab26f24b18 fix crash in redis-cli after making cluster backup (#8267)
getRDB is "designed" to work in two modes: one for redis-cli --rdb and
one for redis-cli --cluster backup.
in the later case it uses the hiredis connection from the cluster nodes
and it used to free it without nullifying the context, so a later
attempt to free the context would crash.

I suppose the reason it seems to want to free the hiredis context ASAP
is that it wants to disconnect the replica link, so that replication
buffers will not be accumulated.

(cherry picked from commit 93b8b139305a99678528fabc9bf9cc5e9133b5a4)
2021-01-12 16:25:37 +02:00
Oran Agra
5576959fdc Fix wrong order of key/value in Lua map response (#8266)
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 bcde1d978d74f84cb4a66dc8bbd746842217f8b2)
2021-01-12 16:25:37 +02:00
Oran Agra
03e4829239 Crash log would crash half way on commands with no arguments (#8260)
The crash log attempts to print the current client info, and when it
does that it attempts to check if the first argument happens to be a key
but it did so for commands with no arguments too, which caused the crash
log to crash half way and not reach its end.

(cherry picked from commit 318d58192289a471987aa12ca913a3569d4f54d0)
2021-01-12 16:25:37 +02:00
Yossi Gottlieb
14305a876b Fix crashes with io-threads-do-reads enabled. (#8230)
Normally IO threads should simply read data from the socket into the
buffer and attempt to parse it.

If a protocol error is detected, a reply is generated which may result
with installing a write handler which is not thread safe. This fix
delays that until the client is processed back in the main thread.

Fixes #8220

(cherry picked from commit 53f926dd9068a62795abc2e01dabac5be0ccbada)
2021-01-12 16:25:37 +02:00
George Prekas
fecbb48519 Add check for the MADV_FREE/fork arm64 Linux kernel bug (#8224)
Older arm64 Linux kernels have a bug that could lead to data corruption during
background save under the following scenario:

1) jemalloc uses MADV_FREE on a page,
2) jemalloc reuses and writes the page,
3) Redis forks the background save process, and
4) Linux performs page reclamation.

Under these conditions, Linux will reclaim the page wrongfully and the
background save process will read zeros when it tries to read the page.

The bug has been fixed in Linux with commit:
ff1712f953e27f0b0718762ec17d0adb15c9fd0b ("arm64: pgtable: Ensure dirty bit is
preserved across pte_wrprotect()")

This Commit adds an ignore-warnings config, when not found, redis will
print a warning and exit on startup (default behavior).

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 75bbf56d37d1134cc9c4f36900a4a623604776a5)

in 6.0 this warning is ignored by default in order to avoid adding
regression, specifically for deployments that don't need persistence or
replication
2021-01-12 16:25:37 +02:00
Qu Chen
01db11ce8d Not over-allocate client query buffer when reading large objects. (#5954)
In response to large client query buffer optimization introduced in 1898e6c. The calculation of the amount of
remaining bytes we need to write to the query buffer was calculated wrong, as a result we are unnecessarily
growing the client query buffer by sdslen(c->querybuf) always. This fix corrects that behavior.

Please note the previous behavior prior to the before-mentioned change was correctly calculating the remaining
additional bytes, and this change makes that calculate to be consistent.

Useful context, the argument of size `ll` starts at qb_pos (which is now the beginning of the sds), but much of it
may have already been read from the socket, so we only need to grow the sds for the remainder of it.

(cherry picked from commit b8c98337cd8f90064085a7af4b416f6fb3e80e1c)
2021-01-12 16:25:37 +02:00
Oran Agra
fb0783c710 Handle output buffer limits for Module blocked clients (#8141)
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 11e0c4739b40c23a70aff5287e67e8ef6418bb2a)
2021-01-12 16:25:37 +02:00
Yossi Gottlieb
0b5312a4a6 Fix setproctitle related crashes. (#8150)
Makes spt_init more careful with assumptions about what memory regions
may be overwritten. It will now only consider a contiguous block of argv
and envp elements and mind any gaps.

(cherry picked from commit 9f272197ea0d8e59f565782a6a1b420b9b94266d)
2021-01-12 16:25:37 +02:00
Yossi Gottlieb
e2f6b95926 Fix use-after-free issue in spt_copyenv. (#8088)
Seems to have gone unnoticed for a long time, because at least with
glibc it will only be triggered if setenv() was called before spt_init,
which Redis doesn't.

Fixes #8064.

(cherry picked from commit 87f59674b4f24fab3e98d3cb029ad85be5e68266)
2021-01-12 16:25:37 +02:00
Wang Yuan
f5d6057cbb 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: Oran Agra <oran@redislabs.com>
(cherry picked from commit 10712afaf3e7f2ea859622fa5b27c96ee8f478c5)
2021-01-12 16:25:37 +02:00
Wang Yuan
ce6eee028d Reset average ttl when empty databases (#8106)
On FLUSHDB or full sync, reset old average TTL stat.
This Stat is incrementally collected by the master over time when it searches for expired keys. 

(cherry picked from commit b6916ca91c623a892f61cc9d1958c19490eb73ae)
2021-01-12 16:25:37 +02:00
Oran Agra
626b8b2a13 Fix bug with module GIL being released prematurely (#8061)
This is hopefully usually harmles.
The server.ready_keys will usually be empty so the code after releasing
the GIL will soon be done.
The only case where it'll actually process things is when a module
releases a client (or module) blocked on a key, by triggering this NOT
from within a command (e.g. a timer event).

This bug was introduced in redis 6.0.9, see #7903

(cherry picked from commit f5604de4c8962db75a770dafff3b0ac830b6c4d1)
2021-01-12 16:25:37 +02:00
Oran Agra
878d8476e5 Fix oom-score-adj-values range, abs options, and bug when used in config file (#8046)
Fix: When oom-score-adj-values is provided in the config file after
oom-score-adj yes, it'll take an immediate action, before
readOOMScoreAdj was acquired, resulting in an error (out of range score
due to uninitialized value. delay the reaction the real call is made by
main().

Since the values are clamped to -1000..1000, and they're
applied as an offset from the value at startup (which may be -1000), we
need to allow the offsets to reach to +2000 so that a value of +1000 is
achievable in case the value at startup was -1000.

Adding an option for absolute values rather than relative ones.

(cherry picked from commit f08fd95c6686467ecd46116dab150d47563aed1c)
2021-01-12 16:25:37 +02:00
guybe7
02236725af EXISTS should not alter LRU, OBJECT should not reveal expired keys on replica (#8016)
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 168dcb549c3d5253fc69d6150ce98f8eb9ca0c99)
2021-01-12 16:25:37 +02:00
Wang Yuan
bde35e3aaa Disable rehash when redis has child process (#8007)
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: e70fbad

(cherry picked from commit 16e3af9d23bb4791a7571f889aad8f2c85546521)
2021-01-12 16:25:37 +02:00
Oran Agra
984d33e8b6 Redis 6.0.9. 2020-10-27 09:12:01 +02:00
Yossi Gottlieb
77b0060fbe Fix wrong zmalloc_size() assumption. (#7963)
When using a system with no malloc_usable_size(), zmalloc_size() assumed
that the heap allocator always returns blocks that are long-padded.

This may not always be the case, and will result with zmalloc_size()
returning a size that is bigger than allocated. At least in one case
this leads to out of bound write, process crash and a potential security
vulnerability.

Effectively this does not affect the vast majority of users, who use
jemalloc or glibc.

This problem along with a (different) fix was reported by Drew DeVault.

(cherry picked from commit 05a086617dc52d07868604e1a0fa922e5b9ce67c)
2020-10-27 09:12:01 +02:00
Oran Agra
bfe67bd205 Attempt to fix sporadic test failures due to wait_for_log_messages (#7955)
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 35eb8ec6f3f6a2deab49ff70b0e9a8587adfd6de)
2020-10-27 09:12:01 +02:00
David CARLIER
8f7b0343ab cpu affinity: DragonFlyBSD support (#7956)
(cherry picked from commit c1ff07dfbb26ffcc9686af3de5a6778e23ab2ce6)
2020-10-27 09:12:01 +02:00
Zach Fewtrell
67b92eaffe fix invalid 'failover' identifier in cluster slave selection test (#7942)
(cherry picked from commit 0a0ec83e48e374ec2b6184049d5b1499e508d8b9)
2020-10-27 09:12:01 +02:00
WuYunlong
39272f6836 Update rdb_last_bgsave_time_sec in INFO on diskless replication (#7917)
`info Persistence` will include correct (updated) rdb_last_bgsave_time_sec
For diskless bgsave (sockets) too (like a few other persistence info fields).

Refactor code to reduce duplicate code.

(cherry picked from commit 51f36283df29e6969215baf63223653d7cec0059)
2020-10-27 09:12:01 +02:00
Wen Hui
6b4aba30a9 do not add save parameter during config rewrite in sentinel mode (#7945)
Previous code would have added default redis save parameters
to the config file on rewrite, which would have been silently ignored
when the config file is loaded.

The new code avoids adding this, and also actively removes these lines
If added by a previous config rewrite. 

(cherry picked from commit f61435fe8b7907f59cb0f11f28f13db50b9023a5)
2020-10-27 09:12:01 +02:00
Qu Chen
872744d196 WATCH no longer ignores keys which have expired for MULTI/EXEC. (#7920)
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 3b031b1 (invalidate watch on expire on access) was released in 6.0 RC2
and 62a3ec8 released in in 6.0.0 GA (invalidate watch when key is evicted).
both of which do similar changes.

(cherry picked from commit 44bcbed2eed8577e7634e04817c4a75f9b722a62)
2020-10-27 09:12:01 +02:00
Oran Agra
7aec82cdb9 improve verbose logging on failed test. print log file lines (#7938)
(cherry picked from commit 33c59266cc338eb9051d70a7cdf5a4120915f84a)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
deaa71637a Add a --no-latency tests flag. (#7939)
Useful for running tests on systems which may be way slower than usual.

(cherry picked from commit be43c030df2a352c5fa02d70e4dcaa46ece25b2b)
2020-10-27 09:12:01 +02:00
filipe oliveira
0a4aaa631f Fixed bug concerning redis-benchmark non clustered benchmark forcing always the same hash tag {tag} (#7931)
Adding the ":{tag}" only if --cluster is used, so that when used against
a proxy it generates traffic to all shards.

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 128bc0f4951e3c887a0cbe16360adb04fdeeda82)
2020-10-27 09:12:01 +02:00
Oran Agra
edf8894162 fix 32bit build warnings (#7926)
(cherry picked from commit cc231e4882f8b49f4d6524904ac980250642a465)
2020-10-27 09:12:01 +02:00
Wen Hui
4807eeef21 fix double fclose in aofrewrite (#7919)
minor fix for a bug which happen on error handling code
and doesn't look like it could have caused any real harm
(fd number wouldn't have been reused yet)

(cherry picked from commit ee8cb472a781e42ec7b10c6a88d258a3399ca34f)
2020-10-27 09:12:01 +02:00
Oran Agra
c55bc96dc6 INFO report peak memory before eviction (#7894)
In some cases one command added a very big bulk of memory, and this
would be "resolved" by the eviction before the next command.

Seeing an unexplained mass eviction we would wish to
know the highest momentary usage too.

Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
loading.

The fix in clientsCronTrackExpansiveClients is related to #7874

(cherry picked from commit 0de424cab96633a3fc94bcdaec83176eacb080b2)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
c9dcf82020 Fix tests failure on busybox systems. (#7916)
(cherry picked from commit 6a035f5edff0be3b404f1bfb9f07e9373cd63934)
2020-10-27 09:12:01 +02:00
Oran Agra
1ee7b3973b Allow requirepass config to clear the password (#7899)
This is a compatibility issue with redis 5.0 that was introduced by ACL.
Before this commit, setting requirepass to an empty string will result
in a server that needs an empty AUTH, unlike redis 5.0 which would
accept connections without an AUTH.

(cherry picked from commit c7fe6387d92b266581ff313ab6a3b39443747b87)
2020-10-27 09:12:01 +02:00
Wang Yuan
86c8cf42a0 Remove temporary aof and rdb files in a background thread (#7905)
If we fail or stop to rewrite aof, we need to remove temporary aof.
We also remove temporary rdb when replicas abort to receive rdb.
But currently we delete them in main thread, to avoid blocking,
we should use bg_unlink to remove them in a background thread.

Btw, we have already used this way to removed child process temporary rdb.

(cherry picked from commit 5bb220660e6b548daee2a68c81d3e7f4b35e1fcc)
2020-10-27 09:12:01 +02:00
guybe7
371555135f Minor improvements to module blocked on keys (#7903)
- Clarify some documentation comments
- Make sure blocked-on-keys client privdata is accessible
  from withing the timeout callback
- Handle blocked clients in beforeSleep - In case a key
  becomes "ready" outside of processCommand

See #7879 #7880

(cherry picked from commit c816eec8938297e827b0ddd19f9011847bab05c3)
2020-10-27 09:12:01 +02:00
Andreas Lind
2a9f491e0d Support redis-cli -u rediss://... (#7900)
(cherry picked from commit efa784d5f24c60b41edb50d61afc2338864c9f39)
2020-10-27 09:12:01 +02:00