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
917dd532
Commit
917dd532
authored
Feb 15, 2013
by
antirez
Browse files
redis-trib: make a few comments 80-cols friendly.
parent
455da35c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
917dd532
...
@@ -313,13 +313,16 @@ class RedisTrib
...
@@ -313,13 +313,16 @@ class RedisTrib
def
compute_reshard_table
(
sources
,
numslots
)
def
compute_reshard_table
(
sources
,
numslots
)
moved
=
[]
moved
=
[]
# Sort from bigger to smaller instance, for two reasons:
# Sort from bigger to smaller instance, for two reasons:
# 1) If we take less slots than instances it is better to start getting from
# 1) If we take less slots than instances it is better to start
# the biggest instances.
# getting from the biggest instances.
# 2) We take one slot more from the first instance in the case of not perfect
# 2) We take one slot more from the first instance in the case of not
# divisibility. Like we have 3 nodes and need to get 10 slots, we take
# perfect divisibility. Like we have 3 nodes and need to get 10
# 4 from the first, and 3 from the rest. So the biggest is always the first.
# slots, we take 4 from the first, and 3 from the rest. So the
# biggest is always the first.
sources
=
sources
.
sort
{
|
a
,
b
|
b
.
slots
.
length
<=>
a
.
slots
.
length
}
sources
=
sources
.
sort
{
|
a
,
b
|
b
.
slots
.
length
<=>
a
.
slots
.
length
}
source_tot_slots
=
sources
.
inject
(
0
)
{
|
sum
,
source
|
sum
+
source
.
slots
.
length
}
source_tot_slots
=
sources
.
inject
(
0
)
{
|
sum
,
source
|
sum
+
source
.
slots
.
length
}
sources
.
each_with_index
{
|
s
,
i
|
sources
.
each_with_index
{
|
s
,
i
|
# Every node will provide a number of slots proportional to the
# Every node will provide a number of slots proportional to the
# slots it has assigned.
# slots it has assigned.
...
@@ -347,8 +350,8 @@ class RedisTrib
...
@@ -347,8 +350,8 @@ class RedisTrib
def
move_slot
(
source
,
target
,
slot
,
o
=
{})
def
move_slot
(
source
,
target
,
slot
,
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
to
# the operations is important, as otherwise a client may be redirected
# the target node that does not yet know it is importing this slot.
#
to
the target node that does not yet know it is importing this slot.
print
"Moving slot
#{
slot
}
from
#{
source
.
info_string
}
: "
;
STDOUT
.
flush
print
"Moving slot
#{
slot
}
from
#{
source
.
info_string
}
: "
;
STDOUT
.
flush
target
.
r
.
cluster
(
"setslot"
,
slot
,
"importing"
,
source
.
info
[
:name
])
target
.
r
.
cluster
(
"setslot"
,
slot
,
"importing"
,
source
.
info
[
:name
])
source
.
r
.
cluster
(
"setslot"
,
slot
,
"migrating"
,
source
.
info
[
:name
])
source
.
r
.
cluster
(
"setslot"
,
slot
,
"migrating"
,
source
.
info
[
:name
])
...
...
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