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
7898bf4b
Commit
7898bf4b
authored
Feb 21, 2013
by
antirez
Browse files
redis-trib: some refactoring and skeleton of the "fix" command.
parent
dc4af606
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
7898bf4b
...
@@ -39,12 +39,14 @@ class ClusterNode
...
@@ -39,12 +39,14 @@ class ClusterNode
exit
1
exit
1
end
end
@r
=
nil
@r
=
nil
@fix
=
false
@info
=
{}
@info
=
{}
@info
[
:host
]
=
s
[
0
]
@info
[
:host
]
=
s
[
0
]
@info
[
:port
]
=
s
[
1
]
@info
[
:port
]
=
s
[
1
]
@info
[
:slots
]
=
{}
@info
[
:slots
]
=
{}
@dirty
=
false
# True if we need to flush slots info into node.
@dirty
=
false
# True if we need to flush slots info into node.
@friends
=
[]
@friends
=
[]
@errors
=
[]
end
end
def
friends
def
friends
...
@@ -231,20 +233,35 @@ class RedisTrib
...
@@ -231,20 +233,35 @@ class RedisTrib
def
check_cluster
def
check_cluster
puts
"Performing Cluster Check (using node
#{
@nodes
[
0
]
}
)"
puts
"Performing Cluster Check (using node
#{
@nodes
[
0
]
}
)"
errors
=
[]
show_nodes
show_nodes
# Check if all the slots are covered
check_slots_coverage
end
# Merge slots of every known node. If the resulting slots are equal
# to ClusterHashSlots, then all slots are served.
def
covered_slots
slots
=
{}
slots
=
{}
@nodes
.
each
{
|
n
|
@nodes
.
each
{
|
n
|
slots
=
slots
.
merge
(
n
.
slots
)
slots
=
slots
.
merge
(
n
.
slots
)
}
}
slots
end
def
check_slots_coverage
slots
=
covered_slots
if
slots
.
length
==
ClusterHashSlots
if
slots
.
length
==
ClusterHashSlots
puts
"[OK] All
#{
ClusterHashSlots
}
slots covered."
puts
"[OK] All
#{
ClusterHashSlots
}
slots covered."
else
else
errors
<<
"[ERR] Not all
#{
ClusterHashSlots
}
slots are covered by nodes."
@errors
<<
puts
errors
[
-
1
]
"[ERR] Not all
#{
ClusterHashSlots
}
slots are covered by nodes."
puts
@errors
[
-
1
]
fix_slots_covarege
if
@fix
end
end
return
errors
end
def
fix_slots_coverage
slots
=
covered_slots
# TODO ... actually fix coverage
end
end
def
alloc_slots
def
alloc_slots
...
@@ -374,15 +391,21 @@ class RedisTrib
...
@@ -374,15 +391,21 @@ class RedisTrib
# redis-trib subcommands implementations
# redis-trib subcommands implementations
def
check_cluster_cmd
def
check_cluster_cmd
load_cluster_info_from_node
(
ARGV
[
1
])
check_cluster
end
def
fix_cluster_cmd
@fix
=
true
load_cluster_info_from_node
(
ARGV
[
1
])
load_cluster_info_from_node
(
ARGV
[
1
])
check_cluster
check_cluster
end
end
def
reshard_cluster_cmd
def
reshard_cluster_cmd
load_cluster_info_from_node
(
ARGV
[
1
])
load_cluster_info_from_node
(
ARGV
[
1
])
errors
=
check_cluster
check_cluster
if
errors
.
length
!=
0
if
@
errors
.
length
!=
0
puts
"Please fix your cluster problems before resharding."
puts
"Please fix your cluster problems before resharding."
exit
1
exit
1
end
end
...
@@ -467,9 +490,10 @@ class RedisTrib
...
@@ -467,9 +490,10 @@ class RedisTrib
end
end
COMMANDS
=
{
COMMANDS
=
{
"create"
=>
[
"create_cluster_cmd"
,
-
2
,
"host1:port host2:port ... hostN:port"
],
"create"
=>
[
"create_cluster_cmd"
,
-
2
,
"host1:port1 ... hostN:portN"
],
"check"
=>
[
"check_cluster_cmd"
,
2
,
"host:port"
],
"check"
=>
[
"check_cluster_cmd"
,
2
,
"host:port"
],
"reshard"
=>
[
"reshard_cluster_cmd"
,
2
,
"host:port"
]
"fix"
=>
[
"fix_cluster_cmd"
,
2
,
"host:port"
],
"reshard"
=>
[
"reshard_cluster_cmd"
,
2
,
"host:port"
]
}
}
# Sanity check
# Sanity check
...
@@ -477,7 +501,7 @@ if ARGV.length == 0
...
@@ -477,7 +501,7 @@ if ARGV.length == 0
puts
"Usage: redis-trib <command> <arguments ...>"
puts
"Usage: redis-trib <command> <arguments ...>"
puts
puts
COMMANDS
.
each
{
|
k
,
v
|
COMMANDS
.
each
{
|
k
,
v
|
puts
"
#{
k
.
ljust
(
2
0
)
}
#{
v
[
2
]
}
"
puts
"
#{
k
.
ljust
(
1
0
)
}
#{
v
[
2
]
}
"
}
}
puts
puts
exit
1
exit
1
...
...
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