9387 Commits

Author SHA1 Message Date
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
Wang Yuan
9418083770 Don't support Gopher if enable io threads to read queries (#7851)
There's currently an issue with IO threads and gopher (issuing lookupKey from within the thread).
simply fix is to just not support it for now.

(cherry picked from commit c9f00bcce2ce7a59a815642674a12c940bbe2207)
2020-10-27 09:12:01 +02:00
Wang Yuan
5d1ac2df64 Set 'loading' and 'shutdown_asap' to volatile sig_atomic_t type (#7845)
We may access and modify these two variables in signal handler function,
to guarantee them async-signal-safe, so we should set them to volatile
sig_atomic_t type.

It doesn't look like this could have caused any real issue, and it seems that
signals are handled in main thread on most platforms. But we want to follow C
and POSIX standard in signal handler function.

(cherry picked from commit f1863a1fe760610cebfd1c121623a3c12a79d600)
2020-10-27 09:12:01 +02:00
Uri Shachar
90555566ed Fix config rewrite file handling to make it really atomic (#7824)
Make sure we handle short writes correctly, sync to disk after writing  and use
rename to make sure the replacement is actually atomic.
In any case of failure old configuration will remain in place.

Also, add some additional logging to make it easier to diagnose rewrite problems.

(cherry picked from commit c30bd02c9d251c63b49ee77a6fd456fb82ff1382)
2020-10-27 09:12:01 +02:00
WuYunlong
bb7e00b699 Add fsync to readSyncBulkPayload(). (#7839)
We should sync temp DB file before renaming as rdb_fsync_range does not use
flag `SYNC_FILE_RANGE_WAIT_AFTER`.

Refer to `Linux Programmer's Manual`:
SYNC_FILE_RANGE_WAIT_AFTER
    Wait upon write-out of all pages in the range after performing any write.

(cherry picked from commit 0d62caab2113fc12077aadd469e80dd19ca78db2)
2020-10-27 09:12:01 +02:00
Wen Hui
faa431c98d rdb.c: handle fclose error case differently to avoid double fclose (#7307)
When fclose would fail, the previous implementation would have attempted to do fclose again
this can in theory lead to segfault.

other changes:
check for non-zero return value as failure rather than a specific error code.
this doesn't fix a real bug, just a minor cleanup.

(cherry picked from commit 323029baa6958781ffae5da331dfc918d66a7117)
2020-10-27 09:12:01 +02:00
Wang Yuan
757ad7cdf2 Don't write replies if close the client ASAP (#7202)
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: Oran Agra <oran@redislabs.com>
(cherry picked from commit 57709c4bc663ddcb9313777c551a92dabf07095e)
2020-10-27 09:12:01 +02:00
Guy Korland
31491202aa Fix RedisModule_HashGet examples (#6697)
(cherry picked from commit b464afb9e2c16277a5cf62cf1290c8e2ad4b0aa1)
2020-10-27 09:12:01 +02:00
Oran Agra
26c1c60187 fix recently broken TLS build error, and add coverage for CI (#7833)
(cherry picked from commit a735bf5c2a8a3d3d18c3a7e9cc728768c2086e89)
2020-10-27 09:12:01 +02:00
David CARLIER
2ccbba650c Further NetBSD update and build fixes. (#7831)
mainly backtrace and register dump support.

(cherry picked from commit c3edaa79413bdf908abb56f088217c01f347ecff)
2020-10-27 09:12:01 +02:00
WuYunlong
c73406c2bd Fix redundancy use of semicolon in do-while macros in ziplist.c. (#7832)
this is very dangerous bug, but it looks like it didn't cause any harm.

(cherry picked from commit 63cd4d4e2044059c44a65e2ce424b9ce1fcdbd39)
2020-10-27 09:12:01 +02:00
yixiang
c1423c016c Fix connGetSocketError usage (#7811)
(cherry picked from commit b96c3595af817721fc838746b859249bf9cf3aaf)
2020-10-27 09:12:01 +02:00
Oran Agra
ecf51b0b3d RM_GetContextFlags - document missing flags (#7821)
(cherry picked from commit 26ca04a8a2d46ee243e97cc80535c7c1e28d5c56)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
9d0388a043 Fix occasional hangs on replication reconnection. (#7830)
This happens only on diskless replicas when attempting to reconnect after 
failing to load an RDB file. It is more likely to occur with larger datasets.

After reconnection is initiated, replicationEmptyDbCallback() may get called 
and try to write to an unconnected socket. This triggered another issue where
the connection is put into an error state and the connect handler never gets
called. The problem is a regression introduced by commit c17e597.

(cherry picked from commit 1980f639b161f46da2944d60f1c2facaf547dc1a)
2020-10-27 09:12:01 +02:00
Ariel Shtul
6a4da4958e Fix redis-check-rdb support for modules aux data (#7826)
redis-check-rdb was unable to parse rdb files containing module aux data.

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 63a05dde462c1be4bd74c32630eca6e794ae440a)
2020-10-27 09:12:01 +02:00
Wen Hui
e8f772efff refactor rewriteStreamObject code for adding missing streamIteratorStop call (#7829)
This commit adds streamIteratorStop call in rewriteStreamObject function in some of the return statement. Although currently this will not cause memory leak since stream id is only 16 bytes long.


(cherry picked from commit 23b50bccccf4efac4a1672a332e470a82b7bd514)
2020-10-27 09:12:01 +02:00
WuYunlong
59866fcd30 Make IO threads killable so that they can be canceled at any time.
This commit can be cherry picked to 6.0 only if we also cherry pick f866023.

(cherry picked from commit c37acb82aa4b1c3317f9bc1b05fc5ab8af23ba00)
2020-10-27 09:12:01 +02:00
WuYunlong
4832cf4fd6 Make main thread killable so that it can be canceled at any time.
Refine comment of makeThreadKillable().

This commit can be backported to 5.0, only if we also backport 8b70cb0.

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 647cac5bb469171a5b97eade276335ab9c552edc)
2020-10-27 09:12:01 +02:00
Oran Agra
fd610ae025 RM_GetContextFlags provides indication that we're in a fork child (#7783)
(cherry picked from commit 2458e5481434bb9c7b99813a449f6cbdf521c028)
2020-10-27 09:12:01 +02:00
Wen Hui
88441019a5 Add Swapdb Module Event (#7804)
(cherry picked from commit dfe9714c867ba69f9ace30c9a9270ae95a111556)
2020-10-27 09:12:01 +02:00