xputs"[ERR] Sorry, Redis-trib can't fix this slot yet (work in progress). Slot is set as migrating in #{migrating.join(",")}, as importing in #{importing.join(",")}, owner is #{owner}"
end
end
# Check if all the nodes agree about the cluster configuration
defcheck_config_consistency
if!is_config_consistent?
cluster_error"[ERR] Nodes don't agree about configuration!"
else
xputs"[OK] All nodes agree about slots configuration."
end
end
defis_config_consistent?
signatures=[]
@nodes.each{|n|
signatures<<n.get_config_signature
}
returnsignatures.uniq.length==1
end
defwait_cluster_join
print"Waiting for the cluster to join"
while!is_config_consistent?
print"."
STDOUT.flush
sleep1
end
print"\n"
end
defalloc_slots
nodes_count=@nodes.length
masters_count=@nodes.length/(@replicas+1)
masters=[]
# The first step is to split instances by IP. This is useful as
# we'll try to allocate master nodes in different physical machines
# (as much as possible) and to allocate slaves of a given master in
# different physical machines as well.
#
# This code assumes just that if the IP is different, than it is more
# likely that the instance is running in a different physical host
# or at least a different virtual machine.
ips={}
@nodes.each{|n|
ips[n.info[:host]]=[]if!ips[n.info[:host]]
ips[n.info[:host]]<<n
}
# Select master instances
puts"Using #{masters_count} masters:"
interleaved=[]
stop=false
whilenotstopdo
# Take one node from each IP until we run out of nodes
# across every IP.
ips.eachdo|ip,nodes|
ifnodes.empty?
# if this IP has no remaining nodes, check for termination
ifinterleaved.length==nodes_count
# stop when 'interleaved' has accumulated all nodes
stop=true
next
end
else
# else, move one node from this IP to 'interleaved'
interleaved.pushnodes.shift
end
end
end
masters=interleaved.slice!(0,masters_count)
nodes_count-=masters.length
masters.each{|m|putsm}
# Rotating the list sometimes helps to get better initial
# anti-affinity before the optimizer runs.
interleaved.pushinterleaved.shift
# Alloc slots on masters. After interleaving to get just the first N
# should be optimal. With slaves is more complex, see later...