Пример #1
0
// RPC interface for the Paxos protocol.
func (svr *Server) Prepare(args *echoproto.Args, reply *echoproto.Reply) error {
	svr.Lock.Lock()

	if args.N >= svr.N_high {
		svr.N_high = args.N
		reply.Response = echoproto.PREPARE_OK
	} else {
		reply.Response = echoproto.PREPARE_REJECT
	}

	svr.info("Prepare()")

	svr.Lock.Unlock()

	return nil
}
Пример #2
0
func (svr *Server) Accept(args *echoproto.Args, reply *echoproto.Reply) error {
	svr.Lock.Lock()

	if args.N >= svr.N_high {
		svr.N_high = args.N
		svr.N_accept = args.N
		svr.V_accept = args.V
		reply.Response = echoproto.ACCEPT_OK
	} else {
		reply.Response = echoproto.ACCEPT_REJECT
	}

	svr.info("Accept()")

	svr.Lock.Unlock()

	return nil
}