// Stop server. func (vs *ViewServer) stop() { logger.Info("Closing view server...") rpc.Close(vs) vs.alive.Set(false) <-vs.done }
// Close worker. func (w *Worker) Shutdown(args *ShutdownArgs, reply *ShutdownReply) error { reply.OK = true reply.MapperNum = w.mapperNum reply.ReducerNum = w.reducerNum rpc.Close(w) return nil }
// Stop this server. func (s *PBServer) stop() { logger.Info(fmt.Sprintf("Pbserver %s is closing...", s.addr)) rpc.Close(s) s.alive.Set(false) <-s.done logger.Info(fmt.Sprintf("Close pbserver %s done", s.addr)) }
// Stop the master and all workers. func (m *Master) shutdown() { logger.Info("Closing master...") m.idleWorkers.Close() rpc.Close(m) args := new(ShutdownArgs) reply := new(ShutdownReply) for _, w := range m.workers { if err := rpc.Call(w, "Worker.Shutdown", args, reply); err != nil { logger.Info(fmt.Sprintf("Worker %s shutdown error: %s", w, err)) } else { logger.Info(fmt.Sprintf("Worker %s runs %d mappers, %d reducers", w, reply.MapperNum, reply.ReducerNum)) } } logger.Info("Close master done") }
func (w *Worker) run() { // Register as a rpc server rpc.Register(w, w.address) // Register as a worker for master. args := &RegisterArgs{ Worker: w.address, } reply := new(RegisterReply) err := rpc.Call(masterAddress, "Master.Register", args, reply) if err != nil { logger.Error(fmt.Sprintf("Cannot register %s as a worker", err)) rpc.Close(w) return } w.file = reply.File w.mapper = reply.CMapper w.reducer = reply.CReducer w.nMapper = reply.NumMapper w.nReducer = reply.NumReducer }