Commit Graph

6783 Commits

Author SHA1 Message Date
meir@redislabs.com
a89bf734a9 Fix RM_ScanKey module api not to return int encoded strings
The scan key module API provides the scan callback with the current
field name and value (if it exists). Those arguments are RedisModuleString*
which means it supposes to point to robj which is encoded as a string.
Using createStringObjectFromLongLong function might return robj that
points to an integer and so break a module that tries for example to
use RedisModule_StringPtrLen on the given field/value.

The PR introduces a fix that uses the createObject function and sdsfromlonglong function.
Using those function promise that the field and value pass to the to the
scan callback will be Strings.

The PR also changes the Scan test module to use RedisModule_StringPtrLen
to catch the issue. without this, the issue is hidden because
RedisModule_ReplyWithString knows to handle integer encoding of the
given robj (RedisModuleString).

The PR also introduces a new test to verify the issue is solved.
2020-06-14 11:20:15 +03:00
antirez
1055398849 Fix LCS object type checking. Related to #7379. 2020-06-12 12:43:40 +02:00
Salvatore Sanfilippo
a66298e6f1
Merge pull request #7375 from hwware/lcs_crash_fix
Fix Server Crash in LCS Command
2020-06-12 12:31:15 +02:00
antirez
ca58198a76 help.h updated. 2020-06-12 12:16:19 +02:00
hwware
7008a0ba66 fix memory leak 2020-06-11 09:56:52 -04:00
antirez
0091125cae LPOS: tests + crash fix. 2020-06-11 12:39:06 +02:00
antirez
89ca2afd6b LPOS: update to latest proposal.
See https://gist.github.com/antirez/3591c5096bc79cad8b5a992e08304f48
2020-06-11 11:18:20 +02:00
antirez
e63a5ba122 LPOS: implement the final design. 2020-06-10 12:49:15 +02:00
Paul Spooren
a7936ef96d LRANK: Add command (the command will be renamed LPOS).
The `LRANK` command returns the index (position) of a given element
within a list. Using the `direction` argument it is possible to specify
going from head to tail (acending, 1) or from tail to head (decending,
-1). Only the first found index is returend. The complexity is O(N).

When using lists as a queue it can be of interest at what position a
given element is, for instance to monitor a job processing through a
work queue. This came up within the Python `rq` project which is based
on Redis[0].

[0]: https://github.com/rq/rq/issues/1197

Signed-off-by: Paul Spooren <mail@aparcar.org>
2020-06-10 12:07:40 +02:00
antirez
cdad0e6485 Temporary fix for #7353 issue about EVAL during -BUSY. 2020-06-09 11:52:33 +02:00
hwware
2a05fa0d48 fix server crash in STRALGO command 2020-06-08 23:36:01 -04:00
Salvatore Sanfilippo
48b2915c18
Merge pull request #7363 from xhebox/unstable
return the correct proto version
2020-06-08 12:54:15 +02:00
Salvatore Sanfilippo
254f06c131
Merge pull request #7370 from oranagra/no_queue_in_aborted_multi
Don't queue commands in an already aborted MULTI state
2020-06-08 11:08:08 +02:00
Salvatore Sanfilippo
8183a4ca7f
Merge pull request #7369 from oranagra/no_reject_watch
Avoid rejecting WATCH / UNWATCH, like MULTI/EXEC/DISCARD
2020-06-08 11:04:26 +02:00
Salvatore Sanfilippo
265a7e7ec7
Merge pull request #7357 from soloestoy/bugfix-aof-keepttl
AOF: append origin SET if no expire option
2020-06-08 11:02:00 +02:00
Salvatore Sanfilippo
cfffda83fb
Merge pull request #7371 from oranagra/fix_disconnectSlaves
fix disconnectSlaves, to try to free each slave.
2020-06-08 10:43:51 +02:00
Salvatore Sanfilippo
74a203a050
Merge pull request #7352 from soloestoy/donot-free-protected-client-when-blocking
donot free protected client in freeClientsInAsyncFreeQueue()
2020-06-08 10:43:17 +02:00
Oran Agra
12504105c4 fix disconnectSlaves, to try to free each slave.
the recent change in that loop (iteration rather than waiting for it to
be empty) was intended to avoid an endless loop in case some slave would
refuse to be freed.

