summaryrefslogtreecommitdiff
path: root/src/hyperloglog.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-12-10 16:10:21 +0100
committerantirez <antirez@gmail.com>2014-12-10 16:10:21 +0100
commit06e76bc3e22dd72a30a8a614d367246b03ff1312 (patch)
treeed3fb494624895b7a705e008b0391ded504807b3 /src/hyperloglog.c
parent3da87b70ddb8c4ff49b3a32424baf24f0a88c2fa (diff)
downloadredis-06e76bc3e22dd72a30a8a614d367246b03ff1312.tar.gz
Better read-only behavior for expired keys in slaves.
Slaves key expire is orchestrated by the master. Sometimes the master will send the synthesized DEL to expire keys on the slave with a non trivial delay (when the key is not accessed, only the incremental expiry algorithm will expire it in background). During that time, a key is logically expired, but slaves still return the key if you GET (or whatever) it. This is a bad behavior. However we can't simply trust the slave view of the key, since we need the master to be able to send write commands to update the slave data set, and DELs should only happen when the key is expired in the master in order to ensure consistency. However 99.99% of the issues with this behavior is when a client which is not a master sends a read only command. In this case we are safe and can consider the key as non existing. This commit does a few changes in order to make this sane: 1. lookupKeyRead() is modified in order to return NULL if the above conditions are met. 2. Calls to lookupKeyRead() in commands actually writing to the data set are repliaced with calls to lookupKeyWrite(). There are redundand checks, so for example, if in "2" something was overlooked, we should be still safe, since anyway, when the master writes the behavior is to don't care about what expireIfneeded() returns. This commit is related to #1768, #1770, #2131.
Diffstat (limited to 'src/hyperloglog.c')
-rw-r--r--src/hyperloglog.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/hyperloglog.c b/src/hyperloglog.c
index a6cfdc742..b3542f997 100644
--- a/src/hyperloglog.c
+++ b/src/hyperloglog.c
@@ -1233,7 +1233,7 @@ void pfcountCommand(redisClient *c) {
*
* The user specified a single key. Either return the cached value
* or compute one and update the cache. */
- o = lookupKeyRead(c->db,c->argv[1]);
+ o = lookupKeyWrite(c->db,c->argv[1]);
if (o == NULL) {
/* No key? Cardinality is zero since no element was added, otherwise
* we would have a key as HLLADD creates it as a side effect. */
@@ -1458,7 +1458,7 @@ void pfdebugCommand(redisClient *c) {
robj *o;
int j;
- o = lookupKeyRead(c->db,c->argv[2]);
+ o = lookupKeyWrite(c->db,c->argv[2]);
if (o == NULL) {
addReplyError(c,"The specified key does not exist");
return;