10832 Commits

Author SHA1 Message Date
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
Yossi Gottlieb
c6c0155725 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 a94ddb27fe919d60c598c2403b230b27c6e3a11c)
2020-10-27 09:12:01 +02:00
Meir Shpilraien (Spielrein)
dbf3902481 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 e9c837ad3118f5ea2cb4defb0ab82cbd113733e7)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
02edabc9aa 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 929f1e2ec73c147251d693631a746baaaf5d4127)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
298808cf32 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 e270302cdf06b6a7b38c7dcb59680419b1b589c8)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
4af8059e61 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 9e58b52a19fed12c4e9fbe120ec0d4baf9c2bc28)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
ad1ed7dcd0 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 bf5beab64a196214c3c741d9ef67d0446c6480c3)
2020-10-27 09:12:01 +02:00
Madelyn Olson
ec9b1cca59 Fixed excessive categories being displayed from acls (#7889)
(cherry picked from commit abe416c5f251b7b151440b38829a719c4846b8b8)
2020-10-27 09:12:01 +02:00
Oran Agra
9cf7292ef7 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 38c7c62d2270b4921219953aaabfcdc721154b88)
2020-10-27 09:12:01 +02:00
Oran Agra
6e03b388ce 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 ba61700db24628451212c5875e0ca7e5d83ea743)
2020-10-27 09:12:01 +02:00
Oran Agra
a5302a8c21 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 7481e513f0507d01381a87046d8d1366c718f94e)
2020-10-27 09:12:01 +02:00
DvirDukhan
7a8a268ac4 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 f0f8e9c824b819c8aec996ec8c8851773a6f9432)
2020-10-27 09:12:01 +02:00
Oran Agra
0d7a1d1d37 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 86483e795262c6e2efdffe92c1642a72ef0dd6a0)
2020-10-27 09:12:01 +02:00
Oran Agra
51dd4677c9 Fix crash in script timeout during AOF loading (#7870)
(cherry picked from commit 8cff3e03520bb08cb7dfdbd11f98827a3cb1d3a5)
2020-10-27 09:12:01 +02:00
Rafi Einstein
57027f0c55 Makefile: enable program suffixes via PROG_SUFFIX (#7868)
(cherry picked from commit 2636b760fb062a763ae528800fd998d2913c7cb1)
2020-10-27 09:12:01 +02:00
nitaicaro
e7bae88392 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 94e9b0124e8582912c3771f9828842348490bc38)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
38853fd487 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 4aca4e5f392ad6030150a92a9ef82412072f9622)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
0816b8fadd 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 82866776d0c26f17043f9c1b0f0f5f48660e6848)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
51a6e1e61a 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 3bd9d0cc85d4ef8f4cc2789e9ab27e5557471409)
2020-10-27 09:12:01 +02:00
Oran Agra
c7cae0df77 warning: comparison between signed and unsigned integer in 32bit build (#7838)
(cherry picked from commit c11bda25fd2959523cb1e87af5b366cc451dbd04)
2020-10-27 09:12:01 +02:00
David CARLIER
4da8211063 Add support for Haiku OS (#7435)
(cherry picked from commit d535a5061ccd561d0c132b2e97b56a3bd252fde9)
2020-10-27 09:12:01 +02:00
Gavrie Philipson
c6d6646567 Fix typo in module API docs (#7861)
(cherry picked from commit ce5efb444b203536335ca6dd5d34cb57425b55be)
2020-10-27 09:12:01 +02:00
David CARLIER
58a7774ca4 getting rss size implementation for netbsd (#7293)
(cherry picked from commit 520c3b26c3fce1c86cf0c70961acd0515c8cb498)
2020-10-27 09:12:01 +02:00
Oran Agra
0fc601b3dd Fix new obuf-limits tests to work with TLS (#7848)
Also stabilize new shutdown tests on slow machines (valgrind)

(cherry picked from commit d89ae2d7ab3f6d181689b2546f2784b574d9b80e)
2020-10-27 09:12:01 +02:00
caozb
5ed795f025 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 01694608cb4e39a6ec7970d24b21ab33b7347e31)
2020-10-27 09:12:01 +02:00
Wang Yuan
a6f8745127 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 9bdef76f8e3bbfaacf0962ab1ceded1bafa80bda)
2020-10-27 09:12:01 +02:00
Wang Yuan
9042852ea1 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 917043fa438d9bbe9a80fb838fcfd33a7e390952)
2020-10-27 09:12:01 +02:00
Uri Shachar
10be3d96d8 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 8dbe91f0316f08d785bad1e8e28f1c13ddfbef2c)
2020-10-27 09:12:01 +02:00
WuYunlong
39e1f2e2bd 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 d119448881655a1529eb6d7d7e78af5f15132536)
2020-10-27 09:12:01 +02:00
Wen Hui
ac867bfb6a 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 c67656fa3541376590fe9a9b146ad5641cb861aa)
2020-10-27 09:12:01 +02:00
Wang Yuan
1c4a99c9ec 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 3085577c095a0f3b1261f6dbf016d7701aadab46)
2020-10-27 09:12:01 +02:00
Guy Korland
66a13267c7 Fix RedisModule_HashGet examples (#6697)
(cherry picked from commit 04945e0e6d5aadd9fb5a7b47d947d759073af51a)
2020-10-27 09:12:01 +02:00
Oran Agra
7ab8961c6d fix recently broken TLS build error, and add coverage for CI (#7833)
(cherry picked from commit 270fcb80bf8c5d8458d60d3a494f422d12e1dfaf)
2020-10-27 09:12:01 +02:00
David CARLIER
06c8f03ba1 Further NetBSD update and build fixes. (#7831)
mainly backtrace and register dump support.

(cherry picked from commit 6bc28d99a3a24c31c44e134b12a502441266e8bc)
2020-10-27 09:12:01 +02:00
WuYunlong
d3fc736123 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 00668f782f0d8e987fc2c049c34e100567c0a5c6)
2020-10-27 09:12:01 +02:00
yixiang
f478a1b6fb Fix connGetSocketError usage (#7811)
(cherry picked from commit 4e70e49d2bdaa477d9436a394f8626a1cc6e94af)
2020-10-27 09:12:01 +02:00
Oran Agra
90e8da536e RM_GetContextFlags - document missing flags (#7821)
(cherry picked from commit 78c80b3f8c4d37884ee387ef44abdd83664ee448)
2020-10-27 09:12:01 +02:00
Yossi Gottlieb
24f258e39c 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 cad93ed.

(cherry picked from commit ecd86283ec292c1062f377f5707be57a8a77adb4)
2020-10-27 09:12:01 +02:00
Ariel Shtul
29f6e9fe95 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 b914d4fc4825cc20cebca43431af5029ee077d09)
2020-10-27 09:12:01 +02:00
Wen Hui
8f4ad687af 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 7934f163b4b6c1c0c0fc55710d3c7e49f56281f1)
2020-10-27 09:12:01 +02:00
WuYunlong
5021ed7c45 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 e9b6077.

(cherry picked from commit 6c6ab16e5a31c09a6ea09f1b4638c121e610566a)
2020-10-27 09:12:01 +02:00
WuYunlong
4a3330c941 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 cf8a6e3.

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit d2291627305d606a5d3b1e3b3bfa17ab10a3ef32)
2020-10-27 09:12:01 +02:00
Oran Agra
f216bf312a RM_GetContextFlags provides indication that we're in a fork child (#7783)
(cherry picked from commit 0b476b591d8b92e88ec56675e747de23968eeae0)
2020-10-27 09:12:01 +02:00
Wen Hui
d3f36e93a9 Add Swapdb Module Event (#7804)
(cherry picked from commit 0db3223bc6090556c920912d9c92dd42878e316c)
2020-10-27 09:12:01 +02:00
Daniel Dai
064992af62 fix make warnings in debug.c MacOS (#7805)
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 6d46a8e2163750f707f9d36889d5fdf514132a69)
2020-10-27 09:12:01 +02:00