but the lookup of the first client remained, which would have caused it
to try the first one again and again instead of moving on.
2020-06-08 09:50:06 +03:00
Oran Agra
2bb297b102 Don't queue commands in an already aborted MULTI state 2020-06-08 09:43:10 +03:00
Oran Agra
2fa077b0e9 Avoid rejecting WATCH / UNWATCH, like MULTI/EXEC/DISCARD
Much like MULTI/EXEC/DISCARD, the WATCH and UNWATCH are not actually
operating on the database or server state, but instead operate on the
client state. the client may send them all in one long pipeline and check
all the responses only at the end, so failing them may lead to a
mismatch between the client state on the server and the one on the
client end, and execute the wrong commands (ones that were meant to be
discarded)

the watched keys are not actually stored in the client struct, but they
are in fact part of the client state. for instance, they're not cleared
or moved in SWAPDB or FLUSHDB.
2020-06-08 09:16:32 +03:00
xhe
7eba5c308a return the correct proto version
HELLO should return the current proto version, while the code hardcoded
3
2020-06-07 13:34:55 +08:00
antirez
44b76a75d2 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-06-06 11:44:05 +02:00
antirez
61074b43a6 Revert "Implements sendfile for redis."
This reverts commit 9cf500a3f6.
2020-06-06 11:42:45 +02:00
antirez
d1e23e04aa Revert "avoid using sendfile if tls-replication is enabled"
This reverts commit b9abecfc4c.
2020-06-06 11:42:41 +02:00
zhaozhao.zz
5d0774d62f AOF: append origin SET if no expire option 2020-06-03 17:55:18 +08:00
zhaozhao.zz
ad6b71352d donot free protected client in freeClientsInAsyncFreeQueue
related #7234
2020-06-02 11:48:14 +08:00
Salvatore Sanfilippo
f644b112ad
Merge pull request #7334 from kevin-fwu/tls_load_chained_certs
Fix TLS certificate loading for chained certificates.
2020-05-31 14:32:56 +02:00
antirez
bdd5411747 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-05-29 11:09:15 +02:00
antirez
1f8ea99b4b Fix handling of special chars in ACL LOAD.
Now it is also possible for ACL SETUSER to accept empty strings
as valid operations (doing nothing), so for instance

    ACL SETUSER myuser ""

Will have just the effect of creating a user in the default state.

This should fix #7329.
2020-05-29 11:07:13 +02:00
Salvatore Sanfilippo
5ef157bae1
Merge pull request #7330 from liuzhen/unstable
fix clusters mixing accidentally by gossip
2020-05-29 10:15:26 +02:00
antirez
6a16a636bf Replication: showLatestBacklog() refactored out. 2020-05-28 10:08:16 +02:00
antirez
484af8ed53 Drop useless line from replicationCacheMaster(). 2020-05-27 17:08:51 +02:00
Kevin Fwu
151b12a80f Fix TLS certificate loading for chained certificates.
This impacts client verification for chained certificates (such as Lets
Encrypt certificates). Client Verify requires the full chain in order to
properly verify the certificate.
2020-05-27 08:53:29 -04:00
antirez
22472fe5a1 Remove the meaningful offset feature.
After a closer look, the Redis core devleopers all believe that this was
too fragile, caused many bugs that we didn't expect and that were very
hard to track. Better to find an alternative solution that is simpler.
2020-05-27 12:06:33 +02:00
antirez
325409a011 Set a protocol error if master use the inline protocol.
We want to react a bit more aggressively if we sense that the master is
sending us some corrupted stream. By setting the protocol error we both
ensure that the replica will disconnect, and avoid caching the master so
that a full SYNC will be required. This is protective against
replication bugs.
2020-05-27 11:45:49 +02:00
Liu Zhen
3984dc6539 fix clusters mixing accidentally by gossip
`clusterStartHandshake` will start hand handshake
and eventually send CLUSTER MEET message, which is strictly prohibited
in the REDIS CLUSTER SPEC.
Only system administrator can initiate CLUSTER MEET message.
Futher, according to the SPEC, rather than IP/PORT pairs, only nodeid
can be trusted.
2020-05-27 12:01:40 +08:00
antirez
94c026cd19 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-05-26 23:55:52 +02:00
antirez
7d35939206 Replication: log backlog creation event. 2020-05-26 23:55:18 +02:00
Salvatore Sanfilippo
caf7c50408
Merge pull request #7328 from oranagra/daily_tls_test
avoid using sendfile if tls-replication is enabled
2020-05-26 13:19:55 +02:00
Oran Agra
b9abecfc4c avoid using sendfile if tls-replication is enabled
this obviously broke the tests, but went unnoticed so far since tls
wasn't often tested.
2020-05-26 13:52:06 +03:00
antirez
92a3ff6168 Clarify what is happening in PR #7320. 2020-05-25 11:47:38 +02:00
zhaozhao.zz
eec769be59 PSYNC2: second_replid_offset should be real meaningful offset
After adjustMeaningfulReplOffset(), all the other related variable
should be updated, including server.second_replid_offset.

