Exemplo n.º 1
0
func (svr *Store) Upgrade(args *echoproto.Args, reply *echoproto.Reply) error {
	svr.Lock.Lock()
	reply.Data = svr.Log
	svr.Lock.Unlock()

	return nil
}
Exemplo n.º 2
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
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
func (svr *Server) Commit(args *echoproto.Args, reply *echoproto.Reply) error {
	svr.Lock.Lock()

	svr.Log = append(svr.Log, args.V)

	// echo the response to the client
	reply.Data = nil
	reply.Data = append(reply.Data, args.V)

	svr.N_high = -1
	svr.N_accept = -1
	svr.V_accept = ""

	svr.info("Commit()")

	svr.Lock.Unlock()

	return nil
}
Exemplo n.º 5
0
func (svr *Server) FetchLog(args *echoproto.Args, reply *echoproto.Reply) error {
	svr.Lock.Lock()

	// increment the Lamport timestamp and copy the current version of the log
	svr.update()
	reply.Data = svr.Log

	svr.info("FetchLog()")

	svr.Lock.Unlock()

	return nil
}