summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Fix oom-score-adj-values range, abs options, and bug when used in config ↵Oran Agra2020-11-223-8/+28
| | | | | | | | | | | | | | | | file (#8046) Fix: When oom-score-adj-values is provided in the config file after oom-score-adj yes, it'll take an immediate action, before readOOMScoreAdj was acquired, resulting in an error (out of range score due to uninitialized value. delay the reaction the real call is made by main(). Since the values are clamped to -1000..1000, and they're applied as an offset from the value at startup (which may be -1000), we need to allow the offsets to reach to +2000 so that a value of +1000 is achievable in case the value at startup was -1000. Adding an option for absolute values rather than relative ones.
* fix compilation with uClibc-ng (#8054)Rosen Penev2020-11-201-1/+1
| | | backtrace can be compile time disabled.
* EXISTS should not alter LRU, OBJECT should not reveal expired keys on ↵guybe72020-11-184-18/+19
| | | | | | | | | | | | | | | replica (#8016) The bug was introduced by #5021 which only attempted avoid EXIST on an already expired key from returning 1 on a replica. Before that commit, dbExists was used instead of lookupKeyRead (which had an undesired effect to "touch" the LRU/LFU) Other than that, this commit fixes OBJECT to also come empty handed on expired keys in replica. And DEBUG DIGEST-VALUE to behave like DEBUG OBJECT (get the data from the key regardless of it's expired state)
* Unified MULTI, LUA, and RM_Call with respect to blocking commands (#8025)Meir Shpilraien (Spielrein)2020-11-1712-12/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Blocking command should not be used with MULTI, LUA, and RM_Call. This is because, the caller, who executes the command in this context, expects a reply. Today, LUA and MULTI have a special (and different) treatment to blocking commands: LUA - Most commands are marked with no-script flag which are checked when executing and command from LUA, commands that are not marked (like XREAD) verify that their blocking mode is not used inside LUA (by checking the CLIENT_LUA client flag). MULTI - Command that is going to block, first verify that the client is not inside multi (by checking the CLIENT_MULTI client flag). If the client is inside multi, they return a result which is a match to the empty key with no timeout (for example blpop inside MULTI will act as lpop) For modules that perform RM_Call with blocking command, the returned results type is REDISMODULE_REPLY_UNKNOWN and the caller can not really know what happened. Disadvantages of the current state are: No unified approach, LUA, MULTI, and RM_Call, each has a different treatment Module can not safely execute blocking command (and get reply or error). Though It is true that modules are not like LUA or MULTI and should be smarter not to execute blocking commands on RM_Call, sometimes you want to execute a command base on client input (for example if you create a module that provides a new scripting language like javascript or python). While modules (on modules command) can check for REDISMODULE_CTX_FLAGS_LUA or REDISMODULE_CTX_FLAGS_MULTI to know not to block the client, there is no way to check if the command came from another module using RM_Call. So there is no way for a module to know not to block another module RM_Call execution. This commit adds a way to unify the treatment for blocking clients by introducing a new CLIENT_DENY_BLOCKING client flag. On LUA, MULTI, and RM_Call the new flag turned on to signify that the client should not be blocked. A blocking command verifies that the flag is turned off before blocking. If a blocking command sees that the CLIENT_DENY_BLOCKING flag is on, it's not blocking and return results which are matches to empty key with no timeout (as MULTI does today). The new flag is checked on the following commands: List blocking commands: BLPOP, BRPOP, BRPOPLPUSH, BLMOVE, Zset blocking commands: BZPOPMIN, BZPOPMAX Stream blocking commands: XREAD, XREADGROUP SUBSCRIBE, PSUBSCRIBE, MONITOR In addition, the new flag is turned on inside the AOF client, we do not want to block the AOF client to prevent deadlocks and commands ordering issues (and there is also an existing assert in the code that verifies it). To keep backward compatibility on LUA, all the no-script flags on existing commands were kept untouched. In addition, a LUA special treatment on XREAD and XREADGROUP was kept. To keep backward compatibility on MULTI (which today allows SUBSCRIBE, and PSUBSCRIBE). We added a special treatment on those commands to allow executing them on MULTI. The only backward compatibility issue that this PR introduces is that now MONITOR is not allowed inside MULTI. Tests were added to verify blocking commands are not blocking the client on LUA, MULTI, or RM_Call. Tests were added to verify the module can check for CLIENT_DENY_BLOCKING flag. Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: Itamar Haber <itamar@redislabs.com>
* ZREVRANGEBYSCORE Optimization for out of range offset (#5773)thomaston2020-11-171-0/+6
| | | | | | ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] When the offset is too large, the query is very slow. Especially when the offset is greater than the length of zset it is easy to determine whether the offset is greater than the length of zset at first, and If it exceed the length of zset, then return directly. Co-authored-by: Oran Agra <oran@redislabs.com>
* Improve and clean up supervised process support. (#8036)Yossi Gottlieb2020-11-171-35/+66
| | | | | | | | | | | | * Configuration file default should now be "auto". * Expose "process_supervised" as an info field. * Log messages improvements (clarify required systemd config, report auto-detected supervision mode, etc.) * Set server.supervised properly, so it can take precedence of "daemonize" configuration. * Produce clear warning if systemd is detected/requested but executable is compiled without support for it, instead of silently ignoring. * Handle systemd notification error on startup, and turn off supervised mode if it failed.
* Add COPY command (#7953)swamp04072020-11-179-0/+401
| | | | | | | | | | Syntax: COPY <key> <new-key> [DB <dest-db>] [REPLACE] No support for module keys yet. Co-authored-by: tmgauss Co-authored-by: Itamar Haber <itamar@redislabs.com> Co-authored-by: Oran Agra <oran@redislabs.com>
* Fix memory leaks in newly added ZDIFF (#8056)Oran Agra2020-11-161-1/+3
|
* Modules callbacks for lazy free effort, and unlink (#7912)chenyangyang2020-11-167-15/+107
| | | | | | | | | | | | | | Add two optional callbacks to the RedisModuleTypeMethods structure, which is `free_effort` and `unlink`. the `free_effort` callback indicates the effort required to free a module memory. Currently, if the effort exceeds LAZYFREE_THRESHOLD, the module memory may be released asynchronously. the `unlink` callback indicates the key has been removed from the DB by redis, and may soon be freed by a background thread. Add `lazyfreed_objects` info field, which represents the number of objects that have been lazyfreed since redis was started. Add `RM_GetTypeMethodVersion` API, which return the current redis-server runtime value of `REDISMODULE_TYPE_METHOD_VERSION`. You can use that when calling `RM_CreateDataType` to know which fields of RedisModuleTypeMethods are gonna be supported and which will be ignored.
* Add new commands ZDIFF and ZDIFFSTORE (#7961)Felipe Machado2020-11-154-44/+260
| | | | | | - Add ZDIFF and ZDIFFSTORE which work similarly to SDIFF and SDIFFSTORE - Make sure the new WITHSCORES argument that was added for ZUNION isn't considered valid for ZUNIONSTORE Co-authored-by: Oran Agra <oran@redislabs.com>
* Fix make warning in hellohook,c and testmodule.c (#8044)sundb2020-11-132-3/+3
| | | | | * Fix build warning in hellohook,c and testmodule.c * Change ci->id type to (unsigned long long)
* Adds user parsing to redis-cli URIs (#8048)Itamar Haber2020-11-121-1/+1
|
* cleanup: move list pop logic to single function (#7997)Yash Ladha2020-11-122-23/+19
| | | | | | | | | | BLPOP when there are elements in the list works in the same way as LPOP does. Due to this they also does the same repetitive action and logic for the same is written at two different places. This is a bad code practice as the one needs the context to change the BLPOP list pop code as well when the LPOP code gets changed. Separated the generic logic from LPOP to a function that is being used by the BLPOP code as well.
* Initialize original client argv for aof (#8042)Madelyn Olson2020-11-111-0/+3
| | | | | (this is a fixup for #8006) Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
* Invalidate aeTimer when returning AE_NOMORE (#8022)tzongw2020-11-111-1/+6
|
* add tracking bcast flag and client redirection in client list (#7995)Wen Hui2020-11-111-2/+4
|
* Rewritten commands are logged as their original command (#8006)Madelyn Olson2020-11-103-16/+39
| | | | | * Rewritten commands are logged as their original command Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
* Adds help for '--cluster-yes' (#8035)Itamar Haber2020-11-101-1/+24
|
* optimization src/adlist.c:listJoin()sundb2020-11-091-3/+4
|
* Moved RMAPI_FUNC_SUPPORTED location such that it will be visible to modules ↵Meir Shpilraien (Spielrein)2020-11-091-2/+2
| | | | | | (#8037) The RMAPI_FUNC_SUPPORTED was defined in the wrong place on redismodule.h and was not visible to modules.
* Fix the init value for repl_id of rdbSaveInfo struct (#8026)bugwz2020-11-081-1/+1
| | | | use 40 zeros rather than 30 zeros to match CONFIG_RUN_ID_SIZE. this doesn't have any real implications.
* DragonFlyBSD resident memory amount (almost) similar as FreeBSD. (#8023)David CARLIER2020-11-081-1/+5
|
* Typo fix: entires -> entries (#8031)sundb2020-11-083-4/+4
|
* Debug Populate: Avoid server crash when passing negative value for key and ↵Wen Hui2020-11-053-2/+23
| | | | | | | value size (#8018) * Debug Populate: Add checks for count and keysize to avoid crash * provide getRangeLongFromObjectOrReply and getPositiveLongFromObjectOrReply for range check
* Fix crash log output on ARM. (#8020)Yossi Gottlieb2020-11-051-1/+1
|
* Better INFO fields to track diskless and disk-based replication progress (#7981)Oran Agra2020-11-053-9/+31
| | | | | | | | | | | | | | | Expose new `loading_rdb_used_mem` showing the used memory of the server that saved the RDB file we're currently using. This is useful in diskless replication when the total size of the rdb is unkown, and can be used as a rought estimation of progres. Use that new field to calculate the "user friendly" `loading_loaded_perc` and `loading_eta_seconds`. Expose `master_sync_total_bytes` and `master_sync_total_bytes` to complement on the existing `master_sync_total_bytes` (which cannot be used on its own to calculate progress). Add "user friendly" field for `master_sync_perc`
* Add RESET command. (#7982)Yossi Gottlieb2020-11-053-10/+68
| | | | | | | | | | | | | | | | | | | | | Perform full reset of all client connection states, is if the client was disconnected and re-connected. This affects: * MULTI state * Watched keys * MONITOR mode * Pub/Sub subscription * ACL/Authenticated state * Client tracking state * Cluster read-only/asking state * RESP version (reset to 2) * Selected database * CLIENT REPLY state The response is +RESET to make it easily distinguishable from other responses. Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: Itamar Haber <itamar@redislabs.com>
* rdb: corrected RedisModuleIO initialization point (#8014)Tomasz Poradowski2020-11-041-2/+2
| | | | | | | | | | | - rdbSaveSingleModuleAux() used RedisModuleIO's "bytes" field for tracking written bytes before calling moduleInitIOContext() which sets "bytes" to zero - rdbSaveObject() re-initialized RedisModuleIO too late This return value is not used at the moment since it's only tested against -1, and the actual byte count isn't used yet. Co-authored-by: Tomasz Poradowski <tomasz.poradowski@generiscorp.com>
* Enable specifying TLS ciphers(suites) in redis-cli/redis-benchmark (#8005)filipe oliveira2020-11-044-1/+46
| | | | | Enable specifying the preferred ciphers and/or ciphersuites for redis-cli/redis-benchmark. Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
* Allow '\0' inside of result of sdscatvprintf, and efficiency improvements ↵Egor Seredin2020-11-041-6/+26
| | | | | | | | | | (#6260) This will allow to use: RedisModule_CreateStringPrintf(ctx, "%s %c %s", "string1", 0, "string2"); On large string, the previous code would incrementally retry to double the output buffer. now it uses the the return value of snprintf and grows to the right size in one step. and also avoids an excessive strlen in sdscat at the end.
* redis-cli cluster import support source and target that need auth (#7994)Wen Hui2020-11-041-11/+45
| | | | | | | | | | | | | | | | Make it possible for redis-cli cluster import to work with source and target that require AUTH. Adding two different flags --cluster-from-user, --cluster-from-pass and --cluster-askpass for source node authentication. Also for target authentication, using existing --user and --pass flag. Example: ./redis-cli --cluster import 127.0.0.1:7000 --cluster-from 127.0.0.1:6379 --pass 1234 --user default --cluster-from-user default --cluster-from-pass 123456 ./redis-cli --cluster import 127.0.0.1:7000 --cluster-from 127.0.0.1:6379 --askpass --cluster-from-user default --cluster-from-askpass
* Add maxclients and cluster_connections to INFO CLIENTS (#7979)Oran Agra2020-11-041-0/+4
| | | | | | | | | | | | | | Few config settings are also reflected by the INFO command. these are mainly ones that are important for either an instant view of the server status (to compare a metric to it's limit config), Important configurations that are necessary in the crash log (which currently doesn't print the config), And things that are important for monitoring solutions (such as Prometheus), which rely on INFO to collect their data. Add cluster_connections to INFO CLUSTER: This makes it possible to be combined together with connected_clients and connected_slaves and be matched against maxclients
* Disable rehash when redis has child process (#8007)Wang Yuan2020-11-034-1/+7
| | | | | | In redisFork(), we don't set child pid, so updateDictResizePolicy() doesn't take effect, that isn't friendly for copy-on-write. The bug was introduced this in redis 6.0: 56258c6
* Added crash report on SIGABRT (#8004)Meir Shpilraien (Spielrein)2020-11-033-0/+9
| | | | | | The reason that we want to get a full crash report on SIGABRT is that the jmalloc, when detecting a corruption, calls abort(). This will cause the Redis to exist silently without any report and without any way to analyze what happened.
* Propagate GETSET and SET-GET as SET (#7957)Oran Agra2020-11-031-1/+24
| | | | | - Generates a more backwards compatible command stream - Slightly more efficient execution in replica/AOF - Add a test for coverage
* Modules: Improve timer accuracy (#7987)guybe72020-11-021-2/+14
| | | | | | | The bug occurs when 'callback' re-registers itself to a point in the future and the execution time in non-negligible: 'now' refers to time BEFORE callback was executed and is used to calculate 'next_period'. We must get the actual current time when calculating 'next_period'
* Add local address to CLIENT LIST, and a CLIENT KILL filter. (#7913)yoav-steinberg2020-10-289-64/+70
| | | | | | | | | Useful when you want to know through which bind address the client connected to the server in case of multiple bind addresses. - Adding `laddr` field to CLIENT list showing the local (bind) address. - Adding `LADDR` option to CLIENT KILL to kill all the clients connected to a specific local address. - Refactoring to share code.
* Optionally (default) fail to start if requested bind address is not ↵Oran Agra2020-10-282-45/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | available (#7936) Background: #3467 (redis 4.0.0), started ignoring ENOPROTOOPT, but did that only for the default bind (in case bind config wasn't explicitly set). #5598 (redis 5.0.3), added that for bind addresses explicitly set (following bug reports in Debian for redis 4.0.9 and 5.0.1), it also ignored a bunch of other errors like EPROTONOSUPPORT which was requested in #3894, and also added EADDRNOTAVAIL (wasn't clear why). This (ignoring EADDRNOTAVAIL) makes redis start successfully, even if a certain network interface isn't up yet , in which case we rather redis fail and will be re-tried when the NIC is up, see #7933. However, it turns out that when IPv6 is disabled (supported but unused), the error we're getting is EADDRNOTAVAIL. and in many systems the default config file tries to bind to localhost for both v4 and v6 and would like to silently ignore the error on v6 if disabled. This means that we sometimes want to ignore EADDRNOTAVAIL and other times we wanna fail. So this commit changes these main things: 1. Ignore all the errors we ignore for both explicitly requested bind address and a default implicit one. 2. Add a '-' prefix to allow EADDRNOTAVAIL be ignored (by default that's different than the previous behavior). 3. Restructure that function in a more readable and maintainable way see below. 4. Make the default behavior of listening to all achievable by setting a bind config directive to * (previously only possible by omitting it) 5. document everything. The old structure of this function was that even if there are no bind addresses requested, the loop that runs though the bind addresses runs at least once anyway! In that one iteration of the loop it binds to both v4 and v6 addresses, handles errors for each of them separately, and then eventually at the if-else chain, handles the error of the last bind attempt again! This was very hard to read and very error prone to maintain, instead now when the bind info is missing we create one with two entries, and run the simple loop twice.
* White space tweaks and skip categories already appliedMadelyn Olson2020-10-281-3/+12
|
* Further improved ACL algorithm for picking categoriesMadelyn Olson2020-10-281-22/+47
|
* refactor aof rewrite code to avoid memory leaks in error handling (#7976)Wen Hui2020-10-281-29/+68
|
* docs: Fix some typos in comments and log messge (#7975)sundb2020-10-284-5/+5
|
* TLS Support for redis-benchmark (#7959)filipe oliveira2020-10-285-164/+323
|
* Fix waste of CPU time about server log in serverCron.WuYunlong2020-10-271-10/+11
| | | | | | When all the work is just adding logs, we could pull the condition out so as to use less CPU time when loglevel is bigger than LL_VERBOSE.
* Fix cluster access to unaligned memory (SIGBUS on old ARM) (#7958)Oran Agra2020-10-272-8/+25
| | | | | | | Turns out this was broken since version 4.0 when we added sds size classes. The cluster code uses sds for the receive buffer, and then casts it to a struct and accesses a 64 bit variable. This commit replaces the use of sds with a simple reallocated buffer.
* Disable THP if enabled (#7381)zhenwei pi2020-10-275-1/+20
| | | | | | | | | | | | | | | | | | | | | In case redis starts and find that THP is enabled ("always"), instead of printing a log message, which might go unnoticed, redis will try to disable it (just for the redis process). Note: it looks like on self-bulit kernels THP is likely be set to "always" by default. Some discuss about THP side effect on Linux: according to http://www.antirez.com/news/84, we can see that redis latency spikes are caused by linux kernel THP feature. I have tested on E3-2650 v3, and found that 2M huge page costs about 0.25ms to fix COW page fault. Add a new config 'disable-thp', the recommended setting is 'yes', (default) the redis tries to disable THP by prctl syscall. But users who really want THP can set it to "no" Thanks to Oran & Yossi for suggestions. Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
* rdb.c: fix typo in a comment (#7970)Andrij Fedyk2020-10-271-1/+1
|
* Speedup cluster failover. (#7948)WuYunlong2020-10-272-11/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit deals with manual failover as well as non-manual failover. We did tests with manual failover as follows: 1, Setup redis cluster which holds 16 partions, each having only 1 corresponding replica. 2, Write a batch of data to redis cluster and make sure the redis is doing a active expire in serverCron. 3, Do a manual failover sequentially to each partions with a time interval of 3 minutes. 4, Collect logs and do some computaiton work. The result: case avgTime maxTime minTime C1 95.8ms 227ms 25ms C2 47.9ms 96ms 12ms C3 12.6ms 27ms 7ms Explanation case C1: All nodes use the version before optimization case C2: Masters use the elder version while replicas use the optimized version case C3: All nodes use the optimized version failover time: The time between when replica got a `manual failover request` and when it `won the failover election`. avgTime: average failover time maxTime: maximum failover time minTime: mimimum failover time ms: millisecond Co-authored-by: chendq8 <c.d_q@163.com>
* Only supress implitic fallthrough on GCC 7Madelyn Olson2020-10-261-1/+1
|
* Fix wrong zmalloc_size() assumption. (#7963)Yossi Gottlieb2020-10-261-3/+0
| | | | | | | | | | | | | | When using a system with no malloc_usable_size(), zmalloc_size() assumed that the heap allocator always returns blocks that are long-padded. This may not always be the case, and will result with zmalloc_size() returning a size that is bigger than allocated. At least in one case this leads to out of bound write, process crash and a potential security vulnerability. Effectively this does not affect the vast majority of users, who use jemalloc or glibc. This problem along with a (different) fix was reported by Drew DeVault.