Пример #1
0
// RPC
func (tl *TranLayer) TransResponse(args *airlineproto.TranArgs, reply *airlineproto.TranReply) error {
	lsplog.Vlogf(5, args.TranID+": Reeceived trans respose %d", args.Vote)
	// send request to store handler
	var req *reqContent
	switch args.TranType {
	case transaction.TRANS_RESPONSE:
		req = &reqContent{TRANS_RESPONSE, "", args}
	case transaction.TRANS_OLD:
		req = &reqContent{TRANS_OLD, "", args}
	}

	switch req.reqType {
	case TRANS_RESPONSE:
		tl.reqChan <- &Request{req, nil}
		reply.Status = airlineproto.OK
	case TRANS_OLD:
		replyc := make(chan interface{})
		tl.reqChan <- &Request{req, replyc}
		decision := (<-replyc).(int)
		reply.Status = decision
	}

	// reply to rpc
	reply.Status = airlineproto.OK
	return nil
}
Пример #2
0
func (as *AirlineServer) Transaction(args *airlineproto.TranArgs, reply *airlineproto.TranReply) error {
	// send request to store handler
	cmdArgs, _ := json.Marshal(*args)
	paxosCmd := fmt.Sprintf("%s@TA@%s", as.myhostport, cmdArgs)
	req := &reqContent{PAXOS_REQUEST, paxosCmd, nil}

	// wait for response
	switch args.TranType {
	case transaction.TRANS_INIT, transaction.TRANS_RESPONSE, transaction.TRANS_OLD_RESPONSE:
		as.reqChan <- &Request{req, nil, true}
		reply.Status = airlineproto.OK
	case transaction.TRANS_OLD:
		replyc := make(chan interface{})
		as.reqChan <- &Request{req, replyc, true}
		decision := (<-replyc).(int)
		reply.Status = decision
	}

	return nil

}