Or the old version redis like 5.0 may receive wrong data from
replication stream, cause redis 5.0 can sync with redis 6.0,
but doesn't know meaningful offset.
2020-05-25 11:17:54 +08:00
antirez
adc5df1bc3 Make disconnectSlaves() synchronous in the base case.
Otherwise we run into that:

Backtrace:
src/redis-server 127.0.0.1:21322(logStackTrace+0x45)[0x479035]
src/redis-server 127.0.0.1:21322(sigsegvHandler+0xb9)[0x4797f9]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7fd373c5e390]
src/redis-server 127.0.0.1:21322(_serverAssert+0x6a)[0x47660a]
src/redis-server 127.0.0.1:21322(freeReplicationBacklog+0x42)[0x451282]
src/redis-server 127.0.0.1:21322[0x4552d4]
src/redis-server 127.0.0.1:21322[0x4c5593]
src/redis-server 127.0.0.1:21322(aeProcessEvents+0x2e6)[0x42e786]
src/redis-server 127.0.0.1:21322(aeMain+0x1d)[0x42eb0d]
src/redis-server 127.0.0.1:21322(main+0x4c5)[0x42b145]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fd3738a3830]
src/redis-server 127.0.0.1:21322(_start+0x29)[0x42b409]

Since we disconnect all the replicas and free the replication backlog in
certain replication paths, and the code that will free the replication
backlog expects that no replica is connected.

However we still need to free the replicas asynchronously in certain
cases, as documented in the top comment of disconnectSlaves().
2020-05-22 19:29:09 +02:00
antirez
07c6bee78f Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-05-22 16:31:05 +02:00
antirez
b407590cee Fix #7306 less aggressively.
Citing from the issue:

btw I suggest we change this fix to something else:
* We revert the fix.
* We add a call that disconnects chained replicas in the place where we trim the replica (that is a master i this case) offset.
This way we can avoid disconnections when there is no trimming of the backlog.

Note that we now want to disconnect replicas asynchronously in
disconnectSlaves(), because it's in general safer now that we can call
it from freeClient(). Otherwise for instance the command:

    CLIENT KILL TYPE master

