From ea7fc82a4a89d5d28217bcc751675d5f91e06db0 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 20 Feb 2013 17:28:35 +0100 Subject: [PATCH] Cluster: new command flag forcing implicit ASKING. Also using this new flag the RESTORE-ASKING command was implemented that will be used by MIGRATE. --- src/cluster.c | 2 +- src/redis.c | 4 ++++ src/redis.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cluster.c b/src/cluster.c index 5c25d8d3f..b17a8489f 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -2007,7 +2007,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg * it is assigned to a different node, but only if the client * issued an ASKING command before. */ if (server.cluster->importing_slots_from[slot] != NULL && - c->flags & REDIS_ASKING) { + (c->flags & REDIS_ASKING || cmd->flags & REDIS_CMD_ASKING)) { return server.cluster->myself; } /* It's not a -ASK case. Base case: just return the right node. */ diff --git a/src/redis.c b/src/redis.c index 9bc797d16..e398fa5da 100644 --- a/src/redis.c +++ b/src/redis.c @@ -111,6 +111,8 @@ struct redisCommand *commandTable; * server this data. Normally no command is accepted in this condition * but just a few. * M: Do not automatically propagate the command on MONITOR. + * k: Perform an implicit ASKING for this command, so the command will be + * accepted in cluster mode if the slot is marked as 'importing'. */ struct redisCommand redisCommandTable[] = { {"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, @@ -242,6 +244,7 @@ struct redisCommand redisCommandTable[] = { {"unwatch",unwatchCommand,1,"rs",0,NULL,0,0,0,0,0}, {"cluster",clusterCommand,-2,"ar",0,NULL,0,0,0,0,0}, {"restore",restoreCommand,-4,"awm",0,NULL,1,1,1,0,0}, + {"restore-asking",restoreCommand,-4,"awmk",0,NULL,1,1,1,0,0}, {"migrate",migrateCommand,-6,"aw",0,NULL,0,0,0,0,0}, {"asking",askingCommand,1,"r",0,NULL,0,0,0,0,0}, {"dump",dumpCommand,2,"ar",0,NULL,1,1,1,0,0}, @@ -1453,6 +1456,7 @@ void populateCommandTable(void) { case 'l': c->flags |= REDIS_CMD_LOADING; break; case 't': c->flags |= REDIS_CMD_STALE; break; case 'M': c->flags |= REDIS_CMD_SKIP_MONITOR; break; + case 'k': c->flags |= REDIS_CMD_ASKING; break; default: redisPanic("Unsupported command flag"); break; } f++; diff --git a/src/redis.h b/src/redis.h index be523e0d8..3f25e32a3 100644 --- a/src/redis.h +++ b/src/redis.h @@ -122,6 +122,7 @@ #define REDIS_CMD_LOADING 512 /* "l" flag */ #define REDIS_CMD_STALE 1024 /* "t" flag */ #define REDIS_CMD_SKIP_MONITOR 2048 /* "M" flag */ +#define REDIS_CMD_ASKING 4096 /* "k" flag */ /* Object types */ #define REDIS_STRING 0