9406 Commits

Author SHA1 Message Date
Yossi Gottlieb
2a2d5a7a1f 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 7e5a6313f0add995c723351532d994118e3e8a6d)
2021-01-12 16:25:37 +02:00
Wang Yuan
a60ed4a599 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 b55a827ea2e19bd6cd48f216e8e6caa34299f9b9)
2021-01-12 16:25:37 +02:00
Wang Yuan
5ed6662145 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 c85bf2352d2a3dd04872124d33066403b114a7e7)
2021-01-12 16:25:37 +02:00
Oran Agra
f885e364ba 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 e6fa47380a5274119ed37c7a5ea7455d4b7dbdcc)
2021-01-12 16:25:37 +02:00
Oran Agra
3ac666b3e6 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 61954951edbda670bfbae8be0147daa64df95f26)
2021-01-12 16:25:37 +02:00
guybe7
4b37eb13dc 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 f8ae991717f10c837c1a76b2954dae56ecb0e6bc)
2021-01-12 16:25:37 +02:00
Wang Yuan
3a13c654e6 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: 56258c6

(cherry picked from commit 89c78a980807aa1de0a6d0ccde6042450333a783)
2021-01-12 16:25:37 +02:00
Oran Agra
25214bd7dc Redis 6.0.9. 2020-10-27 09:12:01 +02:00
Yossi Gottlieb
3cc673bdd8 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 9824fe3e392caa04dc1b4071886e9ac402dd6d95)
2020-10-27 09:12:01 +02:00
Oran Agra
de0919cd62 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 4e2e5be201439cae4c0a03cfc8b6a60be4bff625)
2020-10-27 09:12:01 +02:00
David CARLIER
5aa0fef2ce cpu affinity: DragonFlyBSD support (#7956)
(cherry picked from commit 27f4c212f377dfbe1a60fb96635ae16bc405b959)
2020-10-27 09:12:01 +02:00
Zach Fewtrell
3988e32f41 fix invalid 'failover' identifier in cluster slave selection test (#7942)
(cherry picked from commit ebfa7699252b858af57cdd5388c5bd6d7439a021)
2020-10-27 09:12:01 +02:00
WuYunlong
6f16e52a6d 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 e05a7df7f942a2e17dee3e0e3d67d80e8d1d2e6e)
2020-10-27 09:12:01 +02:00
Wen Hui
c6c2de9567 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 0f370f9b667fab4bede084f1b8b47c93f0d56069)
2020-10-27 09:12:01 +02:00
Qu Chen
cebc1f2696 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 20eeddf (invalidate watch on expire on access) was released in 6.0 RC2
and 2d1968f released in in 6.0.0 GA (invalidate watch when key is evicted).
both of which do similar changes.

