redis-trib: wait cluster join after cluster creation.

This commit is contained in:
antirez 2013-03-25 13:14:17 +01:00
parent 34c1871e9f
commit 70091a2f63

View File

@ -431,17 +431,31 @@ class RedisTrib
# Check if all the nodes agree about the cluster configuration # Check if all the nodes agree about the cluster configuration
def check_config_consistency def check_config_consistency
signatures=[] if !is_config_consistent?
@nodes.each{|n|
signatures << n.get_config_signature
}
if signatures.uniq.length != 1
cluster_error "[ERR] Nodes don't agree about configuration!" cluster_error "[ERR] Nodes don't agree about configuration!"
else else
xputs "[OK] All nodes agree about slots configuration." xputs "[OK] All nodes agree about slots configuration."
end end
end end
def is_config_consistent?
signatures=[]
@nodes.each{|n|
signatures << n.get_config_signature
}
return signatures.uniq.length == 1
end
def wait_cluster_join
print "Waiting for the cluster to join"
while !is_config_consistent?
print "."
STDOUT.flush
sleep 1
end
print "\n"
end
def alloc_slots def alloc_slots
slots_per_node = ClusterHashSlots/@nodes.length slots_per_node = ClusterHashSlots/@nodes.length
i = 0 i = 0
@ -668,6 +682,11 @@ class RedisTrib
xputs ">>> Nodes configuration updated" xputs ">>> Nodes configuration updated"
xputs ">>> Sending CLUSTER MEET messages to join the cluster" xputs ">>> Sending CLUSTER MEET messages to join the cluster"
join_cluster join_cluster
# Give one second for the join to start, in order to avoid that
# wait_cluster_join will find all the nodes agree about the config as
# they are still empty with unassigned slots.
sleep 1
wait_cluster_join
check_cluster check_cluster
end end