May crash: clientCommand() starts running the linked of of clients,
looking for clients to kill. However it finds the master, kills it
calling freeClient(), but this in turn calls replicationCacheMaster()
that may also call disconnectSlaves() now. So the linked list iterator
of the clientCommand() will no longer be valid.
2020-05-22 16:29:53 +02:00
Salvatore Sanfilippo
40161553e2
Merge pull request #7096 from ShooterIT/sendfile
Implements sendfile for redis.
2020-05-22 13:55:46 +02:00
Salvatore Sanfilippo
285817b28a
Merge pull request #7305 from madolson/unstable-connection
EAGAIN not handled for TLS during diskless load
2020-05-22 12:25:40 +02:00
Qu Chen
42f5da5d2d Disconnect chained replicas when the replica performs PSYNC with the master always to avoid replication offset mismatch between master and chained replicas. 2020-05-21 18:42:10 -07:00
Madelyn Olson
5109f16b77 EAGAIN for tls during diskless load 2020-05-21 15:20:59 -07:00
hwware
06a59fd44d using moreargs variable 2020-05-21 18:13:35 -04:00
hwware
5edb1beb63 fix server crash for STRALGO command 2020-05-21 17:30:36 -04:00
Salvatore Sanfilippo
fe640e5858
Merge pull request #7300 from ShooterIT/comment
Replace 'addDeferredMultiBulkLength' with 'addReplyDeferredLen' in comment
2020-05-21 15:53:01 +02:00
Salvatore Sanfilippo
9f932bcc82
Merge pull request #7299 from ShooterIT/reply-bytes
Fix reply bytes calculation error on 32bit platform
2020-05-21 15:47:15 +02:00
ShooterIT
86f0e873c7 Replace addDeferredMultiBulkLength with addReplyDeferredLen in comment 2020-05-21 21:45:35 +08:00
ShooterIT
9018ddc32a Fix reply bytes calculation error
Fix #7275.
2020-05-21 21:00:30 +08:00
zhaozhao.zz
4f3ff46a81 Tracking: flag CLIENT_TRACKING_BROKEN_REDIR when redir broken 2020-05-21 13:57:29 +08:00
Oran Agra
88d71f4793 fix a rare active defrag edge case bug leading to stagnation
There's a rare case which leads to stagnation in the defragger, causing
it to keep scanning the keyspace and do nothing (not moving any
allocation), this happens when all the allocator slabs of a certain bin
have the same % utilization, but the slab from which new allocations are
made have a lower utilization.

this commit fixes it by removing the current slab from the overall
average utilization of the bin, and also eliminate any precision loss in
the utilization calculation and move the decision about the defrag to
reside inside jemalloc.

and also add a test that consistently reproduce this issue.
2020-05-20 16:04:42 +03:00
Oran Agra
5d83e9e1de improve DEBUG MALLCTL to be able to write to write only fields.
also support:
  debug mallctl-str thread.tcache.flush VOID
2020-05-20 14:09:22 +03:00
Salvatore Sanfilippo
23a85ba191
Merge pull request #7276 from hujiecs/fix-clear-all-command-flag-in-acl
fix clear USER_FLAG_ALLCOMMANDS flag in acl
2020-05-19 16:19:28 +02:00
Salvatore Sanfilippo
d949e8fe18
Merge pull request #7196 from ShooterIT/benchmark
Redis Benchmark: make test data better
2020-05-19 16:16:38 +02:00
hwware
07e1417ef0 Redis-Benchmark: avoid potentical memmory leaking 2020-05-18 22:10:57 -04:00
hujie
edc1f7b176 fix clear USER_FLAG_ALLCOMMANDS flag in acl
in ACLSetUserCommandBit, when the command bit overflows, no operation
is performed, so no need clear the USER_FLAG_ALLCOMMANDS flag.

in ACLSetUser, when adding subcommand, we don't need to call
ACLGetCommandID ahead since subcommand may be empty.
2020-05-19 00:58:58 +08:00
ShooterIT
abff264000 Redis Benchmark: generate random test data
The function of generating random data is designed by antirez. See #7196.
2020-05-18 18:18:27 +08:00
Salvatore Sanfilippo
bf3a67be43
Merge pull request #7252 from ShooterIT/dictsize
Use dictSize to get the size of dict in dict.c
2020-05-18 10:33:08 +02:00
Salvatore Sanfilippo
dd78f7463f
Merge pull request #7255 from madolson/dev-unstable-converge-hash-validation
Converge hash validation for adding and removing
2020-05-18 10:31:47 +02:00
Salvatore Sanfilippo
c9ef9f1c48
Merge pull request #7247 from bsergean/patch-3
Redis-cli 6.0.1 `--cluster-yes` doesn't work (fix #7246)
2020-05-18 10:23:54 +02:00
antirez
624742d9b4 Remove the client from CLOSE_ASAP list before caching the master.
This was broken in 1a7cd2c: we identified a crash in the CI, what
was happening before the fix should be like that:

