Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/commands/append.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/blmove.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"LIST"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/blmpop.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"get_keys_function": "blmpopGetKeys",
"command_flags": [
"WRITE",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"LIST"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/blpop.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"LIST"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/brpop.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"LIST"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/brpoplpush.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"LIST"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/bzmpop.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"get_keys_function": "blmpopGetKeys",
"command_flags": [
"WRITE",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"SORTEDSET"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/bzpopmax.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"command_flags": [
"WRITE",
"FAST",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"SORTEDSET"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/bzpopmin.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"command_flags": [
"WRITE",
"FAST",
"BLOCKING"
"BLOCKING",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"SORTEDSET"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/expire.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"KEYSPACE"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/expireat.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"KEYSPACE"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/getdel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"function": "getdelCommand",
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/getex.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"function": "getexCommand",
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/getset.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hexpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"history": [],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hgetdel.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"history": [],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hgetex.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"history": [],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hincrby.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hincrbyfloat.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hpexpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"history": [],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/hsetex.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"HASH"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/incrbyfloat.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"command_flags": [
"WRITE",
"DENYOOM",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/pexpire.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"KEYSPACE"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/psetex.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
],
"command_flags": [
"WRITE",
"DENYOOM"
"DENYOOM",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/setex.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
],
"command_flags": [
"WRITE",
"DENYOOM"
"DENYOOM",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/setrange.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"function": "setrangeCommand",
"command_flags": [
"WRITE",
"DENYOOM"
"DENYOOM",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"STRING"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/spop.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"command_flags": [
"WRITE",
"FAST"
"FAST",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"SET"
Expand Down
3 changes: 2 additions & 1 deletion src/commands/zmpop.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"function": "zmpopCommand",
"get_keys_function": "zmpopGetKeys",
"command_flags": [
"WRITE"
"WRITE",
"GTID_NON_DETERMINISM"
],
"acl_categories": [
"SORTEDSET"
Expand Down
1 change: 1 addition & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ int64_t commandFlagsFromString(char *s) {
else if (!strcasecmp(t,"no-mandatory-keys")) flags |= CMD_NO_MANDATORY_KEYS;
else if (!strcasecmp(t,"allow-busy")) flags |= CMD_ALLOW_BUSY;
else if (!strcasecmp(t, "internal")) flags |= (CMD_INTERNAL|CMD_NOSCRIPT); /* We also disallow internal commands in scripts. */
else if (!strcasecmp(t,"rewrite-command")) flags |= CMD_GTID_NON_DETERMINISM;
else break;
}
sdsfreesplitres(tokens,count);
Expand Down
1 change: 1 addition & 0 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -5286,6 +5286,7 @@ void addReplyFlagsForCommand(client *c, struct redisCommand *cmd) {
{CMD_MOVABLE_KEYS, "movablekeys"},
{CMD_ALLOW_BUSY, "allow_busy"},
/* {CMD_TOUCHES_ARBITRARY_KEYS, "TOUCHES_ARBITRARY_KEYS"}, Hidden on purpose */
{CMD_GTID_NON_DETERMINISM, "rewrite_command"},
{0,NULL}
};
addReplyCommandFlags(c, cmd->flags, flagNames);
Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ extern int configOOMScoreAdjValuesDefaults[CONFIG_OOM_COUNT];
#define CMD_MODULE_GETCHANNELS (1ULL<<27) /* Use the modules getchannels interface. */
#define CMD_TOUCHES_ARBITRARY_KEYS (1ULL<<28)
#define CMD_INTERNAL (1ULL<<29) /* Internal command. */
#define CMD_GTID_NON_DETERMINISM (1ULL<<30)

/* Command flags that describe ACLs categories. */
#define ACL_CATEGORY_KEYSPACE (1ULL<<0)
Expand Down
85 changes: 85 additions & 0 deletions tests/gtid/gtid.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,88 @@ start_server {tags {"repl"} overrides} {
}
}
}

proc gtid_rewrite_cmd_list {} {
return {
append
blmove
blmpop
blpop
brpop
brpoplpush
bzmpop
bzpopmax
bzpopmin
expire
expireat
getdel
getex
getset
hexpire
hgetdel
hgetex
hincrby
hincrbyfloat
hpexpire
hsetex
incrbyfloat
pexpire
psetex
setex
setrange
spop
zmpop
}
}

# Verify that GTID command rejects commands that would rewrite their argv
# (e.g. expire -> PEXPIREAT, setex -> SET PX, incrbyfloat -> SET). Rewriting
# argv inside the gtid command body is unsafe: the rewritten argv is dropped
# on gtidCommand exit (which restores orig_argv), so the unrewritten original
# is written to AOF/replication and breaks master-replica consistency. The
# command list is version-specific and supplied by gtid_rewrite_cmd_list.
start_server {tags {"gtid"} overrides {gtid-enabled yes}} {
test {GTID should reject commands that rewrite argv} {
set rewrite_cmds [gtid_rewrite_cmd_list]
set gno 1
set now_seconds [clock seconds]
set now_ms [clock milliseconds]

foreach cmd $rewrite_cmds {
switch -- $cmd {
"append" { set args [list $cmd rw_append v] }
"expire" { set args [list $cmd k1 1000] }
"pexpire" { set args [list $cmd k1 1000] }
"expireat" { set args [list $cmd k1 [expr {$now_seconds + 100}]] }
"setex" { set args [list $cmd k1 10 v] }
"psetex" { set args [list $cmd k1 10000 v] }
"getdel" { set args [list $cmd rw_getdel k] }
"getset" { set args [list $cmd getset_key new] }
"getex" { set args [list $cmd getset_key EX 100] }
"setrange" { set args [list $cmd rw_setrange 0 v] }
"hexpire" { set args [list $cmd hash_key 100 f1] }
"hpexpire" { set args [list $cmd hash_key 100 f1] }
"hsetex" { set args [list $cmd hash_key 100 f2 v2] }
"hgetdel" { set args [list $cmd hash_key f1] }
"hgetex" { set args [list $cmd hash_key f1 EX 100] }
"hincrby" { set args [list $cmd hash_key f1 1] }
"hincrbyfloat" { set args [list $cmd hash_key f1 1.1] }
"incrbyfloat" { set args [list $cmd getset_key 1.1] }
"blmove" { set args [list $cmd src_key dst_key LEFT RIGHT 1] }
"brpoplpush" { set args [list $cmd src_key dst_key 1] }
"blpop" { set args [list $cmd list_key 1] }
"brpop" { set args [list $cmd list_key 1] }
"blmpop" { set args [list $cmd list_key 2 LEFT 1] }
"bzpopmin" { set args [list $cmd zset_key 1] }
"bzpopmax" { set args [list $cmd zset_key 1] }
"bzmpop" { set args [list $cmd hash_key 2 MIN 1] }
"zmpop" { set args [list $cmd hash_key 2 MIN] }
"spop" { set args [list $cmd spop_key] }
default { fail "unexpected command $cmd" }
}
catch {r gtid A:$gno 0 {*}$args} result
assert_match {*ERR*} $result
incr gno
}
}
}
Loading