예제 #1
0
func main() {
	runtime.GOMAXPROCS(5)
	flag.Parse()

	self := fmt.Sprintf(":%d", *portnum)
	l, e := net.Listen("tcp", self)
	if e != nil {
		log.Fatal("listen error:", e)
	}

	hostport := fmt.Sprintf("localhost:%d", *portnum)

	log.Printf("Paxos replica starting on port %d\n", *portnum)
	history := make(map[int]string)
	tc := &TestClient{strconv.Itoa(*portnum), history}
	lp := libpaxos.NewLibpaxos(hostport, strings.Split(*rep, "-"), 2, *nodepos, tc)

	run_cmds := true
	//run_cmds = (*nodepos == 1)

	if run_cmds {
		go func() {
			time.Sleep(5 * time.Second)
			//st := 2 * time.Second
			st := 100 * time.Millisecond
			for i := 1; i <= N; i += 1 {
				time.Sleep(st)
				var reply libpaxos.Reply
				vs := fmt.Sprintf("(value %d %d)", i, *nodepos)
				lp.ProposeCommand(vs, &reply)
			}

			//time.Sleep(60*time.Second)
		}()
	}

	//go func() {
	rpc.Register(lp)
	rpc.HandleHTTP()
	http.Serve(l, nil)
	//} ()
}
예제 #2
0
func NewAirlineServer(airlineID, myhostport, masterStorage, ownStorage string, replicas []string, pos int) (*AirlineServer, *libpaxos.Libpaxos, error) {
	lsplog.SetVerbose(4)
	as := &AirlineServer{}
	as.cmdNO = 0
	as.reqChan = make(chan *Request)
	as.airlineID = airlineID
	as.myhostport = myhostport
	as.logBuf = make(map[string](*bufi.Buf))
	as.flightBuf = make(map[string](*airlineproto.FlightInfo))
	as.flightQueryBuf = make(map[string](string))
	as.lockBuf = make(map[string](bool))
	as.oldLog = make(map[string]int)
	as.oldReplycMap = make(map[int](chan interface{}))

	q := len(replicas)/2 + len(replicas)%2
	as.lp = libpaxos.NewLibpaxos(myhostport, replicas, q, pos, as)

	lc, err := libconn.NewLibconn(airlineID, masterStorage, myhostport, 0)
	if lsplog.CheckReport(2, err) {
		return nil, nil, err
	}
	as.lib_conn = lc

	//
	//	// Create RPC connection to own storage server
	//	conn2, err := rpc.DialHTTP("tcp", ownStorage)
	//	if err != nil {
	//		return nil, err
	//	}
	//	as.ownStorage = conn2
	//
	// Declare existense
	lc.PublishAirline()
	lc.DeclareExistence()

	go as.storeHandler()
	log.Printf("[%s:%s] Start", airlineID, myhostport)
	return as, as.lp, nil
}