Check target node is a primary during cluster setslot. (#10277)
This commit is contained in:
parent
5bdd72bea7
commit
a5d17f0b6c
@ -5226,6 +5226,10 @@ NULL
|
||||
(char*)c->argv[4]->ptr);
|
||||
return;
|
||||
}
|
||||
if (nodeIsSlave(n)) {
|
||||
addReplyError(c,"Target node is not a master");
|
||||
return;
|
||||
}
|
||||
/* If this hash slot was served by 'myself' before to switch
|
||||
* make sure there are no longer local keys for this hash slot. */
|
||||
if (server.cluster->slots[slot] == myself && n != myself) {
|
||||
|
@ -49,6 +49,34 @@ test "client can handle keys with hash tag" {
|
||||
$cluster close
|
||||
}
|
||||
|
||||
test "slot migration is valid from primary to another primary" {
|
||||
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
|
||||
set key order1
|
||||
set slot [$cluster cluster keyslot $key]
|
||||
array set nodefrom [$cluster masternode_for_slot $slot]
|
||||
array set nodeto [$cluster masternode_notfor_slot $slot]
|
||||
|
||||
assert_equal {OK} [$nodefrom(link) cluster setslot $slot node $nodeto(id)]
|
||||
assert_equal {OK} [$nodeto(link) cluster setslot $slot node $nodeto(id)]
|
||||
}
|
||||
|
||||
test "slot migration is invalid from primary to replica" {
|
||||
set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
|
||||
set key order1
|
||||
set slot [$cluster cluster keyslot $key]
|
||||
array set nodefrom [$cluster masternode_for_slot $slot]
|
||||
|
||||
# Get replica node serving slot.
|
||||
set replicanodeinfo [$cluster cluster replicas $nodefrom(id)]
|
||||
puts $replicanodeinfo
|
||||
set args [split $replicanodeinfo " "]
|
||||
set replicaid [lindex [split [lindex $args 0] \{] 1]
|
||||
puts $replicaid
|
||||
|
||||
catch {[$nodefrom(link) cluster setslot $slot node $replicaid]} err
|
||||
assert_match "*Target node is not a master" $err
|
||||
}
|
||||
|
||||
if {$::tls} {
|
||||
test {CLUSTER SLOTS from non-TLS client in TLS cluster} {
|
||||
set slots_tls [R 0 cluster slots]
|
||||
@ -60,4 +88,4 @@ if {$::tls} {
|
||||
# Compare the ports in the first row
|
||||
assert_no_match [lindex $slots_tls 0 3 1] [lindex $slots_plain 0 3 1]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user