(cherry picked from commit 556acefe7556443b6d1741d804add92047bf4a8b)
2020-10-27 09:12:01 +02:00
Oran Agra
56d8ad932d improve verbose logging on failed test. print log file lines (#7938)
(cherry picked from commit c96ece9f5e7b80d65ca4d1a2b801effe68425c90)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
0103dc09d2 Add a --no-latency tests flag. (#7939)
Useful for running tests on systems which may be way slower than usual.

(cherry picked from commit 843a13e88f3544e936ead06a9d05af28eeefd5a1)
2020-10-27 09:12:01 +02:00
filipe oliveira
71c1427a1b 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 6cf23d6610677d38e4892e02649fc2de7095274b)
2020-10-27 09:12:01 +02:00
Oran Agra
30bb0dd595 fix 32bit build warnings (#7926)
(cherry picked from commit a425e1d26df02ac5ce0fc9a0c679b99d72550009)
2020-10-27 09:12:01 +02:00
Wen Hui
99f39d32ab 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 04a0af9085ed91eace8af94f71a07b651a1af454)
2020-10-27 09:12:01 +02:00
Oran Agra
851ec530b4 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 457b7073b5d512c10aaeeb0dbf1763f0cb10462c)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
79e6ab31d8 Fix tests failure on busybox systems. (#7916)
(cherry picked from commit ef92f507dd0c402a916c16435e7f3f92598b7242)
2020-10-27 09:12:01 +02:00
Oran Agra
b20af834ff 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 19418b6b28b70818e67c50bbdfad8568da7c3458)
2020-10-27 09:12:01 +02:00
Wang Yuan
1453277294 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 aaacb8c955779a76faaa15b7097eef4787a4339f)
2020-10-27 09:12:01 +02:00
guybe7
e4e24460f9 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 addf47dcacec596eb7f6e1500846331d3e13fff4)
2020-10-27 09:12:01 +02:00
Andreas Lind
db9cffe7c2 Support redis-cli -u rediss://... (#7900)
(cherry picked from commit 8b497881f2eda5b028cc2ba0aa17ef204f6a083b)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
9c475272da Modules: fix RM_GetCommandKeys API. (#7901)
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 056a43e1a615080cf9ba405be0538a6a979c821e)
2020-10-27 09:12:01 +02:00
Meir Shpilraien (Spielrein)
6f2c894d69 Add Module API for version and compatibility checks (#7865)
* 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: Oran Agra <oran@redislabs.com>
Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
(cherry picked from commit adc3183cd2b54238424895e4298548df4526f8c3)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
4147a2202e Module API: Add RM_GetClientCertificate(). (#7866)
This API function makes it possible to retrieve the X.509 certificate
used by clients to authenticate TLS connections.

(cherry picked from commit 0aec98dce2acbd280ad8ff4feac631e8afa833b1)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
28d1fe6718 Modules: Add RM_GetDetachedThreadSafeContext(). (#7886)
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 907da0580b57013c9e5c38b27f351597c72e4e25)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
116a2042a7 Modules: add RM_GetCommandKeys().
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 7d117d7591656e947f526f5d5f8a022b88b38ad9)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
945983ac52 Introduce getKeysResult for getKeysFromCommand.
Avoid using a static buffer for short key index responses, and make it
caller's responsibility to stack-allocate a result type. Responses that
don't fit are still allocated on the heap.

(cherry picked from commit 9b7f8ba84b9de1ec846badd45e4004e3cd23f178)
2020-10-27 09:12:01 +02:00
Madelyn Olson
e7c8002b56 Fixed excessive categories being displayed from acls (#7889)
(cherry picked from commit 2127f7c8ebc1d8638eb0c99764f698cebcdb6513)
2020-10-27 09:12:01 +02:00
Oran Agra
86b5e1a72f Add some additional signal info to the crash log (#7891)
- si_code can be very useful info some day.
- a clear indication that redis was killed by an external user

(cherry picked from commit f659d236196ec57b02148031f425cf8864ed77ad)
2020-10-27 09:12:01 +02:00
Oran Agra
bab834574c Allow blocked XREAD on a cluster replica (#7881)
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 216c1106099f7c66c991a5a811c8fbacbb0ab17c)
2020-10-27 09:12:01 +02:00
Oran Agra
76f3a63de1 memory reporting of clients argv (#7874)
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 bea40e6a41e31a52e9e6efee77ea5a4bd873b759)
2020-10-27 09:12:01 +02:00
DvirDukhan
93b4c6b31e redis-cli add control on raw format line delimiter (#7841)
Adding -D option for redis-cli to control newline between command
responses in raw mode.

Also removing cleanup code before calling exit, just in order
to avoid adding more adding more cleanup code (redis doesn't
bother to release allocations before exit anyway)

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 6418d767e86b6fd98ba79253108b2e53966a04b3)
2020-10-27 09:12:01 +02:00
Oran Agra
12055ed8c2 Include internal sds fragmentation in MEMORY reporting (#7864)
The MEMORY command is used for debugging memory usage, so it should include internal
fragmentation, same as used_memory

(cherry picked from commit eb6241a3dd3ee27610922e6bccd44603a9b845e8)
2020-10-27 09:12:01 +02:00
Oran Agra
c80f6219d5 Fix crash in script timeout during AOF loading (#7870)
(cherry picked from commit dc803d25a6f5eb8c41b6afed913cbcd769e4b377)
2020-10-27 09:12:01 +02:00
Rafi Einstein
801c7307fb Makefile: enable program suffixes via PROG_SUFFIX (#7868)
(cherry picked from commit b8187d39fb3eb1cbd2b0346a1e39b68f6ab3029c)
2020-10-27 09:12:01 +02:00
nitaicaro
a7b95b7c72 Fixed Tracking test “The other connection is able to get invalidations” (#7871)
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: Nitai Caro <caronita@amazon.com>
(cherry picked from commit 8fb89a572892e600146bd933c4f8f99d46a519c7)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
919580a228 Modules: expose real client on conn events.
When REDISMODULE_EVENT_CLIENT_CHANGE events are delivered, modules may
want to mutate the client state (e.g. perform authentication).

This change links the module context with the real client rather than a
fake client for these events.

(cherry picked from commit 67b43f75e23ba7a3915bc87e7edaa306fd1eee65)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
e83d6b0cfa Module API: Fail ineffective auth calls.
The client pointed to by the module context may in some cases be a fake
client. RM_Authenticate*() calls in this case would be ineffective but
appear to succeed, and this change fails them to make it easier to catch
such cases.

(cherry picked from commit cfccfbd6f4ad23c1a9feb44ebb91da9cd2a09734)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
cb070accb4 TLS: Do not require CA config if not used. (#7862)
The tls-ca-cert or tls-ca-cert-dir configuration parameters are only
used when Redis needs to authenticate peer certificates, in one of these
scenarios:

1. Incoming clients or replicas, with `tls-auth-clients` enabled.
2. A replica authenticating the master's peer certificate.
3. Cluster nodes authenticating other nodes when establishing the bus
   protocol connection.

(cherry picked from commit 1591e3479d46e7e21a98ae685fab2ccab076d094)
2020-10-27 09:12:01 +02:00
Oran Agra
9ce6fc7322 warning: comparison between signed and unsigned integer in 32bit build (#7838)
(cherry picked from commit ef33252c434ff25991ff75e2c7e4646bc9ad5ff7)
2020-10-27 09:12:01 +02:00
David CARLIER
a7b9cfbe98 Add support for Haiku OS (#7435)
(cherry picked from commit f971a5d8ed58547f01325611c0189745a904c9cc)
2020-10-27 09:12:01 +02:00
Gavrie Philipson
219bab2d85 Fix typo in module API docs (#7861)
(cherry picked from commit 49383a4af74bbcca1c194fca458198412ff1820c)
2020-10-27 09:12:01 +02:00
David CARLIER
d51bebd4d7 getting rss size implementation for netbsd (#7293)
(cherry picked from commit ce8bfc56ad002a3b276249d62038fae4488eae61)
2020-10-27 09:12:01 +02:00
Oran Agra
120c6b43e1 Fix new obuf-limits tests to work with TLS (#7848)
Also stabilize new shutdown tests on slow machines (valgrind)

(cherry picked from commit 8aa083bd283963f60c46eb6156e7aacca3c853c3)
2020-10-27 09:12:01 +02:00
caozb
63075b81e6 ignore slaveof no one in redis.conf (#7842)
when slaveof config is "no one", reset any pre-existing config and resume.

also solve a memory leak if slaveof appears twice.
and fail loading if port number is out of range or not an integer.

Co-authored-by: caozhengbin <caozb@yidingyun.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit a295770e32b4bd71ff560c5ec7bc5c0ad12bf068)
2020-10-27 09:12:01 +02:00