From d303bca58787300efe29212940e7806ee625ae9f Mon Sep 17 00:00:00 2001 From: Suraj Narkhede Date: Thu, 22 Jun 2017 23:52:00 -0700 Subject: [PATCH 1/2] Fix brpop command table entry and redirect blocked clients. --- src/cluster.c | 3 ++- src/server.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 77ec2f1b..56af347b 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -5418,8 +5418,9 @@ int clusterRedirectBlockedClientIfNeeded(client *c) { return 1; } + /* All keys must belong to the same slot, so check first key only. */ di = dictGetIterator(c->bpop.keys); - while((de = dictNext(di)) != NULL) { + if ((de = dictNext(di)) != NULL) { robj *key = dictGetKey(de); int slot = keyHashSlot((char*)key->ptr, sdslen(key->ptr)); clusterNode *node = server.cluster->slots[slot]; diff --git a/src/server.c b/src/server.c index a3c13284..46e5bb9f 100644 --- a/src/server.c +++ b/src/server.c @@ -152,7 +152,7 @@ struct redisCommand redisCommandTable[] = { {"linsert",linsertCommand,5,"wm",0,NULL,1,1,1,0,0}, {"rpop",rpopCommand,2,"wF",0,NULL,1,1,1,0,0}, {"lpop",lpopCommand,2,"wF",0,NULL,1,1,1,0,0}, - {"brpop",brpopCommand,-3,"ws",0,NULL,1,1,1,0,0}, + {"brpop",brpopCommand,-3,"ws",0,NULL,1,-2,1,0,0}, {"brpoplpush",brpoplpushCommand,4,"wms",0,NULL,1,2,1,0,0}, {"blpop",blpopCommand,-3,"ws",0,NULL,1,-2,1,0,0}, {"llen",llenCommand,2,"rF",0,NULL,1,1,1,0,0}, From f85f36f50d7066bc7b3a845488a90e9ad3f1625d Mon Sep 17 00:00:00 2001 From: Suraj Narkhede Date: Fri, 23 Jun 2017 00:30:21 -0700 Subject: [PATCH 2/2] Fix following issues in blocking commands: 1. brpop last key index, thus checking all keys for slots. 2. Memory leak in clusterRedirectBlockedClientIfNeeded. 3. Remove while loop in clusterRedirectBlockedClientIfNeeded. --- src/cluster.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cluster.c b/src/cluster.c index 56af347b..407ddee8 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -5438,6 +5438,7 @@ int clusterRedirectBlockedClientIfNeeded(client *c) { clusterRedirectClient(c,node,slot, CLUSTER_REDIR_MOVED); } + dictReleaseIterator(di); return 1; } }