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
915e8133
Commit
915e8133
authored
Feb 21, 2013
by
antirez
Browse files
redis-trib: ability to fix uncovered slots for the trivial case.
parent
619d3945
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
915e8133
...
@@ -259,9 +259,44 @@ class RedisTrib
...
@@ -259,9 +259,44 @@ class RedisTrib
end
end
end
end
def
nodes_with_keys_in_slot
(
slot
)
nodes
=
[]
@nodes
.
each
{
|
n
|
nodes
<<
n
if
n
.
r
.
cluster
(
"getkeysinslot"
,
slot
,
1
).
length
>
0
}
nodes
end
def
fix_slots_coverage
def
fix_slots_coverage
slots
=
covered_slots
not_covered
=
(
0
...
ClusterHashSlots
).
to_a
-
covered_slots
.
keys
# TODO ... actually fix coverage
puts
"
\n
Fixing slots coverage..."
puts
"List of not covered slots: "
+
not_covered
.
join
(
","
)
# For every slot, take action depending on the actual condition:
# 1) No node has keys for this slot.
# 2) A single node has keys for this slot.
# 3) Multiple nodes have keys for this slot.
slots
=
{}
not_covered
.
each
{
|
slot
|
nodes
=
nodes_with_keys_in_slot
(
slot
)
slots
[
slot
]
=
nodes
puts
"Slot
#{
slot
}
has keys in
#{
nodes
.
length
}
nodes"
}
none
=
slots
.
select
{
|
k
,
v
|
v
.
length
==
0
}
single
=
slots
.
select
{
|
k
,
v
|
v
.
length
==
1
}
multi
=
slots
.
select
{
|
k
,
v
|
v
.
length
>
1
}
# TODO: Handle none and single cases as well.
if
single
.
length
puts
"The folowing uncovered slots have keys in just one node:"
puts
single
.
keys
.
join
(
","
)
yes_or_die
"Fix this slots by covering with those nodes?"
single
.
each
{
|
slot
,
nodes
|
puts
"Covering slot
#{
slot
}
with
#{
nodes
[
0
]
}
"
nodes
[
0
].
r
.
cluster
(
"addslots"
,
slot
)
}
end
end
end
def
alloc_slots
def
alloc_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