summaryrefslogtreecommitdiff
path: root/src/redis-trib.rb
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-02-22 12:25:16 +0100
committerantirez <antirez@gmail.com>2013-02-22 12:25:16 +0100
commit36af851550b7aedf7a3fafaaa1331ffb9747b16e (patch)
treea9032f60a82a5d00ed80909bddb563bc03dbbf5a /src/redis-trib.rb
parent51b5058d04233bce24927ac233d68cfdfda2cfb9 (diff)
downloadredis-36af851550b7aedf7a3fafaaa1331ffb9747b16e.tar.gz
redis-trib: check that all the nodes agree about the slots configuration.
Diffstat (limited to 'src/redis-trib.rb')
-rwxr-xr-xsrc/redis-trib.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/redis-trib.rb b/src/redis-trib.rb
index fd4d29063..52431bd00 100755
--- a/src/redis-trib.rb
+++ b/src/redis-trib.rb
@@ -192,6 +192,19 @@ class ClusterNode
"[#{@info[:cluster_state].upcase}] #{self.info[:name]} #{self.to_s} slots:#{slots} (#{self.slots.length} slots)"
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
@info
end
@@ -234,6 +247,7 @@ class RedisTrib
def check_cluster
puts "Performing Cluster Check (using node #{@nodes[0]})"
show_nodes
+ check_config_consistency
check_slots_coverage
end
@@ -328,6 +342,19 @@ class RedisTrib
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
slots_per_node = ClusterHashSlots/@nodes.length
i = 0