1. The client gets in the async free list.
2. However freeClient() gets called again against the same client
   which is a master.
3. The client arrived in freeClient() with the CLOSE_ASAP flag set.
4. The master gets cached, but NOT removed from the CLOSE_ASAP linked
   list.
5. The master client that was cached was immediately removed since it
   was still in the list.
6. Redis accessed a freed cached master.

This is how the crash looked like:

=== REDIS BUG REPORT START: Cut & paste starting from here ===
1092:S 16 May 2020 11:44:09.731 # Redis 999.999.999 crashed by signal: 11
1092:S 16 May 2020 11:44:09.731 # Crashed running the instruction at: 0x447e18
1092:S 16 May 2020 11:44:09.731 # Accessing address: 0xffffffffffffffff
1092:S 16 May 2020 11:44:09.731 # Failed assertion:  (:0)

------ STACK TRACE ------
EIP:
src/redis-server 127.0.0.1:21300(readQueryFromClient+0x48)[0x447e18]

And the 0xffff address access likely comes from accessing an SDS that is
set to NULL (we go -1 offset to read the header).
2020-05-16 17:15:35 +02:00
antirez
3cd92e87d1 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-05-15 10:21:51 +02:00
antirez
1a7cd2c0e2 Cache master without checking of deferred close flags.
The context is issue #7205: since the introduction of threaded I/O we close
clients asynchronously by default from readQueryFromClient(). So we
should no longer prevent the caching of the master client, to later
PSYNC incrementally, if such flags are set. However we also don't want
the master client to be cached with such flags (would be closed
immediately after being restored). And yet we want a way to understand
if a master was closed because of a protocol error, and in that case
prevent the caching.
2020-05-15 10:19:13 +02:00
Benjamin Sergeant
f4d2abd3df do not handle --cluster-yes for cluster fix mode 2020-05-14 15:29:06 -07:00
Madelyn Olson
f0f30fc43f Converge hash validation for adding and removing 2020-05-14 11:07:51 -07:00
Salvatore Sanfilippo
112e19a59c
Merge pull request #7230 from yossigo/tls-crypto-locks
TLS: Add crypto locks for older OpenSSL support.
2020-05-14 18:14:49 +02:00
Salvatore Sanfilippo
67a4fb912f
Merge pull request #7244 from devnexen/netbsd_build_fix
NetBSD build update.
2020-05-14 18:14:06 +02:00
Madelyn Olson
41cabca2ab Added a refcount on timer events to prevent deletion of recursive timer calls 2020-05-14 08:49:11 -07:00
antirez
c38fd1f661 Merge branch 'free_clients_during_loading' into unstable 2020-05-14 11:28:08 +02:00
antirez
3e6acc24d6 rax.c updated from upstream antirez/rax. 2020-05-14 11:17:47 +02:00
antirez
a4d0720fa1 Tracking: send eviction messages when evicting entries.
A fix for #7249.
2020-05-14 11:17:04 +02:00
antirez
bc4667acbc Track events processed while blocked globally.
Related to #7234.
2020-05-14 10:06:27 +02:00
Benjamin Sergeant
db39b04d76 fix typo ... 2020-05-13 09:32:27 -07:00
Benjamin Sergeant
827e6cc644
Redis-cli 6.0.1 --cluster-yes doesn't work (fix #7246)
This make it so that all prompts for all redis-cli --cluster commands are automatically answered with a yes.
2020-05-13 09:24:51 -07:00
David Carlier
4715ce5903 NetBSD build update.
This platform supports CPU affinity (but not OpenBSD).
2020-05-12 21:21:22 +01:00
antirez
27e25e9d1e Some rework of #7234. 2020-05-12 13:07:44 +02:00
Oran Agra
905e28ee87 fix redis 6.0 not freeing closed connections during loading.
This bug was introduced by a recent change in which readQueryFromClient
is using freeClientAsync, and despite the fact that now
freeClientsInAsyncFreeQueue is in beforeSleep, that's not enough since
it's not called during loading in processEventsWhileBlocked.
furthermore, afterSleep was called in that case but beforeSleep wasn't.

