func main() { flag.Parse() if *masterHostPort == "" && *port == 0 { // If masterHostPort string is empty, then this node is the master. *port = defaultMasterPort } // Create and start the paxos server var paxosBackend backend.Backend if *testing { paxosBackend = backend.NewStub() } else { paxosBackend, _ = backend.NewJeopardyServer() } var debug paxosrpc.Debug if *debugArgs == "none" { debug = paxosrpc.NONE } else if *debugArgs == "dropstart" { debug = paxosrpc.DROPSTART } else { debug = paxosrpc.DROPODD } _, err := paxos.NewPaxos(*masterHostPort, *numNodes, "localhost:"+strconv.Itoa(*port), *nodeID, *masterID, paxosBackend, debug) if err != nil { log.Fatalln("Failed to create Paxos node:", err) } // Run the node forever. select {} }
func testPaxosReplaceNode() { t.send(10, master) for i := 0; i < (*numNodes-1)*10; i++ { //All but the dead node reply <-t.messages } reply := new(paxosrpc.GetServerReply) master.Call("Paxos.GetServers", new(paxosrpc.GetServerArgs), reply) nodes := (*reply).Nodes hostPort := "localhost:" + strconv.Itoa(10000+(rand.Int()%10000)) stub := backend.NewStub() _, err := paxos.NewPaxos(nodes[0].HostPort, *numNodes, hostPort, uint64(*numNodes), 0, stub, paxosrpc.NONE) if err != nil { log.Println(err) } var replaceNode paxosrpc.Node for _, node := range nodes { if node.NodeID == 2 { //Again, we always assume 2 is killed..this is dependent on paxostest.sh replaceNode = node } } args := &paxosrpc.QuiesceArgs{nodes[0], replaceNode, paxosrpc.Node{hostPort, uint64(*numNodes)}} for _, node := range nodes { if node.NodeID != 2 { conn, err := rpc.DialHTTP("tcp", node.HostPort) if err != nil { log.Println(err) } conn.Call("Paxos.Quiesce", args, new(paxosrpc.QuiesceReply)) } } for i := 0; i < 10; i++ { <-t.messages } master.Call("Paxos.GetServers", new(paxosrpc.GetServerArgs), reply) nodes = (*reply).Nodes for _, node := range nodes { conn, err := rpc.DialHTTP("tcp", node.HostPort) if err != nil { log.Println(err) } conn.Call("Paxos.Resume", new(paxosrpc.ResumeArgs), new(paxosrpc.ResumeReply)) } t.sendAndListen(20) }