27610 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
66a13267c7 Fix RedisModule_HashGet examples (#6697)
(cherry picked from commit 04945e0e6d5aadd9fb5a7b47d947d759073af51a)
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
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
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
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
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
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
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
f478a1b6fb Fix connGetSocketError usage (#7811)
(cherry picked from commit 4e70e49d2bdaa477d9436a394f8626a1cc6e94af)
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
90e8da536e RM_GetContextFlags - document missing flags (#7821)
(cherry picked from commit 78c80b3f8c4d37884ee387ef44abdd83664ee448)
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
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
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
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
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
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
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
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
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
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
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
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
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
d3f36e93a9 Add Swapdb Module Event (#7804)
(cherry picked from commit 0db3223bc6090556c920912d9c92dd42878e316c)
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
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
Daniel Dai
aa1feec746 fix make warnings in debug.c MacOS (#7805)
Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 1b3b75208c243fe9e18f34c4fb5f0233c2dc5a7f)
2020-10-27 09:12:01 +02:00
David CARLIER
57e1dbff57 debug.c: NetBSD build warning fix. (#7810)
The symbol base address is a const on this system.

(cherry picked from commit c9edb477921d2fbf80c8ffef0882fbd0281675fa)
2020-10-27 09:12:01 +02:00
David CARLIER
e5e353c81d debug.c: NetBSD build warning fix. (#7810)
The symbol base address is a const on this system.

(cherry picked from commit eabe3eaec02e293d479c695bc973b8780c989da9)
2020-10-27 09:12:01 +02:00
Wang Yuan
048816bf27 Remove tmp rdb file in background thread (#7762)
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 6638f6129553d0f19c60944e70fe619a4217658c)
2020-10-27 09:12:01 +02:00
Wang Yuan
0bdddd3c89 Remove tmp rdb file in background thread (#7762)
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 b002d2b4f1415f4db805081bc8f5b85d00f30e33)
2020-10-27 09:12:01 +02:00
Oran Agra
1cbdafc980 Add printf attribute and fix warnings and a minor bug (#7803)
The fix in error handling of rdbGenericLoadStringObject is an actual bugfix

(cherry picked from commit 622b57e9eea44e069ad973597bed40107cfbeff0)
2020-10-27 09:12:01 +02:00
Oran Agra
7bc0726016 Add printf attribute and fix warnings and a minor bug (#7803)
The fix in error handling of rdbGenericLoadStringObject is an actual bugfix

(cherry picked from commit 092cfca5224e8e88053cd5b8a7b82f0f14b17011)
2020-10-27 09:12:01 +02:00
WuYunlong
201b993840 bio: doFastMemoryTest should try to kill io threads as well.
(cherry picked from commit e9b6077ac798e4d30c9401a3687ffe61568b6eae)
2020-10-27 09:12:01 +02:00
WuYunlong
ea4bf91abc bio: doFastMemoryTest should try to kill io threads as well.
(cherry picked from commit f86602339968cc89e31bd51fb9d6c771c3ab26ee)
2020-10-27 09:12:01 +02:00
WuYunlong
4aef590a63 bio: fix doFastMemoryTest.
If one thread got SIGSEGV, function sigsegvHandler() would be triggered,
it would call bioKillThreads(). But call pthread_cancel() to cancel itself
would make it block. Also note that if SIGSEGV is caught by bio thread, it
should kill the main thread in order to give a positive report.

(cherry picked from commit cf8a6e3c7a0448851f0c00ff1a726701a2be9f1a)
2020-10-27 09:12:01 +02:00
WuYunlong
5d9332266d bio: fix doFastMemoryTest.
If one thread got SIGSEGV, function sigsegvHandler() would be triggered,
it would call bioKillThreads(). But call pthread_cancel() to cancel itself
would make it block. Also note that if SIGSEGV is caught by bio thread, it
should kill the main thread in order to give a positive report.

(cherry picked from commit 8b70cb0ef8e654d09d0d2974ad72388f46be9fde)
2020-10-27 09:12:01 +02:00
Wen Hui
385e3596b5 correct OBJECT ENCODING response for stream type (#7797)
This commit makes stream object returning "stream" as encoding type in OBJECT ENCODING subcommand and DEBUG OBJECT command.

Till now, it would return "unknown"

(cherry picked from commit 2a8803f534728a6fd1b7c29a2d7e195f6a928f50)
2020-10-27 09:12:01 +02:00