Unverified Commit 35e836c2 authored by Binbin's avatar Binbin Committed by GitHub
Browse files

Add SENTINEL command flag to CLIENT/COMMANDS subcommands (#10904)

This was harmless because we marked the parent command
with SENTINEL flag. So the populateCommandTable was ok.
And we also don't show the flag (SENTINEL and ONLY-SENTNEL)
in COMMAND INFO.

In this PR, we also add the same CMD_SENTINEL and CMD_ONLY_SENTINEL
flags check when populating the sub-commands.
so that in the future it'll be possible to add some sub-commands to sentinel or sentinel-only but not others.
parent 51da5c3d
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"function": "commandGetKeysAndFlagsCommand", "function": "commandGetKeysAndFlagsCommand",
"command_flags": [ "command_flags": [
"LOADING", "LOADING",
"STALE" "STALE",
"SENTINEL"
], ],
"acl_categories": [ "acl_categories": [
"CONNECTION" "CONNECTION"
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"function": "commandHelpCommand", "function": "commandHelpCommand",
"command_flags": [ "command_flags": [
"LOADING", "LOADING",
"STALE" "STALE",
"SENTINEL"
], ],
"acl_categories": [ "acl_categories": [
"CONNECTION" "CONNECTION"
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
], ],
"command_flags": [ "command_flags": [
"LOADING", "LOADING",
"STALE" "STALE",
"SENTINEL"
], ],
"acl_categories": [ "acl_categories": [
"CONNECTION" "CONNECTION"
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
"function": "commandListCommand", "function": "commandListCommand",
"command_flags": [ "command_flags": [
"LOADING", "LOADING",
"STALE" "STALE",
"SENTINEL"
], ],
"acl_categories": [ "acl_categories": [
"CONNECTION" "CONNECTION"
......
...@@ -2793,8 +2793,23 @@ int populateArgsStructure(struct redisCommandArg *args) { ...@@ -2793,8 +2793,23 @@ int populateArgsStructure(struct redisCommandArg *args) {
return count; return count;
} }
/* Recursively populate the command structure. */ /* Recursively populate the command structure.
void populateCommandStructure(struct redisCommand *c) { *
* On success, the function return C_OK. Otherwise C_ERR is returned and we won't
* add this command in the commands dict. */
int populateCommandStructure(struct redisCommand *c) {
/* If the command marks with CMD_SENTINEL, it exists in sentinel. */
if (!(c->flags & CMD_SENTINEL) && server.sentinel_mode)
return C_ERR;
/* If the command marks with CMD_ONLY_SENTINEL, it only exists in sentinel. */
if (c->flags & CMD_ONLY_SENTINEL && !server.sentinel_mode)
return C_ERR;
/* Translate the command string flags description into an actual
* set of flags. */
setImplicitACLCategories(c);
/* Redis commands don't need more args than STATIC_KEY_SPECS_NUM (Number of keys /* Redis commands don't need more args than STATIC_KEY_SPECS_NUM (Number of keys
* specs can be greater than STATIC_KEY_SPECS_NUM only for module commands) */ * specs can be greater than STATIC_KEY_SPECS_NUM only for module commands) */
c->key_specs = c->key_specs_static; c->key_specs = c->key_specs_static;
...@@ -2828,14 +2843,15 @@ void populateCommandStructure(struct redisCommand *c) { ...@@ -2828,14 +2843,15 @@ void populateCommandStructure(struct redisCommand *c) {
for (int j = 0; c->subcommands[j].declared_name; j++) { for (int j = 0; c->subcommands[j].declared_name; j++) {
struct redisCommand *sub = c->subcommands+j; struct redisCommand *sub = c->subcommands+j;
/* Translate the command string flags description into an actual
* set of flags. */
setImplicitACLCategories(sub);
sub->fullname = catSubCommandFullname(c->declared_name, sub->declared_name); sub->fullname = catSubCommandFullname(c->declared_name, sub->declared_name);
populateCommandStructure(sub); if (populateCommandStructure(sub) == C_ERR)
continue;
commandAddSubcommand(c, sub, sub->declared_name); commandAddSubcommand(c, sub, sub->declared_name);
} }
} }
return C_OK;
} }
extern struct redisCommand redisCommandTable[]; extern struct redisCommand redisCommandTable[];
...@@ -2853,16 +2869,9 @@ void populateCommandTable(void) { ...@@ -2853,16 +2869,9 @@ void populateCommandTable(void) {
int retval1, retval2; int retval1, retval2;
setImplicitACLCategories(c);
if (!(c->flags & CMD_SENTINEL) && server.sentinel_mode)
continue;
if (c->flags & CMD_ONLY_SENTINEL && !server.sentinel_mode)
continue;
c->fullname = sdsnew(c->declared_name); c->fullname = sdsnew(c->declared_name);
populateCommandStructure(c); if (populateCommandStructure(c) == C_ERR)
continue;
retval1 = dictAdd(server.commands, sdsdup(c->fullname), c); retval1 = dictAdd(server.commands, sdsdup(c->fullname), c);
/* Populate an additional dictionary that will be unaffected /* Populate an additional dictionary that will be unaffected
......
...@@ -2186,9 +2186,10 @@ typedef int redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, ge ...@@ -2186,9 +2186,10 @@ typedef int redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, ge
* or may just execute read commands. A command can not be marked * or may just execute read commands. A command can not be marked
* both CMD_WRITE and CMD_MAY_REPLICATE * both CMD_WRITE and CMD_MAY_REPLICATE
* *
* CMD_SENTINEL: This command is present in sentinel mode too. * CMD_SENTINEL: This command is present in sentinel mode.
* *
* CMD_SENTINEL_ONLY: This command is present only when in sentinel mode. * CMD_ONLY_SENTINEL: This command is present only when in sentinel mode.
* And should be removed from redis.
* *
* CMD_NO_MANDATORY_KEYS: This key arguments for this command are optional. * CMD_NO_MANDATORY_KEYS: This key arguments for this command are optional.
* *
......
...@@ -12,6 +12,13 @@ if {$::simulate_error} { ...@@ -12,6 +12,13 @@ if {$::simulate_error} {
} }
} }
test "Sentinel commands sanity check" {
foreach_sentinel_id id {
assert_equal {72} [llength [S $id command list]]
assert_equal {15} [S $id command count]
}
}
test "Basic failover works if the master is down" { test "Basic failover works if the master is down" {
set old_port [RPort $master_id] set old_port [RPort $master_id]
set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster] set addr [S 0 SENTINEL GET-MASTER-ADDR-BY-NAME mymaster]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment