// Internal control command. // SlaveStatus reads migration/slave status. func (c *CtrlContext) SlaveStatus(migration bool, slotId uint16) (int, error) { call := c.cli.newCall(proto.CmdSlaveSt, nil) if call.err != nil { return ctrl.NotSlave, call.err } var p ctrl.PkgSlaveStatus p.Migration = migration p.SlotId = slotId pkg, err := ctrl.Encode(call.cmd, c.dbId, call.seq, &p) if err != nil { c.cli.errCall(call, err) return ctrl.NotSlave, call.err } call.pkg = pkg c.cli.sending <- call r, err := (<-call.Done).Reply() if err != nil { return ctrl.NotSlave, call.err } t := r.(*ctrl.PkgSlaveStatus) if t.ErrMsg != "" { return ctrl.NotSlave, errors.New(t.ErrMsg) } return t.Status, nil }
func (srv *Server) slaveStatus(req *Request) { var cliType uint32 = ClientTypeNormal if req.Cli != nil { cliType = req.Cli.ClientType() } switch cliType { case ClientTypeNormal: var p ctrl.PkgSlaveStatus var err = ctrl.Decode(req.Pkg, nil, &p) p.ErrMsg = "" if err != nil { p.ErrMsg = fmt.Sprintf("decode failed %s", err) } else { m := srv.mc.GetMaster() if len(m.MasterAddr) > 0 { if p.Migration { if !m.Migration { p.ErrMsg = fmt.Sprintf("check migration status on normal slave") } else if m.SlotId != p.SlotId { p.ErrMsg = fmt.Sprintf("slot id mismatch (%d, %d)", m.SlotId, p.SlotId) } } else { if m.Migration { p.ErrMsg = fmt.Sprintf("check normal slave status on migration") } } } if len(p.ErrMsg) == 0 { p.Status = m.Status } } 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 MigStatus command, close now!", cliType) req.Cli.Close() } }