474 Commits

Author SHA1 Message Date
Oran Agra
d92f14e825 allow dictFind using static robj
since the recent addition of OBJ_STATIC_REFCOUNT and the assertion in
incrRefCount it is now impossible to use dictFind using a static robj,
because dictEncObjKeyCompare will call getDecodedObject which tries to
increment the refcount just in order to decrement it later.
2020-04-28 11:20:15 +02:00
Madelyn Olson
1652f7b897 Implemented CRC64 based on slice by 4 2020-04-28 11:20:15 +02:00
antirez
a0c54d5622 Fix STRALGO command flags. 2020-04-27 15:52:49 +02:00
Dave-in-lafayette
1713328723 fix for unintended crash during panic response
If redis crashes early, before lua is set up (like, if File Descriptor 0 is closed before exec), it will crash again trying to print memory statistics.
2020-04-27 15:52:49 +02:00
antirez
262da0ba78 LCS -> STRALGO LCS.
STRALGO should be a container for mostly read-only string
algorithms in Redis. The algorithms should have two main
characteristics:

1. They should be non trivial to compute, and often not part of
programming language standard libraries.
2. They should be fast enough that it is a good idea to have optimized C
implementations.

Next thing I would love to see? A small strings compression algorithm.
2020-04-24 16:49:27 +02:00
antirez
0b1b56b6fc Fix XCLAIM propagation in AOF/replicas for blocking XREADGROUP.
See issue #7105.
2020-04-17 12:40:54 +02:00
antirez
3b373fbb0b Speedup: unblock clients on keys in O(1).
See #7071.
2020-04-15 16:03:16 +02:00
antirez
fdd6da647d Speedup INFO by counting client memory incrementally.
Related to #5145.

Design note: clients may change type when they turn into replicas or are
moved into the Pub/Sub category and so forth. Moreover the recomputation
of the bytes used is problematic for obvious reasons: it changes
continuously, so as a conservative way to avoid accumulating errors,
each client remembers the contribution it gave to the sum, and removes
it when it is freed or before updating it with the new memory usage.
2020-04-07 16:53:13 +02:00
antirez
087ed099d1 LCS: initial functionality implemented. 2020-04-07 16:52:57 +02:00
srzhao
c5d805f877 Check OOM at script start to get stable lua OOM state.
Checking OOM by `getMaxMemoryState` inside script might get different result
with `freeMemoryIfNeededAndSafe` at script start, because lua stack and
arguments also consume memory.

This leads to memory `borderline` when memory grows near server.maxmemory:

- `freeMemoryIfNeededAndSafe` at script start detects no OOM, no memory freed
- `getMaxMemoryState` inside script detects OOM, script aborted

We solve this 'borderline' issue by saving OOM state at script start to get
stable lua OOM state.

related to issue #6565 and #5250.
2020-04-07 16:52:28 +02:00
Valentino Geron
dc38619afb XREAD and XREADGROUP should not be allowed from scripts when BLOCK option is being used 2020-04-07 16:52:04 +02:00
Guy Benoish
115fd1136e Stale replica should allow MULTI/EXEC
Example: Client uses a pipe to send the following to a
stale replica:

MULTI
.. do something ...
DISCARD

The replica will reply the MUTLI with -MASTERDOWN and
execute the rest of the commands... A client using a
pipe might not be aware that MULTI failed until it's
too late.

I can't think of a reason why MULTI/EXEC/DISCARD should
not be executed on stale replicas...

Also, enable MULTI/EXEC/DISCARD during loading
2020-04-07 16:52:04 +02:00
antirez
81bf978d8c cast raxSize() to avoid warning with format spec. 2020-03-31 17:41:23 +02:00
antirez
c202c54ff7 Minor changes to #7037. 2020-03-31 17:12:19 +02:00
Guy Benoish
5c23cd55d4 Modules: Test MULTI/EXEC replication of RM_Replicate
Makse sure call() doesn't wrap replicated commands with
a redundant MULTI/EXEC

