示例#1
0
func NewTribserver(agencyid, master, ownstorage, myhostport string, prefer int) *Tribserver {
	lsplog.SetVerbose(3)

	//Connect to master
	lc, err := libconn.NewLibconn(agencyid, master, myhostport, prefer)
	if lsplog.CheckReport(1, err) {
		return nil
	}

	//Init libstore : Agency storage server
	ls, err := libstore.NewLibstore(agencyid, ownstorage, myhostport, libstore.NONE)
	if lsplog.CheckReport(1, err) {
		log.Printf("[%s:%s] Fail to start", agencyid, myhostport)
		return nil
	}

	//Init libairline : Airline storage server
	la, err := libairline.NewLibairline(lc, agencyid, myhostport)
	if lsplog.CheckReport(1, err) {
		log.Printf("[%s:%s] Fail to start", agencyid, myhostport)
		return nil
	}

	//lsplog.Vlogf(5, "Server active... %s", myhostport);
	log.Printf("[%s:%s] Start", agencyid, myhostport)
	return &Tribserver{ls, la, agencyid, myhostport}
}
示例#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
}