redis/src
antirez 7eb850ef0e A reimplementation of blocking operation internals.
Redis provides support for blocking operations such as BLPOP or BRPOP.
This operations are identical to normal LPOP and RPOP operations as long
as there are elements in the target list, but if the list is empty they
block waiting for new data to arrive to the list.

All the clients blocked waiting for th same list are served in a FIFO
way, so the first that blocked is the first to be served when there is
more data pushed by another client into the list.

The previous implementation of blocking operations was conceived to
serve clients in the context of push operations. For for instance:

1) There is a client "A" blocked on list "foo".
2) The client "B" performs `LPUSH foo somevalue`.
3) The client "A" is served in the context of the "B" LPUSH,
synchronously.

Processing things in a synchronous way was useful as if "A" pushes a
value that is served by "B", from the point of view of the database is a
NOP (no operation) thing, that is, nothing is replicated, nothing is
written in the AOF file, and so forth.

However later we implemented two things:

1) Variadic LPUSH that could add multiple values to a list in the
context of a single call.
2) BRPOPLPUSH that was a version of BRPOP that also provided a "PUSH"
side effect when receiving data.

This forced us to make the synchronous implementation more complex. If
client "B" is waiting for data, and "A" pushes three elemnents in a
single call, we needed to propagate an LPUSH with a missing argument
in the AOF and replication link. We also needed to make sure to
replicate the LPUSH side of BRPOPLPUSH, but only if in turn did not
happened to serve another blocking client into another list ;)

This were complex but with a few of mutually recursive functions
everything worked as expected... until one day we introduced scripting
in Redis.

Scripting + synchronous blocking operations = Issue #614.

Basically you can't "rewrite" a script to have just a partial effect on
the replicas and AOF file if the script happened to serve a few blocked
clients.

The solution to all this problems, implemented by this commit, is to
change the way we serve blocked clients. Instead of serving the blocked
clients synchronously, in the context of the command performing the PUSH
operation, it is now an asynchronous and iterative process:

1) If a key that has clients blocked waiting for data is the subject of
a list push operation, We simply mark keys as "ready" and put it into a
queue.
2) Every command pushing stuff on lists, as a variadic LPUSH, a script,
or whatever it is, is replicated verbatim without any rewriting.
3) Every time a Redis command, a MULTI/EXEC block, or a script,
completed its execution, we run the list of keys ready to serve blocked
clients (as more data arrived), and process this list serving the
blocked clients.
4) As a result of "3" maybe more keys are ready again for other clients
(as a result of BRPOPLPUSH we may have push operations), so we iterate
back to step "3" if it's needed.

The new code has a much simpler semantics, and a simpler to understand
implementation, with the disadvantage of not being able to "optmize out"
a PUSH+BPOP as a No OP.