Other, unrelated changes:
1. Formatting compiler warning in INFO CLIENTS
2. Use CLIENT_ID_AOF instead of UINT64_MAX
2020-03-31 17:12:19 +02:00
antirez
514ca204bb Fix module commands propagation double MULTI bug.
b512cb40 introduced automatic wrapping of MULTI/EXEC for the
alsoPropagate API. However this collides with the built-in mechanism
already present in module.c. To avoid complex changes near Redis 6 GA
this commit introduces the ability to exclude call() MUTLI/EXEC wrapping
for also propagate in order to continue to use the old code paths in
module.c.
2020-03-31 16:57:20 +02:00
antirez
2a820251c8 timeout.c created: move client timeouts code there. 2020-03-31 16:57:20 +02:00
antirez
c881ba1680 Precise timeouts: cleaup the table on unblock.
Now that this mechanism is the sole one used for blocked clients
timeouts, it is more wise to cleanup the table when the client unblocks
for any reason. We use a flag: CLIENT_IN_TO_TABLE, in order to avoid a
radix tree lookup when the client was already removed from the table
because we processed it by scanning the radix tree.
2020-03-31 16:56:46 +02:00
antirez
0e5723ff18 Precise timeouts: fix comments after functional change. 2020-03-31 16:56:46 +02:00
antirez
444089c55e Precise timeouts: use only radix tree for timeouts. 2020-03-31 16:56:46 +02:00
antirez
c49ff92431 Precise timeouts: fast exit for clientsHandleShortTimeout(). 2020-03-31 16:56:46 +02:00
antirez
e512707aed Precise timeouts: fix bugs in initial implementation. 2020-03-31 16:56:46 +02:00
antirez
cedeec01f2 Precise timeouts: working initial implementation. 2020-03-31 16:56:46 +02:00
antirez
b636856df0 Precise timeouts: refactor unblocking on timeout. 2020-03-31 16:56:46 +02:00
伯成
2a13f59a18 Boost up performance for redis PUB-SUB patterns matching
If lots of clients PSUBSCRIBE to same patterns, multiple pattens matching will take place. This commit change it into just one single pattern matching by using a `dict *` to store the unique pattern and which clients subscribe to it.
2020-03-31 12:47:14 +02:00
antirez
ce73158a9c PSYNC2: meaningful offset implemented.
A very commonly signaled operational problem with Redis master-replicas
sets is that, once the master becomes unavailable for some reason,
especially because of network problems, many times it wont be able to
perform a partial resynchronization with the new master, once it rejoins
the partition, for the following reason:

1. The master becomes isolated, however it keeps sending PINGs to the
replicas. Such PINGs will never be received since the link connection is
actually already severed.
2. On the other side, one of the replicas will turn into the new master,
setting its secondary replication ID offset to the one of the last
command received from the old master: this offset will not include the
PINGs sent by the master once the link was already disconnected.
3. When the master rejoins the partion and is turned into a replica, its
offset will be too advanced because of the PINGs, so a PSYNC will fail,
and a full synchronization will be required.

Related to issue #7002 and other discussion we had in the past around
this problem.
2020-03-25 15:55:24 +01:00
antirez
45ba72ad01 Explain why we allow transactions in -BUSY state.
Related to #7022.
2020-03-25 15:55:24 +01:00
Oran Agra
e1e2f91589 MULTI/EXEC during LUA script timeout are messed up
Redis refusing to run MULTI or EXEC during script timeout may cause partial
transactions to run.

1) if the client sends MULTI+commands+EXEC in pipeline without waiting for
response, but these arrive to the shards partially while there's a busy script,
and partially after it eventually finishes: we'll end up running only part of
the transaction (since multi was ignored, and exec would fail).

2) similar to the above if EXEC arrives during busy script, it'll be ignored and
the client state remains in a transaction.

