func (srv *Server) deleteSlot(req *Request) { var cliType uint32 = ClientTypeNormal if req.Cli != nil { cliType = req.Cli.ClientType() } switch cliType { case ClientTypeNormal: var p ctrl.PkgDelSlot var err = ctrl.Decode(req.Pkg, nil, &p) p.ErrMsg = "" if err != nil { p.ErrMsg = fmt.Sprintf("decode failed %s", err) } else { err = srv.deleteMigrationSlot(p.SlotId, srv.mc.GetMaster()) if err != nil { p.ErrMsg = fmt.Sprintf("delete slot failed %s", err) } } pkg, err := ctrl.Encode(req.Cmd, req.DbId, req.Seq, &p) if err == nil { srv.sendResp(false, req, pkg) } case ClientTypeSlave: fallthrough case ClientTypeMaster: log.Println("Invalid client type %d for DelSlot command, close now!", cliType) req.Cli.Close() } }
// Internal control command. // DelSlot deletes one slot data. func (c *CtrlContext) DelSlot(slotId uint16) error { call := c.cli.newCall(proto.CmdDelSlot, nil) if call.err != nil { return call.err } var p ctrl.PkgDelSlot p.SlotId = slotId pkg, err := ctrl.Encode(call.cmd, c.dbId, call.seq, &p) if err != nil { c.cli.errCall(call, err) return call.err } call.pkg = pkg c.cli.sending <- call r, err := (<-call.Done).Reply() if err != nil { return call.err } t := r.(*ctrl.PkgDelSlot) if t.ErrMsg != "" { return errors.New(t.ErrMsg) } return nil }