Commit Graph

11250 Commits

Author SHA1 Message Date
Binbin 35e836c26d
Add SENTINEL command flag to CLIENT/COMMANDS subcommands (#10904)
This was harmless because we marked the parent command
with SENTINEL flag. So the populateCommandTable was ok.
And we also don't show the flag (SENTINEL and ONLY-SENTNEL)
in COMMAND INFO.

In this PR, we also add the same CMD_SENTINEL and CMD_ONLY_SENTINEL
flags check when populating the sub-commands.
so that in the future it'll be possible to add some sub-commands to sentinel or sentinel-only but not others.
2022-06-30 16:32:40 +03:00
Wen Hui 51da5c3dde
Fix CLUSTER RESET command argument number issue (#10898)
Fix regression of CLUSTER RESET command in redis 7.0.

cluster reset command format is:
CLUSTER RESET [ HARD | SOFT]

According to the cluster reset command doc and codes, the third argument is optional, so
the arity in json file should be -2 instead of 3.

Add test to verify future regressions with RESET and RESET SOFT that were not covered.

Co-authored-by: Ubuntu <lucas.guang.yang1@huawei.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Binbin <binloveplay1314@qq.com>
2022-06-29 08:17:00 +03:00
jonnyomerredis 35c2ee8716
Add sharded pubsub keychannel count to client info (#10895)
When calling CLIENT INFO/LIST, and in various debug prints, Redis is printing
the number of pubsub channels / patterns the client is subscribed to.
With the addition of sharded pubsub, it would be useful to print the number of
keychannels the client is subscribed to as well.
2022-06-28 10:11:17 +03:00
Tian 069b30a2b3
A minor refinement to clusterbus extension estlen (#10902) 2022-06-27 20:42:55 -07:00
Viktor Söderqvist 6af021007a
Add missing REDISMODULE_CLIENTINFO_INITIALIZER (#10885)
The module API docs mentions this macro, but it was not defined (so no one could have used it).

Instead of adding it as is, we decided to add a _V1 macro, so that if / when we some day extend this struct,
modules that use this API and don't need the extra fields, will still use the old version
and still be compatible with older redis version (despite being compiled with newer redismodule.h)
2022-06-27 08:29:05 +03:00
RinChanNOW! 2854637385
Support conversion between `RedisModuleString` and `unsigned long long` (#10889)
Since the ranges of `unsigned long long` and `long long` are different, we cannot read an
`unsigned long long` integer from a `RedisModuleString` by `RedisModule_StringToLongLong` . 

So I added two new Redis Module APIs to support the conversion between these two types:
* `RedisModule_StringToULongLong`
* `RedisModule_CreateStringFromULongLong`

Signed-off-by: RinChanNOWWW <hzy427@gmail.com>
2022-06-26 15:02:52 +03:00
Binbin d443e312ad
redis-server command line arguments allow passing config name and value in the same arg (#10866)
This commit has two topics.

## Passing config name and value in the same arg
In #10660 (Redis 7.0.1), when we supported the config values that can start with `--` prefix (one of the two topics of that PR),
we broke another pattern: `redis-server redis.config "name value"`, passing both config name
and it's value in the same arg, see #10865

This wasn't a intended change (i.e we didn't realize this pattern used to work).
Although this is a wrong usage, we still like to fix it.

Now we support something like:
```
src/redis-server redis.conf "--maxmemory '700mb'" "--maxmemory-policy volatile-lru" --proc-title-template --my--title--template --loglevel verbose
```

## Changes around --save
Also in this PR, we undo the breaking change we made in #10660 on purpose.
1. `redis-server redis.conf --save --loglevel verbose` (missing `save` argument before anotehr argument).
    In 7.0.1, it was throwing an wrong arg error.
    Now it will work and reset the save, similar to how it used to be in 7.0.0 and 6.2.x.
3. `redis-server redis.conf --loglevel verbose --save` (missing `save` argument as last argument).
    In 6.2, it did not reset the save, which was a bug (inconsistent with the previous bullet).
    Now we will make it work and reset the save as well (a bug fix).
2022-06-26 14:36:39 +03:00
Viktor Söderqvist 6272ca609e
Add RM_SetClientNameById and RM_GetClientNameById (#10839)
Adding Module APIs to let the module read and set the client name of an arbitrary connection.
2022-06-26 14:34:59 +03:00
Binbin d96cf3639a
Sync argv_len var back after command call in execCommand (#10900)
This is harmless, we only restore mstate to make sure we
free the right pointer in freeClientMultiState, but it'll
be nicer to also sync that argv_len var back.
2022-06-26 12:32:34 +03:00
Elvina Yakubova e2cf386765
Replace regular array to array of structs to get rid of false sharing (#10892)
There are a lot of false sharing cache misses in line 4013 inside getIOPendingCount function.
The reason is that elements of io_threads_pending array access the same cache line from different
threads, so it is better to represent it as an array of structures with fields aligned to cache line size.
This change should improve performance (in particular, it affects the latency metric, we saw up to 3% improvement).
2022-06-26 08:39:30 +03:00
Steve Lorello a64b29485d
changing min,max in ZRANGE -> start stop (#10097)
In 6.2.0 with the introduction of the REV subcommand in ZRANGE, there was a semantic shift in the arguments of ZRANGE when the REV sub-command is executed. Without the sub-command `min` and `max` (the old names of the arguments) are appropriate because if you put the min value and the max value in everything works fine.

```bash
127.0.0.1:6379> ZADD myset 0 foo
(integer) 1
127.0.0.1:6379> ZADD myset 1 bar
(integer) 1
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE
1) "foo"
2) "bar"
``` 

However - if you add the `REV` subcommand, ordering the arguments `min` `max` breaks the command:

```bash
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE REV
(empty array)
```

why? because `ZRANGE` with the `REV` sub-command is expecting the `max` first and the `min` second (because it's a reverse range like `ZREVRANGEBYSCORE`):

```bash
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE REV
(empty array)
```
2022-06-25 19:02:20 +03:00
WuYunlong 64205345bc
migrateGetSocket() cleanup.. (#5546)
I think parameter c is only useful to get client reply.
Besides, other commands' host and port parameters may not be the at index 1 and 2.
2022-06-23 18:41:32 +03:00
Binbin 755b51a42c
When dirCreateIfMissing or openNewIncrAofForAppend fail, set aof_lastbgrewrite_status to err (#10775)
It will be displayed in the `aof_last_bgrewrite_status`
field of the INFO command.
2022-06-23 18:40:20 +03:00
(╯°□°)╯︵ uᴉǝssnH ɐɟɐʇsoW c52922e1d9
command prompt help: add stdin config usage (#6313)
Signed-off-by: Mostafa Hussein <mostafa.hussein91@gmail.com>
2022-06-23 18:37:42 +03:00
judeng d2405b9b6b
fix benchmark failure in daily test with TLS (#10896)
The new test added in #10891 can fail with a different error.
see comment in networking.c saying
```c
        /* That's a best effort error message, don't check write errors.
         * Note that for TLS connections, no handshake was done yet so nothing
         * is written and the connection will just drop. */
```
2022-06-23 18:19:36 +03:00
Binbin aabce8932a
Add bus_port argument in cluster-meet.json (#10304)
In `CLUSTER MEET`, bus-port argument was added in 11436b1.
For cluster announce ip / port implementation, part of the
4.0-RC1.

And in #9389, we add a new cluster-port config and make
cluster bus port configurable, part of the 7.0-RC1.
2022-06-23 07:56:25 +03:00
judeng 49876158cc
fix redis-benchmark's bug: check if clients are created successfully in idle mode (#10891)
my maxclients config:
```
redis-cli config get maxclients
1) "maxclients"
2) "4064"
```

Before this bug was fixed, creating 4065 clients appeared to be successful, but only 4064 were actually created```
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
cients: 4065
```

now :
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
Error from server: ERR max number of clients reached

./redis-benchmark -c 4064 -I
Creating 4064 idle connections and waiting forever (Ctrl+C when done)
clients: 4064

```
2022-06-22 19:30:22 +03:00
Viktor Söderqvist 02acb8fd3a
Module API docs corrections (#10890)
* Fix typo `RedisModule_CreatString` -> `RedisModule_CreateString` (multiple occurrences)
* Make the markdown gen script change all `RM_` to `RedisModule_` even in code examples, etc.
2022-06-21 17:00:24 +03:00
Meir Shpilraien (Spielrein) 61baabd8d5
Fix crash on RM_Call with script mode. (#10886)
The PR fixes 2 issues:

### RM_Call crash on script mode

`RM_Call` can potentially be called from a background thread where `server.current_client`
are not set. In such case we get a crash on `NULL` dereference.
The fix is to check first if `server.current_client` is `NULL`, if it does we should
verify disc errors and readonly replica as we do to any normal clients (no masters nor AOF).

### RM_Call block OOM commands when not needed

Again `RM_Call` can be executed on a background thread using a `ThreadSafeCtx`.
In such case `server.pre_command_oom_state` can be irrelevant and should not be
considered when check OOM state. This cause OOM commands to be blocked when
not necessarily needed.

In such case, check the actual used memory (and not the cached value). Notice that in
order to know if the cached value can be used, we check that the ctx that was used on
the `RM_Call` is a ThreadSafeCtx. Module writer can potentially abuse the API and use
ThreadSafeCtx on the main thread. We consider this as a API miss used.
2022-06-21 10:01:13 +03:00
Vlad a3fdc9cd82
Outdated comments, replace COUNTER_INIT_VAL with LFU_INIT_VAL, fix typo (#10888)
`COUNTER_INIT_VAL` doesn't exist in the code anymore so we can replace it with `LFU_INIT_VAL` entries
2022-06-21 08:14:31 +03:00
Bar Shaul 091701f363
Set replicas' configEpoch to 0 when loaded from cluster configuration file (#10798)
* Changed clusterLoadConfig to set the config epoch of replica nodes to 0 when loaded.
2022-06-20 21:40:48 -07:00
judeng ff6419658b
Optimize the performance of clusterSendPing for large clusters (#10624)
Optimize the performance of clusterSendPing by improving speed of checking for duplicate items in gossip.
2022-06-20 21:02:22 -07:00
Tian 99a425d0f3
Fsync directory while persisting AOF manifest, RDB file, and config file (#10737)
The current process to persist files is `write` the data, `fsync` and `rename` the file,
but a underlying problem is that the rename may be lost when a sudden crash like
power outage and the directory hasn't been persisted.

The article [Ensuring data reaches disk](https://lwn.net/Articles/457667/) mentions
a safe way to update file should be:

1. create a new temp file (on the same file system!)
2. write data to the temp file
3. fsync() the temp file
4. rename the temp file to the appropriate name
5. fsync() the containing directory

This commit handles CONFIG REWRITE, AOF manifest, and RDB file (both for persistence,
and the one the replica gets from the master).
It doesn't handle (yet), ACL SAVE and Cluster configs, since these don't yet follow this pattern.
2022-06-20 19:17:23 +03:00
Moti Cohen 4c72a09b78
Fix sentinel acl change test. Timing issue. (#10868)
Co-authored-by: moticless <moticless@github.com>
2022-06-19 09:45:16 +03:00
Masahiro Ide f2387daa83
Fix a prototype inconsitency of `_serverAssert` between redisassert.h and redis.h (#10872)
both redisassert.c and server.h + debug.c use const, but redisassert.h doesn't.
2022-06-19 08:42:12 +03:00
Wen Hui c37d63e87a
DEPRECATED rename-command config in sentinel (#10877)
Clients could use this config in sentinel only when they already add rename-command in the redis conf file,
but becuase in Redis instance, we already DEPRECATED rename-command config,
thus we should deprecate this in the sentinel part as well.

Co-authored-by: Oran Agra <oran@redislabs.com>
2022-06-19 08:18:47 +03:00
Chris Lamb a4754e228f
Correct 'certificate' typo. (#10867) 2022-06-15 13:37:39 +03:00
Oran Agra 2189100383
optimize zset conversion on large ZRANGESTORE (#10789)
when we know the size of the zset we're gonna store in advance,
we can check if it's greater than the listpack encoding threshold,
in which case we can create a skiplist from the get go, and avoid
converting the listpack to skiplist later after it was already populated.
2022-06-14 21:12:45 +03:00
Oran Agra 8ef4f1dbad
Script that made modification will not break with unexpected NOREPLICAS error (#10855)
If a script made a modification and then was interrupted for taking too long.
there's a chance redis will detect that a replica dropped and would like to reject
write commands with NOREPLICAS due to insufficient good replicas.
returning an error on a command in this case breaks the script atomicity.

The same could in theory happen with READONLY, MISCONF, but i don't think
these state changes can happen during script execution.
2022-06-14 21:09:50 +03:00
Oran Agra ffa0077041
Allow ECHO in loading and stale modes (#10853)
I noticed that scripting.tcl uses INFO from within a script and thought it's an
overkill and concluded it's nicer to use another CMD_STALE command,
decided to use ECHO, and then noticed it's not at all allowed in stale mode.
probably overlooked at #6843
2022-06-14 08:48:08 +03:00
hdyztmdqd c65e5087e8
Fix 2 comments in dict.c & redis-cli.c (#10860)
* fix comment in dict.c

fix comment in dict.c

* Fix comment in redis-cli.c

Fix comment in redis-cli.c
2022-06-14 08:09:08 +03:00
Huang Zhw 78960ad57b
Throw -TRYAGAIN instead of -ASK on migrating nodes for multi-key commands when the node only has some of the keys (#9526)
* In cluster getNodeByQuery when target slot is in migrating state and
the slot lack some keys but have at least one key, should return TRYAGAIN.

Before this commit, when a node is in migrating state and recevies
multiple keys command, if some keys don't exist, the command emits
an `ASK` redirection.

After this commit, if some keys exist and some keys don't exist, the
command emits a TRYAGAIN error. If all keys don't exist, the command
emits an `ASK` redirection.
2022-06-13 21:32:43 -07:00
Binbin 0a2f78837d
redis-check-rdb add when_opcode check for module aux (#10859)
In #9199, we add a `goto eoferr` in when_opcode check,
this means that if the when_opcode check fails, we will
abort the rdb loading, but this not reflected in the
rdb-check tool. So someone can modify when_opcode to make
rdb load fail, but rdb-check will report OK. Just a cleanup
or a code consistency issue.
```
serverLog: # Internal error in RDB reading offset 0, function at rdb.c:3055 -> bad when_opcode
[offset 0] Checking RDB file dump.rdb
[offset 109] \o/ RDB looks OK! \o/
```

Plus a minor memory leak fix like #9860, note that it will
exit immediately after the eoferr, so it is not strictly a
leak, so it is also a small cleanup.
2022-06-13 18:23:53 +03:00
XiongDa d4595dd94f
Fix typo in replication.c (#10854) 2022-06-13 12:12:46 +03:00
Johannes Truschnigg 9f3b410050
Correctly check for vm.overcommit_memory == 0 (#10841)
A regression caused by #10636 (released in 7.0.1) causes Redis startup warning about overcommit to be missing when needed and printed when not. 

Also, using atoi() to convert the string's value to an integer cannot discern
between an actual 0 (zero) having been read, or a conversion error.
2022-06-12 20:53:11 +03:00
XiongDa abb2ea7e3c
Fix 3 comments in server.c (#10844) 2022-06-12 08:44:44 +03:00
Binbin 92fb4f4f61
Fixed SET and BITFIELD commands being wrongly marked movablekeys (#10837)
The SET and BITFIELD command were added `get_keys_function` in #10148, causing
them to be wrongly marked movablekeys in `populateCommandMovableKeys`.

This was an unintended side effect introduced in #10148 (7.0 RC1)
which could cause some clients an extra round trip for these commands in cluster mode.

Since we define movablekeys as a way to determine if the legacy range [first, last, step]
doesn't find all keys, then we need a completely different approach.

The right approach should be to check if the legacy range covers all key-specs,
and if none of the key-specs have the INCOMPLETE flag. 
This way, we don't need to look at getkeys_proc of VARIABLE_FLAG at all.
Probably with the exception of modules, who may still not be using key-specs.

In this PR, we removed `populateCommandMovableKeys` and put its logic in
`populateCommandLegacyRangeSpec`.
In order to properly serve both old and new modules, we must probably keep relying
CMD_MODULE_GETKEYS, but do that only for modules that don't declare key-specs. 
For ones that do, we need to take the same approach we take with native redis commands.

This approach was proposed by Oran. Fixes #10833

Co-authored-by: Oran Agra <oran@redislabs.com>
2022-06-12 08:22:18 +03:00
Binbin 62ac1ab007
Fix crash when overcommit_memory is inaccessible (#10848)
When `/proc/sys/vm/overcommit_memory` is inaccessible, fp is NULL.
`checkOvercommit` will return -1 without setting err_msg, and then
the err_msg is used to print the log, crash the server.
Set the err_msg variables to Null when declaring it, seems safer.

And the overcommit_memory error log will print two "WARNING",
like `WARNING WARNING overcommit_memory is set to 0!`, this PR
also removes the second WARNING in `checkOvercommit`.

Reported in #10846. Fixes #10846. Introduced in #10636 (7.0.1)
2022-06-11 22:27:44 +03:00
Christian Krieg 032619b82b
Fixing test to consider statically linked binaries (#10835)
The test calls `ldd` on `redis-server` in order to find out whether the binary
was linked against `libmusl`; However, `ldd` returns a value different from `0`
when statically linking the binaries agains libc-musl, because `redis-server` is
not a dynamic executable (as given by the exception thrown by the failing test),
and `make test` terminates with an error::

   $ ldd src/redis-server
       not a dynamic executable
   $ echo $?
   1

This commit fixes the test by ignoring such failures.

Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
2022-06-09 12:59:33 +03:00
Wen Hui 6e1c3ff132
Update some comments in stream command docs (#10821)
some small documentation fixes.
2022-06-09 10:16:56 +03:00
Steve Lorello 9e40b076dd
Module api doc generator, fixing issue with negative lookback terminating at "." (#10832)
There is a little regex that wraps up all the free-floating functions in the doc-block
e.g. malloc() with backticks.
in case of `redis.call()`, it used to wrap just `call()` in backticks.
2022-06-08 15:30:04 +03:00
Petr Vaněk f22bfe86b6
Update musl libc detection pattern (#10826)
This change fixes failing `integration/logging.tcl` test in Gentoo with
musl libc, where `ldd` returns
```
libc.so => /lib/ld-musl-x86_64.so.1 (0x7f9d5f171000)
```
unlike Alpine's
```
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f82cfa16000)
```
The solution is to extend matching pattern introduced in #8532.
2022-06-07 18:47:01 +03:00
Binbin ae9764ea0a
Increment the stat_rdb_saves counter in SAVE command (#10827)
Currently, we only increment stat_rdb_saves in rdbSaveBackground,
we should also increment it in the SAVE command.

We concluded there's no need to increment when:
1. saving a base file for an AOF
2. when saving an empty rdb file to delete an old one
3. when saving to sockets (not creating a persistence / snapshot file)

The stat counter was introduced in #10178

* fix a wrong comment in startSaving
2022-06-07 17:38:31 +03:00
ls-2018 b8665b879b
fix unused argument warning in ae_select.c (#10824) 2022-06-07 14:47:09 +03:00
Bjorn Svensson 1067cfb34b
Documentation fixes of `BITFIELD_RO` and `XINFO STREAM` (#10823)
Correcting the introduction version of the command `BITFIELD_RO`
Command added by commit: b3e4abf06e 

Add history info of the `FULL` modifier in `XINFO STREAM`
Modifier was added by commit: 1e2aee3919

(Includes output from `./utils/generate-command-code.py`)
2022-06-07 13:26:47 +03:00
Binbin 3d56f607b7
Handle multiple_token flag in generate-command-help.rb (#10822)
Currently generate-command.help.rb dose not handle the
multiple_token flag, handle this flag in this PR.
The format is the same as redis-cli rendering.
```diff
- bitfield_ro key GET encoding offset [encoding offset ...]
+ bitfield_ro key GET encoding offset [GET encoding offset ...]
```

Re run generate-command-code.py which was forget in #10820.
Also change the flag value from string to bool, like "true" to true
2022-06-07 10:15:39 +03:00
ranshid b4772f6381
Fix bitfield_ro documentation (#10820)
Current documentation only states a single GET token is needed which is not true. Marking the command with multiple_token.
2022-06-06 18:11:58 -07:00
Oran Agra b0272252f7
update help.h (#10818)
before releasing 7.0.1
2022-06-06 11:39:53 +03:00
Oran Agra 475563e2e9
crash report instructions (#10816)
Trying to avoid people opening crash report issues about module crashes and ARM QEMU bugs.
2022-06-06 11:39:23 +03:00
DarrenJiang13 f558583493
Split instantaneous_repl_total_kbps to instantaneous_input_repl_kbps and instantaneous_output_repl_kbps. (#10810)
A supplement to https://github.com/redis/redis/pull/10062
Split `instantaneous_repl_total_kbps` to `instantaneous_input_repl_kbps` and `instantaneous_output_repl_kbps`. 
## Work:
This PR:
- delete 1 info field:
    - `instantaneous_repl_total_kbps`
- add 2 info fields:
    - `instantaneous_input_repl_kbps / instantaneous_output_repl_kbps`
## Result:
- master
```
total_net_input_bytes:26633673
total_net_output_bytes:21716596
total_net_repl_input_bytes:0
total_net_repl_output_bytes:18433052
instantaneous_input_kbps:0.02
instantaneous_output_kbps:0.00
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
- slave
```
total_net_input_bytes:18433212
total_net_output_bytes:94790
total_net_repl_input_bytes:18433052
total_net_repl_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.05
instantaneous_input_repl_kbps:0.00
instantaneous_output_repl_kbps:0.00
```
2022-06-06 08:29:24 +03:00