This bug also caused slowness sine the level-triggered mode of epoll
kept signaling these connections as readable causing us to keep doing
connRead again and again for ll of these, which keep accumulating.

now both before and after sleep are called, but not all of their actions
are performed during loading, some are only reserved for the main loop.

fixes issue #7215
2020-05-11 11:33:46 +03:00
Yossi Gottlieb
450f0d7248 TLS: Add crypto locks for older OpenSSL support.
This is really required only for older OpenSSL versions.

Also, at the moment Redis does not use OpenSSL from multiple threads so
this will only be useful if modules end up doing that.
2020-05-10 17:40:31 +03:00
antirez
1750513ac7 Merge branch 'unstable' of github.com:/antirez/redis into unstable 2020-05-09 11:13:32 +02:00
antirez
4387ba6a17 Cluster: clarify we always resolve the sender. 2020-05-09 11:12:51 +02:00
antirez
79de9d6c78 Cluster: refactor ping/data delay handling. 2020-05-09 11:10:38 +02:00
antirez
00a3bc4359 Cluster: introduce data_received field.
We want to send pings and pongs at specific intervals, since our packets
also contain information about the configuration of the cluster and are
used for gossip. However since our cluster bus is used in a mixed way
for data (such as Pub/Sub or modules cluster messages) and metadata,
sometimes a very busy channel may delay the reception of pong packets.
So after discussing it in #7216, this commit introduces a new field that
is not exposed in the cluster, is only an internal information about
the last time we received any data from a given node: we use this field
in order to avoid detecting failures, claiming data reception of new
data from the node is a proof of liveness.
2020-05-09 11:10:35 +02:00
Salvatore Sanfilippo
5fa6f9ebe1
Merge pull request #7204 from ShooterIT/benchmark-fix
Redis Benchmark: Fix coredump because of double free
2020-05-08 10:53:20 +02:00
ShooterIT
4afa243ff1 Use dictSize to get the size of dict in dict.c 2020-05-07 11:04:08 +08:00
antirez
e17f9311c8 stringmatchlen() should not expect null terminated strings. 2020-05-06 16:18:21 +02:00
Salvatore Sanfilippo
2e2f57e23b
Merge pull request #7201 from braddunbar/stringmatchlen
Remove unreachable branch.
2020-05-06 16:17:10 +02:00
hwware
24173d11bf add include guard for lolwut.h 2020-05-05 23:35:08 -04:00
Salvatore Sanfilippo
54cb8214d9
Merge pull request #7175 from bsergean/bsergean-patch-1
redis-cli cluster reshard does not work with ACL (AUTH2 MIGRATE args un-implemented)
2020-05-05 18:22:24 +02:00
ShooterIT
150ba0e1ff Redis Benchmark: Fix coredump because of double free 2020-05-05 23:09:45 +08:00
Brad Dunbar
5508c228e7
Remove unreachable branch. 2020-05-05 09:57:01 -04:00
antirez
373a3384ac Don't propagate spurious MULTI on DEBUG LOADAOF. 2020-05-05 15:50:00 +02:00
antirez
51ab31dbab Dump recent backlog on master query generating errors. 2020-05-05 13:40:33 +02:00
Titouan Christophe
1f246bfcc8 make struct user anonymous (only typedefed)
This works because this struct is never referenced by its name,
but always by its type.

This prevents a conflict with struct user from <sys/user.h>
when compiling against uclibc.

Signed-off-by: Titouan Christophe <titouan.christophe@railnova.eu>
2020-05-05 11:35:03 +02:00
Salvatore Sanfilippo
140c20fb5e
Merge pull request #7197 from bsergean/patch-1
Add --user argument to redis-benchmark.c (ACL)
2020-05-05 10:28:35 +02:00