Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
a5d17f0b
Unverified
Commit
a5d17f0b
authored
Feb 11, 2022
by
Harkrishn Patro
Committed by
GitHub
Feb 10, 2022
Browse files
Check target node is a primary during cluster setslot. (#10277)
parent
5bdd72be
Changes
2
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
a5d17f0b
...
...
@@ -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
)
{
...
...
tests/cluster/tests/15-cluster-slots.tcl
View file @
a5d17f0b
...
...
@@ -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
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment