Created
March 1, 2012 00:47
-
-
Save rkive/1946271 to your computer and use it in GitHub Desktop.
Generate a Voldemort partition scheme for a given size of cluster.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# gen_cluster_partitions.rb | |
# Generate a Voldemort partition scheme for a given size of cluster. | |
# | |
usage = "Usage: gen_cluster_partitions.rb <name of cluster> < # of cluster nodes> < # of partitions per node>" | |
if ARGV[0] | |
cluster_name = ARGV[0] | |
else | |
puts "Missing Cluster name" | |
puts usage | |
exit 1 | |
end | |
if ARGV[1] | |
number_of_nodes = ARGV[1].to_i | |
else | |
puts "Missing # of cluster nodes" | |
puts usage | |
exit 1 | |
end | |
if ARGV[2] | |
partitions_per_node = ARGV[2].to_i | |
else | |
puts "Missing # of partitions per node" | |
puts usage | |
exit 1 | |
end | |
def gen_cluster_partitions(cluster_name, number_of_nodes, partitions_per_node) | |
#Build an array of node id's | |
nodes = (0...(number_of_nodes)).to_a | |
n = number_of_nodes | |
partition_ids = (0...(n * partitions_per_node)).to_a | |
# use known seed so this is repeatable | |
srand(92873498274) | |
partition_ids.shuffle! | |
p = partitions_per_node | |
cluster = [] | |
id = 0 | |
nodes.each do |host_number| | |
host_number_s = host_number.to_s | |
host_name = "v#{cluster_name}#{host_number_s}" | |
ids = partition_ids[id*p...(id+1)*p] | |
partition_array = ids.sort!.join(",") | |
cluster_node = { | |
"node_id" => host_number_s, | |
"node_name" => host_name, | |
"partitions" => partition_array | |
} | |
cluster << cluster_node | |
# Move onto the next group | |
id = id.next | |
end | |
return cluster | |
end | |
cluster = gen_cluster_partitions(cluster_name, number_of_nodes, partitions_per_node) | |
cluster.each do|node_hash| | |
puts node_hash.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment