This commit is contained in:
Diego Lopez Recas 2026-02-04 04:54:12 +07:00 committed by GitHub
commit 033b4863dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 4 deletions

View file

@ -18,7 +18,6 @@ set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
while {[incr iterations -1]} {
set tokill [randomInt 10]
set other [expr {($tokill+1)%10}] ; # Some other instance.
set key [randstring 20 20 alpha]
set val [randstring 20 20 alpha]
set role [RI $tokill role]
@ -57,7 +56,10 @@ while {[incr iterations -1]} {
# Wait for the write to propagate to the slave if we
# are going to kill a master.
if {$role eq {master}} {
R $tokill wait 1 20000
# The WAIT command is only effective if sent by the same client that
# performed the last write on the server that will be killed.
set link [$cluster get_link [get_instance_addr redis $tokill]]
$link wait 1 20000
}
}

View file

@ -612,6 +612,10 @@ proc set_instance_attrib {type id attrib newval} {
lset ::${type}_instances $id $d
}
proc get_instance_addr {type id} {
return [get_instance_attrib $type $id host]:[get_instance_attrib $type $id port]
}
# Create a master-slave cluster of the given number of total instances.
# The first instance "0" is the master, all others are configured as
# slaves.

View file

@ -201,6 +201,11 @@ proc ::redis_cluster::__method__masternode_notfor_slot {id slot} {
error "Slot $slot is everywhere"
}
proc ::redis_cluster::__method__get_link {id node_addr} {
set node [dict get $::redis_cluster::nodes($id) $node_addr]
return [dict get $node link]
}
proc ::redis_cluster::__dispatch__ {id method args} {
if {[info command ::redis_cluster::__method__$method] eq {}} {
# Get the keys from the command.
@ -226,8 +231,7 @@ proc ::redis_cluster::__dispatch__ {id method args} {
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]
set link [::redis_cluster::__method__get_link $id $node_addr]
if {$asking} {
$link ASKING
set asking 0