Mercurial > hg > Database > Christie
changeset 169:1e696b2d3c6d
add paxos.rb paxos.dot
author | akahori |
---|---|
date | Tue, 22 Jan 2019 18:32:13 +0900 |
parents | c7300be0fff6 |
children | f9f83bb213e8 |
files | scripts/Log/paxos.dot scripts/paxos.rb |
diffstat | 2 files changed, 67 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/Log/paxos.dot Tue Jan 22 18:32:13 2019 +0900 @@ -0,0 +1,17 @@ +digraph test { + proposer1 -> acceptor1 [label="acceptor1"] + proposer1 -> acceptor2 [label="acceptor2"] + proposer1 -> acceptor3 [label="acceptor3"] + proposer2 -> acceptor1 [label="acceptor1"] + proposer2 -> acceptor2 [label="acceptor2"] + proposer2 -> acceptor3 [label="acceptor3"] + acceptor1 -> proposer1 [label="proposer1"] + acceptor2 -> proposer1 [label="proposer1"] + acceptor3 -> proposer1 [label="proposer1"] + acceptor1 -> proposer2 [label="proposer2"] + acceptor2 -> proposer2 [label="proposer2"] + acceptor3 -> proposer2 [label="proposer2"] + acceptor1 -> learner1 [label="learner1"] + acceptor2 -> learner1 [label="learner1"] + acceptor3 -> learner1 [label="learner1"] +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/paxos.rb Tue Jan 22 18:32:13 2019 +0900 @@ -0,0 +1,50 @@ +node_name_list = ["proposer", "acceptor", "learner"] + +def create_nodes(name, node_num) + (0..node_num - 1).map { |i| + i = name + i.to_s + } +end + + +def print_dot(connections) + puts "digraph paxos {" + connections.each { |connection| + print "\t" + print connection[0] + print " -> " + print connection[1] + print ' [label="' + connection[2] + '"]' + puts + } + puts "}" +end + +node_list = Array.new +node_name_list.each_with_index { |node_name, i| + node_num = ARGV.shift + while !node_num + printf("input %s num : ", node_name) + node_num = STDIN.gets.chomp + end + node_list << create_nodes(node_name, node_num.to_i) +} +connections = Array.new + +node_list.each_with_index { |nodes1, i| + if i == node_name_list.size - 1 + break + end + nodes2 = node_list[i+1] + nodes1.each_with_index{ |node1, j| + + nodes2.each_with_index{ |node2, k| + connections << [node1, node2, node2] + if i == 0 + connections << [node2,node1, node1] + end + } + } +} + +print_dot(connections.sort!) \ No newline at end of file