Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
36af8515
You need to sign in or sign up before continuing.
Commit
36af8515
authored
Feb 22, 2013
by
antirez
Browse files
redis-trib: check that all the nodes agree about the slots configuration.
parent
51b5058d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-trib.rb
View file @
36af8515
...
@@ -192,6 +192,19 @@ class ClusterNode
...
@@ -192,6 +192,19 @@ class ClusterNode
"[
#{
@info
[
:cluster_state
].
upcase
}
]
#{
self
.
info
[
:name
]
}
#{
self
.
to_s
}
slots:
#{
slots
}
(
#{
self
.
slots
.
length
}
slots)"
"[
#{
@info
[
:cluster_state
].
upcase
}
]
#{
self
.
info
[
:name
]
}
#{
self
.
to_s
}
slots:
#{
slots
}
(
#{
self
.
slots
.
length
}
slots)"
end
end
# Return a single string representing nodes and associated slots.
# TODO: remove slaves from config when slaves will be handled
# by Redis Cluster.
def
get_config_signature
config
=
[]
@r
.
cluster
(
"nodes"
).
each_line
{
|
l
|
s
=
l
.
split
slots
=
s
[
7
..-
1
].
select
{
|
x
|
x
[
0
..
0
]
!=
"["
}
config
<<
s
[
0
]
+
":"
+
(
slots
.
sort
.
join
(
","
))
}
config
.
sort
.
join
(
"|"
)
end
def
info
def
info
@info
@info
end
end
...
@@ -234,6 +247,7 @@ class RedisTrib
...
@@ -234,6 +247,7 @@ class RedisTrib
def
check_cluster
def
check_cluster
puts
"Performing Cluster Check (using node
#{
@nodes
[
0
]
}
)"
puts
"Performing Cluster Check (using node
#{
@nodes
[
0
]
}
)"
show_nodes
show_nodes
check_config_consistency
check_slots_coverage
check_slots_coverage
end
end
...
@@ -328,6 +342,19 @@ class RedisTrib
...
@@ -328,6 +342,19 @@ class RedisTrib
end
end
end
end
# Check if all the nodes agree about the cluster configuration
def
check_config_consistency
signatures
=
[]
@nodes
.
each
{
|
n
|
signatures
<<
n
.
get_config_signature
}
if
signatures
.
uniq
.
length
!=
1
puts
"[ERR] Nodes don't agree about configuration!"
else
puts
"[OK] All nodes agree about slots configuration."
end
end
def
alloc_slots
def
alloc_slots
slots_per_node
=
ClusterHashSlots
/
@nodes
.
length
slots_per_node
=
ClusterHashSlots
/
@nodes
.
length
i
=
0
i
=
0
...
...
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