summaryrefslogtreecommitdiff
path: root/tests/support
diff options
context:
space:
mode:
authorSokolov Yura <funny.falcon@gmail.com>2021-03-29 13:52:02 +0300
committerGitHub <noreply@github.com>2021-03-29 13:52:02 +0300
commit315df9ada056841c3acb6e4c1052b60ef61072e8 (patch)
tree1e9e71bcf05bc5ab3372f21a8ee4ec87e14f7810 /tests/support
parent036963a7daa03778ed5a8a0672bb7aa5d7aa74e4 (diff)
downloadredis-315df9ada056841c3acb6e4c1052b60ef61072e8.tar.gz
Add cluster slot migration tests (#8649)
Add tests for fixing migrating slot at all stages: 1. when migration is half inited on "migrating" node 2. when migration is half inited on "importing" node 3. migration inited, but not finished 4. migration is half finished on "migrating" node 5. migration is half finished on "importing" node Also add tests for many simultaneous slot migrations. Co-authored-by: Yossi Gottlieb <yossigo@gmail.com>
Diffstat (limited to 'tests/support')
-rw-r--r--tests/support/cluster.tcl28
-rw-r--r--tests/support/util.tcl14
2 files changed, 35 insertions, 7 deletions
diff --git a/tests/support/cluster.tcl b/tests/support/cluster.tcl
index fb8c46e75..97a659a1d 100644
--- a/tests/support/cluster.tcl
+++ b/tests/support/cluster.tcl
@@ -164,6 +164,28 @@ proc ::redis_cluster::__method__close {id} {
catch {interp alias {} ::redis_cluster::instance$id {}}
}
+proc ::redis_cluster::__method__masternode_for_slot {id slot} {
+ # Get the node mapped to this slot.
+ set node_addr [dict get $::redis_cluster::slots($id) $slot]
+ if {$node_addr eq {}} {
+ error "No mapped node for slot $slot."
+ }
+ return [dict get $::redis_cluster::nodes($id) $node_addr]
+}
+
+proc ::redis_cluster::__method__masternode_notfor_slot {id slot} {
+ # Get a node that is not mapped to this slot.
+ set node_addr [dict get $::redis_cluster::slots($id) $slot]
+ set addrs [dict keys $::redis_cluster::nodes($id)]
+ foreach addr [lshuffle $addrs] {
+ set node [dict get $::redis_cluster::nodes($id) $addr]
+ if {$node_addr ne $addr && [dict get $node slaveof] eq "-"} {
+ return $node
+ }
+ }
+ error "Slot $slot is everywhere"
+}
+
proc ::redis_cluster::__dispatch__ {id method args} {
if {[info command ::redis_cluster::__method__$method] eq {}} {
# Get the keys from the command.
@@ -186,10 +208,15 @@ proc ::redis_cluster::__dispatch__ {id method args} {
# Execute the command in the node we think is the slot owner.
set retry 100
+ set asking 0
while {[incr retry -1]} {
if {$retry < 5} {after 100}
set node [dict get $::redis_cluster::nodes($id) $node_addr]
set link [dict get $node link]
+ if {$asking} {
+ $link ASKING
+ set asking 0
+ }
if {[catch {$link $method {*}$args} e]} {
if {$link eq {} || \
[string range $e 0 4] eq {MOVED} || \
@@ -202,6 +229,7 @@ proc ::redis_cluster::__dispatch__ {id method args} {
} elseif {[string range $e 0 2] eq {ASK}} {
# ASK redirection.
set node_addr [lindex $e 2]
+ set asking 1
continue
} else {
# Non redirecting error.
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index 886ef5020..c35441ab0 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -506,18 +506,18 @@ proc stop_write_load {handle} {
proc K { x y } { set x }
-# Shuffle a list. From Tcl wiki. Originally from Steve Cohen that improved
-# other versions. Code should be under public domain.
+# Shuffle a list with Fisher-Yates algorithm.
proc lshuffle {list} {
set n [llength $list]
- while {$n>0} {
+ while {$n>1} {
set j [expr {int(rand()*$n)}]
- lappend slist [lindex $list $j]
incr n -1
- set temp [lindex $list $n]
- set list [lreplace [K $list [set list {}]] $j $j $temp]
+ if {$n==$j} continue
+ set v [lindex $list $j]
+ lset list $j [lindex $list $n]
+ lset list $n $v
}
- return $slist
+ return $list
}
# Execute a background process writing complex data for the specified number