the 3rd test which i added for a case where MULTI and EXEC are ok, and
only the body arrives during busy script was already handled correctly
since processCommand calls flagTransaction
2020-03-25 15:55:24 +01:00
antirez
6a1a5cb2a1 Abort transactions after -READONLY error. Fix #7014. 2020-03-25 15:55:24 +01:00
bodong.ybd
015d1cb2ff Added BITFIELD_RO variants for read-only operations. 2020-03-25 15:55:24 +01:00
WuYunlong
37c6571a6c Fix master replica inconsistency for upgrading scenario.
Before this commit, when upgrading a replica, expired keys will not
be loaded, thus causing replica having less keys in db. To this point,
master and replica's keys is logically consistent. However, before
the keys in master and replica are physically consistent, that is,
they have the same dbsize, if master got a problem and the replica
got promoted and becomes new master of that partition, and master
updates a key which does not exist on master, but physically exists
on the old master(new replica), the old master would refuse to update
the key, thus causing master and replica data inconsistent.

How could this happen?
That's all because of the wrong judgement of roles while starting up
the server. We can not use server.masterhost to judge if the server
is master or replica, since it fails in cluster mode.

When we start the server, we load rdb and do want to load expired keys,
and do not want to have the ability to active expire keys, if it is
a replica.
2020-03-25 15:54:34 +01:00
antirez
21c22bcd9a ACL: default user off should not allow automatic authentication.
This fixes issue #7011.
2020-03-25 15:54:34 +01:00
zhaozhao.zz
db4f03bc51 Threaded IO: handle pending reads clients ASAP after event loop 2020-03-25 15:54:34 +01:00
antirez
e91ca9fee9 Remove RDB files used for replication in persistence-less instances. 2020-03-05 12:51:14 +01:00
Oran Agra
4ca389bb60 add no_auth to COMMAND INFO 2020-03-05 12:51:14 +01:00
antirez
7841d0234f Tracking: BCAST: basic feature now works. 2020-02-27 17:59:57 +01:00
antirez
ed36f3c76f Tracking: BCAST: parsing of the options + skeleton. 2020-02-27 17:59:57 +01:00
antirez
ddc4965ac5 Tracking: minor change of names and new INFO field. 2020-02-27 17:59:57 +01:00
antirez
e264fa8917 Tracking: rename INFO field with total items. 2020-02-27 17:59:57 +01:00
antirez
fce22c6a42 Tracking: first conversion from hashing to key names. 2020-02-27 17:59:57 +01:00
Oran Agra
ca22e14d8a A few non-data commands that should be allowed while loading or stale
SELECT, and HELLO are commands that may be executed by the client
as soon as it connects, there's no reason to block them, preventing the
client from doing the rest of his sequence (which might just be INFO or
CONFIG, etc).

MONITOR, DEBUG, SLOWLOG, TIME, LASTSAVE are all non-data accessing
commands, which there's no reason to block.
2020-02-12 14:17:40 +01:00
Guy Benoish
f4c30fd74b Fix small bugs related to replica and monitor ambiguity
1. server.repl_no_slaves_since can be set when a MONITOR client disconnects
2. c->repl_ack_time can be set by a newline from a MONITOR client
3. Improved comments
2020-02-12 14:15:56 +01:00
Oran Agra
138252dc56 memoryGetKeys helper function so that ACL can limit access to keys for MEMORY command 2020-02-12 14:15:56 +01:00
antirez
c0de265bfa ACL LOG: log failed auth attempts. 2020-02-12 14:15:35 +01:00
antirez
9f5b64c4a6 ACL LOG: actually emit entries. 2020-02-12 14:15:35 +01:00
antirez
2d06604451 ACL LOG: data structures and initial functions. 2020-02-12 14:15:35 +01:00
antirez
4048cf6125 Change error message for #6775. 2020-01-17 10:47:38 +01:00
Vasyl Melnychuk
037755edd4 Make error when submitting command in incorrect context more explicit
So error message `ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context` will become
`ERR 'get' command submitted, but only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context`
2020-01-17 10:47:38 +01:00
Salvatore Sanfilippo
95a43c2178 Merge pull request #6615 from soloestoy/wrap-also-propagate-as-multi
Wrap also propagate as multi
2019-12-19 09:24:52 +01:00
Salvatore Sanfilippo
3d344f9467 Merge pull request #6052 from jtru/better-systemd-integration-v2
Better systemd integration v2
2019-12-19 08:54:22 +01:00