This commit will be tested with care before the final merge, more tests
will be added likely.
2012-09-17 10:26:46 +02:00
..
.gitignore Ignore gcov/lcov artifacts 2012-04-13 17:52:33 -07:00
Makefile First implementation of Redis Sentinel. 2012-07-23 13:14:44 +02:00
Makefile.dep Makefile.dep updated. 2012-04-11 12:12:30 +02:00
adlist.c Process async client checks like client timeouts and BLPOP timeouts incrementally using a circular list. 2012-03-13 18:05:11 +01:00
adlist.h Process async client checks like client timeouts and BLPOP timeouts incrementally using a circular list. 2012-03-13 18:05:11 +01:00
ae.c Set fd to writable when poll(2) detects POLLERR or POLLHUP event. 2012-05-23 11:33:32 +02:00
ae.h Max limit to 10k clients removed, this implements feature request on issue #194 2011-12-15 11:42:40 +01:00
ae_epoll.c mark fd as writable when EPOLLERR or EPOLLHUP is returned by epoll_wait. 2012-06-29 12:06:38 +08:00
ae_evport.c Whitespace 2012-05-15 11:19:01 +02:00
ae_kqueue.c Max limit to 10k clients removed, this implements feature request on issue #194 2011-12-15 11:42:40 +01:00
ae_select.c redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
anet.c First implementation of Redis Sentinel. 2012-07-23 13:14:44 +02:00
anet.h Added a config directive for a Unix socket mask 2011-10-10 11:21:15 -07:00
aof.c Merge pull request #587 from saj/truncate-short-write-from-aof 2012-07-27 03:56:48 -07:00
asciilogo.h ASCII ART FTW 2011-04-13 10:58:21 +02:00
bio.c Mask SIGALRM everything but in the main thread. 2012-03-27 13:48:57 +02:00
bio.h REDIS_BIO_AOF_FSYNC implemented 2011-09-15 18:25:53 +02:00
bitops.c BITCOUNT: fix segmentation fault. 2012-09-05 16:19:04 +02:00
cluster.c Better Out of Memory handling. 2012-08-24 12:55:37 +02:00
config.c Sentinel: Redis-side support for slave priority. 2012-08-28 17:20:26 +02:00
config.h Incrementally flush RDB on disk while loading it from a master. 2012-08-28 12:47:33 +02:00
crc16.c Exact variant of CRC16 specified into crc16.c 2011-10-02 14:05:29 +02:00
crc64.c crc64.c modified for incremental computation. 2012-04-09 12:20:47 +02:00
db.c Make sure that SELECT argument is an integer or return an error. 2012-09-11 10:32:04 +02:00
debug.c Better Out of Memory handling. 2012-08-24 12:55:37 +02:00
dict.c Even inside #if 0 comments are comments. 2012-04-21 21:49:21 +02:00
dict.h Fix for hash table collision attack. We simply randomize hash table initialization value at startup time. 2012-01-21 23:30:13 +01:00
endianconv.c endian.c/h -> endianconv.c/h to avoid issues with broken libraries search paths. 2012-02-14 16:11:46 +01:00
endianconv.h Add stdint.h in endianconv.h to fix issue #336. 2012-02-15 12:21:04 +01:00
fmacros.h Incrementally flush RDB on disk while loading it from a master. 2012-08-28 12:47:33 +02:00
help.h redis-cli commands description in help.h updated. 2012-04-27 15:57:27 +02:00
intset.c endian.c/h -> endianconv.c/h to avoid issues with broken libraries search paths. 2012-02-14 16:11:46 +01:00
intset.h encoded types API to get blob length 2011-02-28 14:48:49 +01:00
lzf.h redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
lzfP.h redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
lzf_c.c redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
lzf_d.c redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
memtest.c memtest.c fixed to actually use v1 and v2 in memtest_fill_value(). 2012-04-27 16:29:44 +02:00
mkreleasehdr.sh redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
multi.c Support for read-only slaves. Semantical fixes. 2012-03-20 17:32:48 +01:00
networking.c REPLCONF internal command introduced. 2012-06-27 09:43:57 +02:00
object.c remove mentions of VM in comments 2012-04-02 11:56:03 +02:00
pqsort.c redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
pqsort.h redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
pubsub.c Use less memory when emitting the protocol, by using more shared objects for commonly emitted parts of the protocol. 2012-02-04 08:58:37 +01:00
rand.c libc neutral random function derived from a drand48() implementation added. Will be used to replace Lua's math.random implementation. 2011-09-23 14:51:48 +02:00
rand.h Defined macro with bigger number that redisLrand48() can output. 2011-09-23 15:06:07 +02:00
rdb.c RDB type loading functions clarified in comments. 2012-06-02 10:21:57 +02:00
rdb.h Fixed RESTORE hash failure (Issue #532) 2012-06-02 10:24:27 +02:00
redis-benchmark.c redis-benchmark: disable big buffer cleanup in hiredis context. 2012-08-21 17:31:44 +02:00
redis-check-aof.c redis-check-aof is now large files safe also on 32 bit systems. 2012-02-14 19:57:51 +01:00
redis-check-dump.c redis-check-dump now is RDB version 6 ready. 2012-04-24 19:05:27 +02:00
redis-cli.c Check that we have connection before enabling pipe mode 2012-07-15 14:35:02 +02:00
redis-trib.rb redis-trib: fix the MIGRATE call that now has milliseconds timeout (were seconds before). 2012-03-31 11:28:37 +02:00
redis.c A reimplementation of blocking operation internals. 2012-09-17 10:26:46 +02:00
redis.h A reimplementation of blocking operation internals. 2012-09-17 10:26:46 +02:00
release.c redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
replication.c Merge pull request #576 from saj/fix-slave-ping-period 2012-09-05 06:59:37 -07:00
rio.c Fixed compilation of new rio.c changes (typos and so forth.) 2012-04-09 12:36:44 +02:00
rio.h Make inline functions rioRead/Write/Tell static. This fixes issue #447. 2012-04-11 11:58:32 +02:00
scripting.c Scripting: Force SORT BY constant determinism inside SORT itself. 2012-09-05 01:17:49 +02:00
sds.c Added consts keyword where possible 2012-03-30 21:19:51 +02:00
sds.h Added consts keyword where possible 2012-03-30 21:19:51 +02:00
sentinel.c Sentinel: reply -IDONTKNOW to get-master-addr-by-name on lack of info. 2012-09-04 16:06:53 +02:00
sha1.c byte ordering detection in config.h 2011-03-09 15:44:21 +01:00
sha1.h redis.c split into many different C files. 2010-07-01 14:38:51 +02:00
slowlog.c Limit memory used by big SLOWLOG entries. 2012-04-21 20:34:45 +02:00
slowlog.h Limit memory used by big SLOWLOG entries. 2012-04-21 20:34:45 +02:00
solarisfixes.h Fix for solaris compilation bug Issue 325 2010-09-06 10:12:44 +02:00
sort.c Scripting: Force SORT BY constant determinism inside SORT itself. 2012-09-05 01:17:49 +02:00
syncio.c syncio.c read / write functions reworked for correctness and performance. 2012-05-02 22:41:50 +02:00
t_hash.c Dump ziplist hex value on failed assertion. 2012-06-12 00:41:48 +02:00
t_list.c A reimplementation of blocking operation internals. 2012-09-17 10:26:46 +02:00
t_set.c Fixed some spelling errors in the comments 2012-04-07 14:40:29 +02:00
t_string.c Bit-related string operations moved to bitop.c 2012-05-24 15:19:51 +02:00
t_zset.c Fixed issue #516 (ZINTERSTORE mixing sets and zsets). 2012-05-23 11:12:43 +02:00
testhelp.h testhelp.h now exits with retcode 1 on failed tests. 2011-11-02 16:52:10 +01:00
util.c Use correct variable name for value to convert. 2012-07-31 11:48:00 +02:00
util.h string2* functions take a const pointer 2012-01-02 15:24:50 -08:00
valgrind.sup more valgrind friendly test 2011-07-06 15:22:00 +02:00
version.h Version 2.9.7. 2012-04-10 16:34:33 +02:00
ziplist.c Set p to its new offset before modifying it 2012-08-13 14:13:09 -07:00
ziplist.h Implements ziplistFind 2012-01-03 16:13:42 -08:00
zipmap.c Fixed some spelling errors in the comments 2012-04-07 14:40:29 +02:00
zipmap.h save zipmap encoded hashes as blobs. Work in progress. 2011-02-28 09:56:48 +01:00
zmalloc.c Fix a forget zmalloc_oom() -> zmalloc_oom_handler() replacement. 2012-08-24 15:40:22 +02:00
zmalloc.h Better Out of Memory handling. 2012-08-24 12:55:37 +02:00