447 Commits

Author SHA1 Message Date
antirez
694cc141d5 Fix a race that may lead to the active (slave) client to be freed.
In issue #2948 a crash was reported in processCommand(). Later Oran Agra
(@oranagra) traced the bug (in private chat) in the following sequence
of events:

1. Some maxmemory is set.
2. The slave is the currently active client and is executing PING or
   REPLCONF or whatever a slave can send to its master.
3. freeMemoryIfNeeded() is called since maxmemory is set.
4. flushSlavesOutputBuffers() is called by freeMemoryIfNeeded().
5. During slaves buffers flush, a write error could be encoutered in
   writeToClient() or sendReplyToClient() depending on the version of
   Redis. This will trigger freeClient() against the currently active
   client, so a segmentation fault will likely happen in
   processCommand() immediately after the call to freeMemoryIfNeeded().

There are different possible fixes:

1. Add flags to writeToClient() (recent versions code base) so that
   we can ignore the write errors, and use this flag in
   flushSlavesOutputBuffers(). However this is not simple to do in older
   versions of Redis.
2. Use freeClientAsync() during write errors. This works but changes the
   current behavior of releasing clients ASAP when possible. Normally
   we write to clients during the normal event loop processing, in the
   writable client, where there is no active client, so no care must be
   taken.
3. The fix of this commit: to detect that the current client is no
   longer valid. This fix is a bit "ad-hoc", but works across all the
   versions and has the advantage of not changing the remaining
   behavior. Only alters what happens during this race condition,
   hopefully.
2015-12-17 09:39:43 +01:00
antirez
3f563bf30c Fix processCommand() comment about return value. 2015-12-17 09:22:16 +01:00
antirez
47cb5c697b MIGRATE: Fix key extraction for new form. 2015-12-11 18:09:01 +01:00
antirez
e3c11c1198 Handle wait3() errors.
My guess was that wait3() with WNOHANG could never return -1 and an
error. However issue #2897 may possibly indicate that this could happen
under non clear conditions. While we try to understand this better,
better to handle a return value of -1 explicitly, otherwise in the
case a BGREWRITE is in progress but wait3() returns -1, the effect is to
match the first branch of the if/else block since server.rdb_child_pid
is -1, and call backgroundSaveDoneHandler() without a good reason, that
will, in turn, crash the Redis server with an assertion.
2015-11-27 16:11:05 +01:00
antirez
76fd26e778 Lua debugger: call wait3() if there are pending forked debugging sessions. 2015-11-17 15:43:23 +01:00
antirez
5c05038252 Lua debugger: handle forked sessions children during shutdown. 2015-11-17 15:43:22 +01:00
antirez
063bbc8074 Lua debugger: foundations implemented. 2015-11-17 15:43:20 +01:00
antirez
6adc1fe86a Remove "s" flag for MIGRATE in command table.
Maybe there are legitimate use cases for MIGRATE inside Lua scripts, at
least for now. When the command will be executed in an asynchronous
fashion (planned) it is possible we'll no longer be able to permit it
from within Lua scripts.
2015-11-17 15:43:13 +01:00
antirez
aa2785936f Fix MIGRATE entry in command table.
Thanks to Oran Agra (@oranagra) for reporting. Key extraction would not
work otherwise and it does not make sense to take wrong data in the
command table.
2015-11-17 15:33:09 +01:00
antirez
b56cc1b939 call() deserves a good top-comment. 2015-11-10 13:31:25 +01:00
antirez
dd9955a080 Best effort flush of slave buffers before SHUTDOWN. 2015-11-09 17:26:58 +01:00
antirez
f741c4871e Fix error reply in subscribed Pub/Sub mode.
PING is now a valid command to issue in this context.
2015-11-09 11:10:53 +01:00
antirez
e8eb45509e Initialize all Lua scripting related things into scripting.c 2015-11-05 11:37:39 +01:00
antirez
169e86f9b1 Scripting: ability to turn on Lua commands style replication globally.
Currently this feature is only accessible via DEBUG for testing, since
otherwise depending on the instance configuration a given script works
or is broken, which is against the Redis philosophy.
2015-10-30 12:06:09 +01:00
antirez
721f612918 Fix call() FORCE_REPL/AOF flags setting.
This commit also inverts two stanzas of the code just becuase they are
more logical like that, not because currently it makes any difference.
2015-10-30 12:06:08 +01:00
antirez
7d05c2d795 Lua script selective replication fixes. 2015-10-30 12:06:08 +01:00
antirez
24103bafd0 Scripting: single commands replication mode implemented.
By calling redis.replicate_commands(), the scripting engine of Redis
switches to commands replication instead of replicating whole scripts.
This is useful when the script execution is costly but only results in a
few writes performed to the dataset.

