9916 Commits

Author SHA1 Message Date
sundb
8b97b35a39 Merge pushGenericCommand and pushxGenericCommand (#8255)
Merge pushGenericCommand and pushxGenericCommand to remove redundancy and simplify code.
2020-12-29 22:37:37 -08:00
Oran Agra
08ed96dd76 Fix memory leaks in error replies due to recent change (#8249)
Recently 4ef25c45b started using addReplyErrorSds in place of
addReplySds the later takes ownership of the string but the former did
not.
This introduced memory leaks when a script returns an error to redis,
and also in clusterRedirectClient (two new usages of
addReplyErrorSds which was mostly unused till now.

This commit chagnes two thanks.
1. change addReplyErrorSds to take ownership of the error string.
2. scripting.c doesn't actually need to use addReplyErrorSds, it's a
perfect match for addReplyErrorFormat (replaces newlines with spaces)
2020-12-27 21:40:12 +02:00
Oran Agra
adfe32135e Make the protocol-version argument of HELLO optional (#7377) 2020-12-27 16:37:27 +02:00
zhaozhao.zz
da52a7cef2 Tracking: add CLIENT TRACKINGINFO subcommand (#7309)
Add CLIENT TRACKINGINFO subcommand

Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-27 13:14:39 +02:00
Itamar Haber
cc76a1e0a6 Adds count to L/RPOP (#8179)
Adds: `L/RPOP <key> [count]`

Implements no. 2 of the following strategies:

1. Loop on listTypePop - this would result in multiple calls for memory freeing and allocating (see 769167a079)
2. Iterate the range to build the reply, then call quickListDelRange - this requires two iterations and **is the current choice**
3. Refactor quicklist to have a pop variant of quickListDelRange - probably optimal but more complex

Also:
* There's a historical check for NULL after calling listTypePop that was converted to an assert.
* This refactors common logic shared between LRANGE and the new form of LPOP/RPOP into addListRangeReply (adds test for b/w compat)
* Consequently, it may have made sense to have `LRANGE l -1 -2` and `LRANGE l 9 0` be legit and return a reverse reply. Due to historical reasons that would be, however, a breaking change.
* Added minimal comments to existing commands to adhere to the style, make core dev life easier and get commit karma, naturally.
2020-12-25 21:49:24 +02:00
Itamar Haber
95345015eb Use addReplyErrorObject with shared.syntaxerror (#8248) 2020-12-25 18:27:30 +02:00
xhe
129e376d70 fix the format
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-25 10:17:55 +08:00
xhe
d411c39bc5 reword
Co-authored-by: Itamar Haber <itamar@redislabs.com>
2020-12-25 01:40:06 +08:00
Oran Agra
acd8fac359 resolve hung test. 2020-12-24 14:33:53 +02:00
xhe
77abfebefc address comment
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 20:13:57 +08:00
xhe
609686f5b2 reword
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 19:25:30 +08:00
xhe
4f4fee77b8 ask protover for authentication
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 19:23:35 +08:00
xhe
304740e791 correction
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 19:16:28 +08:00
huangzhw
bd08dbcf83 cleanup: ziplist prev entry large length use sizeof(uint32_t) instead 4 (#8241)
This is just a cleanup, no bugs in the real world.

Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 11:58:43 +02:00
Oran Agra
12f684e267 syncWithMaster: use pipeline for AUTH+REPLCONF*3
The commit deals with the syncWithMaster and the ugly state machine in it.
It attempts to clean it a bit, but more importantly it uses pipeline for
part of the work (rather than 7 round trips, we now have 4).
i.e. the connect and PING are separate, then AUTH + 3 REPLCONF in one pipeline,
and finally the PSYNC (must be separate since the master has to have an empty
output buffer).
2020-12-24 11:55:28 +02:00
Oran Agra
5fe831f599 syncWithMaster: sendSynchronousCommand split to send, and receive
This is just a refactoring commit.

This function was never actually used as a synchronous (do both send or
receive), it was always used only ine one of the two modes, which meant it
has to take extra arguments that are not relevant for the other.

Besides that, a tool that sends a synchronous command, it not something
we want in our toolbox (synchronous IO in single threaded app is evil).

sendSynchronousCommand was now refactored into separate sending and
receiving APIs, and the sending part has two variants, one taking vaargs,
and the other taking argc+argv (and an optional length array which means
you can use binary sds strings).
2020-12-24 11:55:28 +02:00
xhe
9caae4f488 fix the test
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 17:31:50 +08:00
xhe
3abe8da7eb simplify
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 17:03:53 +08:00
xhe
4d284744e8 simplify
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 17:03:45 +08:00
xhe
b46a3530ae simplify
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 17:03:36 +08:00
xhe
991d84a506 simplify
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-24 17:03:22 +08:00
xhe
bb5ef2bd72 try to fix the test
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 16:50:08 +08:00
Brad Dunbar
18fe7b6464 Typo: timout -> timeout (#8228) 2020-12-24 10:42:52 +02:00
xhe
2a173d7aba prefer !
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 15:29:17 +08:00
xhe
66065db476 add a test
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 15:26:24 +08:00
xhe
451956e15b HELLO without protover
Signed-off-by: xhe <xw897002528@gmail.com>
2020-12-24 13:35:41 +08:00
xhe
e3cedbb18c add a read-only variant for HELLO
As discussed in https://github.com/antirez/redis/issues/7364, it is good
to have a HELLO command variant, which does not switch the current proto
version of a redis server.

While `HELLO` will work, it introduced a certain difficulty on parsing
options of the command. We will need to offset the index of authentication
and setname option by -1.

So 0 is marked a special version meaning non-switching. And we do not
need to change the code much.
2020-12-24 13:03:47 +08:00
Madelyn Olson
b625554f32 Cleanup key tracking documentation and table management (#8039)
Cleanup key tracking documentation, always cleanup the tracking table, and free the tracking table in an async manner when applicable.
2020-12-23 19:13:12 -08:00
Madelyn Olson
4ef25c45bb Flow through the error handling path for most errors (#8226)
Properly throw errors for invalid replication stream and support https://github.com/redis/redis/pull/8217
2020-12-23 19:06:25 -08:00
Wang Yuan
2427481e49 Add semicolon to calls of test_cond() (#8238) 2020-12-23 09:16:49 -08:00
sundb
f6c6f30bdd Fix redundancy incrRefCount in lmoveGenericCommand (#8218) 2020-12-23 08:37:33 -08:00
Yang Bodong
214e4189a3 Tests: fix the problem that Darwin memory leak detection may fail (#8213)
Apparently the "leaks" took reports a different error string about process
that's not found in each version of MacOS.
This cause the test suite to fail on some OS versions, since some tests terminate
the process before looking for leaks.
Instead of looking at the error string, we now look at the (documented) exit code.
2020-12-23 16:28:17 +02:00
Greg Femec
c2eaae3653 Fix random element selection for large hash tables. (#8133)
When a database on a 64 bit build grows past 2^31 keys, the underlying hash table expands to 2^32 buckets. After this point, the algorithms for selecting random elements only return elements from half of the available buckets because they use random() which has a range of 0 to 2^31 - 1. This causes problems for eviction policies which use dictGetSomeKeys or dictGetRandomKey. Over time they cause the hash table to become unbalanced because, while new keys are spread out evenly across all buckets, evictions come from only half of the available buckets. Eventually this half of the table starts to run out of keys and it takes longer and longer to find candidates for eviction. This continues until no more evictions can happen.

This solution addresses this by using a 64 bit PRNG instead of libc random().

Co-authored-by: Greg Femec <gfemec@google.com>
2020-12-23 15:52:07 +02:00
Oran Agra
997c2dc7ec 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
2020-12-23 12:55:05 +02:00
Felix Bünemann
8497c75eb7 Fix TLS build on macOS arm64 systems (#8197)
Homebrew for darwin-arm64 uses /opt/homebrew instead of /usr/local as
the prefix, so that it can coexist with darwin-x86_64 using Rosetta 2.
2020-12-23 09:46:23 +02:00
Wen Hui
84a2084d07 Sentinel: add missing calls for sentinelflushconfig when config master at runtime (#8229) 2020-12-22 16:14:15 +02:00
Meir Shpilraien (Spielrein)
4192faa982 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.
2020-12-22 15:17:39 +02:00
Yossi Gottlieb
53f926dd90 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
2020-12-22 12:24:20 +02:00
Oran Agra
de9050af71 Remove read-only flag from non-keyspace cmds, different approach for EXEC to propagate MULTI (#8216)
In the distant history there was only the read flag for commands, and whatever
command that didn't have the read flag was a write one.
Then we added the write flag, but some portions of the code still used !read
Also some commands that don't work on the keyspace at all, still have the read
flag.

Changes in this commit:
1. remove the read-only flag from TIME, ECHO, ROLE and LASTSAVE

2. EXEC command used to decides if it should propagate a MULTI by looking at
   the command flags (!read & !admin).
   When i was about to change it to look at the write flag instead, i realized
   that this would cause it not to propagate a MULTI for PUBLISH, EVAL, and
   SCRIPT, all 3 are not marked as either a read command or a write one (as
   they should), but all 3 are calling forceCommandPropagation.

   So instead of introducing a new flag to denote a command that "writes" but
   not into the keyspace, and still needs propagation, i decided to rely on
   the forceCommandPropagation, and just fix the code to propagate MULTI when
   needed rather than depending on the command flags at all.

   The implication of my change then is that now it won't decide to propagate
   MULTI when it sees one of these: SELECT, PING, INFO, COMMAND, TIME and
   other commands which are neither read nor write.

3. Changing getNodeByQuery and clusterRedirectBlockedClientIfNeeded in
   cluster.c to look at !write rather than read flag.
   This should have no implications, since these code paths are only reachable
   for commands which access keys, and these are always marked as either read
   or write.

This commit improve MULTI propagation tests, for modules and a bunch of
other special cases, all of which used to pass already before that commit.
the only one that test change that uncovered a change of behavior is the
one that DELs a non-existing key, it used to propagate an empty
multi-exec block, and no longer does.
2020-12-22 12:03:49 +02:00
sundb
83ea60e00d Fix some redundancy use of semicolon in do-while macros (#8221)
* Fix some redundancy use of semicolon in do-while macros
2020-12-21 22:57:45 -08:00
valentinogeron
7edc54dcb7 Fix PFDEBUG commands flag (#8222)
- Mark it as a @hyperloglog command (ACL)
- Should not be allowed in OOM
- Add firstkey, lastkey, step
- Add comment that explains the 'write' flag
2020-12-21 15:40:20 +02:00
sundb
bc82c3bf96 Fix command reset's arity (#8212) 2020-12-18 14:55:39 +02:00
Qu Chen
b8c98337cd 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.
2020-12-17 21:58:58 +02:00
Qu Chen
c021626bc1 Handle binary safe string for REQUIREPASS and MASTERAUTH directives (#8200)
* Handle binary safe string for REQUIREPASS and MASTERAUTH directives.
2020-12-17 09:26:33 -08:00
Nick Revin
f394387e04 install redis-check-rdb and redis-check-aof as symlinks to redis-server (#5745) 2020-12-17 14:49:19 +02:00
Hanif Ariffin
96ab6f1baa More fixes to printf format specifier. (#7909)
mostly signed / unsigned mismatches.

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
2020-12-17 13:00:48 +02:00
sundb
161203086c Fix comment of georadiusGeneric function (#8202) 2020-12-17 11:02:17 +02:00
Wang Yuan
b9f236a781 [Redis-benchmark] Use IP from CLUSTER NODE reply for first node too (#8154)
If we only has one node in cluster or before 8fdc857, we don't know myself ip, so we should use config.hostip for myself.
However, we should use the IP from the command response to update node->ip if it exists and is different from config.hostip

otherwise, when there's more than one node in cluster, if we use -h with virtual IP or DNS, benchmark doesn't show node real ip and port of myself even though it could get right IP and port by CLUSTER NODES command.
2020-12-17 10:22:13 +02:00
Wen Hui
f583bfa1dd fix wrong comment in cluster.h (#8191) 2020-12-16 23:19:12 +02:00
filipe oliveira
498192d2d3 Included in redis.conf explicit explanation of tls-protocol defaults (#8193) 2020-12-15 22:03:05 +02:00