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
628af702
Commit
628af702
authored
Dec 18, 2015
by
antirez
Browse files
Cluster: redis-trib reshard / rebalance --pipeline support.
parent
77f849b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
628af702
...
@@ -26,6 +26,7 @@ require 'redis'
...
@@ -26,6 +26,7 @@ require 'redis'
ClusterHashSlots
=
16384
ClusterHashSlots
=
16384
MigrateDefaultTimeout
=
60000
MigrateDefaultTimeout
=
60000
MigrateDefaultPipeline
=
10
RebalanceDefaultThreshold
=
2
RebalanceDefaultThreshold
=
2
$verbose
=
false
$verbose
=
false
...
@@ -36,6 +37,8 @@ def xputs(s)
...
@@ -36,6 +37,8 @@ def xputs(s)
color
=
"29;1"
color
=
"29;1"
when
"[ER"
when
"[ER"
color
=
"31;1"
color
=
"31;1"
when
"[WA"
color
=
"31;1"
when
"[OK"
when
"[OK"
color
=
"32"
color
=
"32"
when
"[FA"
,
"***"
when
"[FA"
,
"***"
...
@@ -847,6 +850,8 @@ class RedisTrib
...
@@ -847,6 +850,8 @@ class RedisTrib
# :update -- Update nodes.info[:slots] for source/target nodes.
# :update -- Update nodes.info[:slots] for source/target nodes.
# :quiet -- Don't print info messages.
# :quiet -- Don't print info messages.
def
move_slot
(
source
,
target
,
slot
,
o
=
{})
def
move_slot
(
source
,
target
,
slot
,
o
=
{})
o
=
{
:pipeline
=>
MigrateDefaultPipeline
}.
merge
(
o
)
# We start marking the slot as importing in the destination node,
# We start marking the slot as importing in the destination node,
# and the slot as migrating in the target host. Note that the order of
# and the slot as migrating in the target host. Note that the order of
# the operations is important, as otherwise a client may be redirected
# the operations is important, as otherwise a client may be redirected
...
@@ -862,7 +867,7 @@ class RedisTrib
...
@@ -862,7 +867,7 @@ class RedisTrib
end
end
# Migrate all the keys from source to target using the MIGRATE command
# Migrate all the keys from source to target using the MIGRATE command
while
true
while
true
keys
=
source
.
r
.
cluster
(
"getkeysinslot"
,
slot
,
10
)
keys
=
source
.
r
.
cluster
(
"getkeysinslot"
,
slot
,
o
[
:pipeline
]
)
break
if
keys
.
length
==
0
break
if
keys
.
length
==
0
begin
begin
source
.
r
.
client
.
call
([
"migrate"
,
target
.
info
[
:host
],
target
.
info
[
:port
],
""
,
0
,
@timeout
,
:keys
,
*
keys
])
source
.
r
.
client
.
call
([
"migrate"
,
target
.
info
[
:host
],
target
.
info
[
:port
],
""
,
0
,
@timeout
,
:keys
,
*
keys
])
...
@@ -908,6 +913,10 @@ class RedisTrib
...
@@ -908,6 +913,10 @@ class RedisTrib
end
end
def
rebalance_cluster_cmd
(
argv
,
opt
)
def
rebalance_cluster_cmd
(
argv
,
opt
)
opt
=
{
'pipeline'
=>
MigrateDefaultPipeline
}.
merge
(
opt
)
# Load nodes info before parsing options, otherwise we can't
# handle --weight.
load_cluster_info_from_node
(
argv
[
0
])
load_cluster_info_from_node
(
argv
[
0
])
# Options parsing
# Options parsing
...
@@ -995,7 +1004,10 @@ class RedisTrib
...
@@ -995,7 +1004,10 @@ class RedisTrib
else
else
reshard_table
.
each
{
|
e
|
reshard_table
.
each
{
|
e
|
move_slot
(
e
[
:source
],
dst
,
e
[
:slot
],
move_slot
(
e
[
:source
],
dst
,
e
[
:slot
],
:quiet
=>
true
,
:dots
=>
false
,
:update
=>
true
)
:quiet
=>
true
,
:dots
=>
false
,
:update
=>
true
,
:pipeline
=>
opt
[
'pipeline'
])
print
"#"
print
"#"
STDOUT
.
flush
STDOUT
.
flush
}
}
...
@@ -1020,6 +1032,8 @@ class RedisTrib
...
@@ -1020,6 +1032,8 @@ class RedisTrib
end
end
def
reshard_cluster_cmd
(
argv
,
opt
)
def
reshard_cluster_cmd
(
argv
,
opt
)
opt
=
{
'pipeline'
=>
MigrateDefaultPipeline
}.
merge
(
opt
)
load_cluster_info_from_node
(
argv
[
0
])
load_cluster_info_from_node
(
argv
[
0
])
check_cluster
check_cluster
if
@errors
.
length
!=
0
if
@errors
.
length
!=
0
...
@@ -1132,7 +1146,9 @@ class RedisTrib
...
@@ -1132,7 +1146,9 @@ class RedisTrib
exit
(
1
)
if
(
yesno
!=
"yes"
)
exit
(
1
)
if
(
yesno
!=
"yes"
)
end
end
reshard_table
.
each
{
|
e
|
reshard_table
.
each
{
|
e
|
move_slot
(
e
[
:source
],
target
,
e
[
:slot
],
:dots
=>
true
)
move_slot
(
e
[
:source
],
target
,
e
[
:slot
],
:dots
=>
true
,
:pipeline
=>
opt
[
'pipeline'
])
}
}
end
end
...
@@ -1531,8 +1547,8 @@ ALLOWED_OPTIONS={
...
@@ -1531,8 +1547,8 @@ ALLOWED_OPTIONS={
"create"
=>
{
"replicas"
=>
true
},
"create"
=>
{
"replicas"
=>
true
},
"add-node"
=>
{
"slave"
=>
false
,
"master-id"
=>
true
},
"add-node"
=>
{
"slave"
=>
false
,
"master-id"
=>
true
},
"import"
=>
{
"from"
=>
:required
,
"copy"
=>
false
,
"replace"
=>
false
},
"import"
=>
{
"from"
=>
:required
,
"copy"
=>
false
,
"replace"
=>
false
},
"reshard"
=>
{
"from"
=>
true
,
"to"
=>
true
,
"slots"
=>
true
,
"yes"
=>
false
,
"timeout"
=>
MigrateDefaultTimeout
},
"reshard"
=>
{
"from"
=>
true
,
"to"
=>
true
,
"slots"
=>
true
,
"yes"
=>
false
,
"timeout"
=>
true
,
"pipeline"
=>
true
},
"rebalance"
=>
{
"weight"
=>
[],
"auto-weights"
=>
false
,
"threshold"
=>
RebalanceDefaultThreshold
,
"use-empty-masters"
=>
false
,
"timeout"
=>
MigrateDefaultTimeout
,
"simulate"
=>
fals
e
},
"rebalance"
=>
{
"weight"
=>
[],
"auto-weights"
=>
false
,
"threshold"
=>
RebalanceDefaultThreshold
,
"use-empty-masters"
=>
false
,
"timeout"
=>
true
,
"simulate"
=>
false
,
"pipeline"
=>
tru
e
},
"fix"
=>
{
"timeout"
=>
MigrateDefaultTimeout
},
"fix"
=>
{
"timeout"
=>
MigrateDefaultTimeout
},
}
}
...
...
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