Morover, in this mode, it is possible to call functions with side
effects freely, since the script execution does not need to be
deterministic: anyway we'll capture the outcome from the point of view
of changes to the dataset.

In this mode math.random() returns different sequences at every call.

If redis.replicate_commnads() is not called before any other write, the
command returns false and sticks to whole scripts replication instead.
2015-10-30 12:06:08 +01:00
antirez
52b4464ed6 call(): selective ability to prevent propagation on AOF / slaves. 2015-10-30 12:06:08 +01:00
antirez
78d342ec30 call(): don't inherit CLIENT_PREVENT_PROP + minor refactoring. 2015-10-30 12:06:08 +01:00
antirez
9fc48ed151 DEBUG RESTART/CRASH-AND-RECOVER [delay] implemented. 2015-10-13 11:12:25 +02:00
antirez
5b7bd883e6 Server: restartServer() API.
This new function is able to restart the server "in place". The current
Redis process executes the same executable it was executed with, using
the same arguments and configuration file.
2015-10-13 11:02:35 +02:00
antirez
27ec5105eb Lazyfree: cond vars to enabled/disable it based on DEL context. 2015-10-02 15:27:57 +02:00
antirez
93da3c7874 FLUSHDB and FLUSHALL ASYNC option implemented. 2015-10-01 13:02:26 +02:00
antirez
da103b45ed Lazyfree: pending objects count in INFO output. 2015-10-01 13:02:26 +02:00
antirez
7babd6e184 Lazyfree: incremental removed, only threaded survived. 2015-10-01 13:02:25 +02:00
antirez
fbc46738f4 Threaded lazyfree WIP #1. 2015-10-01 13:02:25 +02:00
antirez
5eb85d8fe7 Lazyfree: Hash converted to use plain SDS WIP 4. 2015-10-01 13:02:25 +02:00
antirez
5fd01e29d9 Lazyfree: Hash converted to use plain SDS WIP 1. 2015-10-01 13:02:24 +02:00
antirez
c4175281f6 Lazyfree: Sorted sets convereted to plain SDS. (several commits squashed) 2015-10-01 13:02:24 +02:00
antirez
062bf5ce19 Lazyfree: Convert Sets to use plains SDS (several commits squashed). 2015-10-01 13:02:24 +02:00
antirez
ca8d13bd90 Lazyfree: a first implementation of non blocking DEL. 2015-10-01 13:00:19 +02:00
antirez
7a7b8bc244 Move handleClientsWithPendingWrites() in networking.c. 2015-09-30 16:29:42 +02:00
antirez
e5121eba31 Avoid installing the client write handler when possible. 2015-09-30 16:29:41 +02:00
antirez
e32a7ab492 checkTcpBacklogSetting() now called in Sentinel mode too. 2015-07-29 12:13:20 +02:00
antirez
3af2851586 CLIENT_MASTER introduced. 2015-07-28 16:58:35 +02:00
antirez
4fc564cc98 RDMF: Redis -> Server in adjustOpenFilesLimit(). 2015-07-28 11:19:20 +02:00
antirez
3bb9900bbc Avoid magic "0" argument to prepareForShutdown().
Backported from Disque.
2015-07-28 11:10:42 +02:00
antirez
6976e49063 RDMF: dictRedisObjectDestructor -> dictObjectDestructor." 2015-07-28 11:03:01 +02:00
antirez
5dfb7f6632 Use mstime_t as return value of mstime(). 2015-07-28 10:14:33 +02:00
antirez
3064487047 RDMF: more names updated. 2015-07-27 15:03:10 +02:00
antirez
c15cac0d77 RDMF: More consistent define names. 2015-07-27 14:37:58 +02:00
antirez
8a893fa4cf RDMF: REDIS_OK REDIS_ERR -> C_OK C_ERR. 2015-07-26 23:17:55 +02:00
antirez
58844a7bfe RDMF: redisAssert -> serverAssert. 2015-07-26 15:29:53 +02:00
antirez
62b27ebc2a RDMF: OBJ_ macros for object related stuff. 2015-07-26 15:28:00 +02:00
antirez
fa26d3dd63 RDMF: use client instead of redisClient, like Disque. 2015-07-26 15:20:52 +02:00
antirez
e2b858a580 RDMF: redisLog -> serverLog. 2015-07-26 15:17:43 +02:00
antirez
6a424b5e36 RDMF (Redis/Disque merge friendlyness) refactoring WIP 1. 2015-07-26 15:17:18 +02:00