summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorVo Trong Phuc <38036797+noradomi@users.noreply.github.com>2022-02-03 16:57:51 +0700
committerGitHub <noreply@github.com>2022-02-03 11:57:51 +0200
commit53c43fcc847d00d101c1e97563d7e3adc8b94143 (patch)
treeba749afe42fa3e27ad7030a3a95f7d7c60f0421f /tests/integration
parentf4ecc799c87fa504b375afc17a7f8302789254b5 (diff)
downloadredis-53c43fcc847d00d101c1e97563d7e3adc8b94143.tar.gz
Add check min-slave-* feature when evaluating Lua scripts and Functions (#10160)
Add check enough good slaves for write command when evaluating scripts. This check is made before the script is executed, if we have function flags, and per redis command if we don't. Co-authored-by: Phuc. Vo Trong <phucvt@vng.com.vn> Co-authored-by: Oran Agra <oran@redislabs.com> Co-authored-by: Meir Shpilraien (Spielrein) <meir@redis.com>
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/replication-4.tcl42
1 files changed, 33 insertions, 9 deletions
diff --git a/tests/integration/replication-4.tcl b/tests/integration/replication-4.tcl
index 8cccd9678..b8c50308a 100644
--- a/tests/integration/replication-4.tcl
+++ b/tests/integration/replication-4.tcl
@@ -46,6 +46,12 @@ start_server {tags {"repl external:skip"}} {
set master_port [srv -1 port]
set slave [srv 0 client]
+ # Load some functions to be used later
+ $master FUNCTION load lua test replace {
+ redis.register_function{function_name='f_default_flags', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={}}
+ redis.register_function{function_name='f_no_writes', callback=function(keys, args) return redis.call('get',keys[1]) end, flags={'no-writes'}}
+ }
+
test {First server should have role slave after SLAVEOF} {
$slave slaveof $master_host $master_port
wait_replica_online $master
@@ -54,28 +60,46 @@ start_server {tags {"repl external:skip"}} {
test {With min-slaves-to-write (1,3): master should be writable} {
$master config set min-slaves-max-lag 3
$master config set min-slaves-to-write 1
- $master set foo bar
- } {OK}
+ assert_equal OK [$master set foo 123]
+ assert_equal OK [$master eval "return redis.call('set','foo',12345)" 0]
+ }
test {With min-slaves-to-write (2,3): master should not be writable} {
$master config set min-slaves-max-lag 3
$master config set min-slaves-to-write 2
- catch {$master set foo bar} e
- set e
- } {NOREPLICAS*}
+ assert_error "*NOREPLICAS*" {$master set foo bar}
+ assert_error "*NOREPLICAS*" {$master eval "redis.call('set','foo','bar')" 0}
+ }
+
+ test {With min-slaves-to-write function without no-write flag} {
+ assert_error "*NOREPLICAS*" {$master fcall f_default_flags 1 foo}
+ assert_equal "12345" [$master fcall f_no_writes 1 foo]
+ }
+
+ test {With not enough good slaves, read in Lua script is still accepted} {
+ $master config set min-slaves-max-lag 3
+ $master config set min-slaves-to-write 1
+ $master eval "redis.call('set','foo','bar')" 0
+
+ $master config set min-slaves-to-write 2
+ $master eval "return redis.call('get','foo')" 0
+ } {bar}
test {With min-slaves-to-write: master not writable with lagged slave} {
$master config set min-slaves-max-lag 2
$master config set min-slaves-to-write 1
- assert {[$master set foo bar] eq {OK}}
+ assert_equal OK [$master set foo 123]
+ assert_equal OK [$master eval "return redis.call('set','foo',12345)" 0]
+ # Killing a slave to make it become a lagged slave.
exec kill -SIGSTOP [srv 0 pid]
+ # Waiting for slave kill.
wait_for_condition 100 100 {
- [catch {$master set foo bar}] != 0
+ [catch {$master set foo 123}] != 0
} else {
fail "Master didn't become readonly"
}
- catch {$master set foo bar} err
- assert_match {NOREPLICAS*} $err
+ assert_error "*NOREPLICAS*" {$master set foo 123}
+ assert_error "*NOREPLICAS*" {$master eval "return redis.call('set','foo',12345)" 0}
exec kill -SIGCONT [srv 0 pid]
}
}