func apiMigrateStatus() (int, string) { migrateSlots, err := models.GetMigratingSlots(safeZkConn, globalEnv.ProductName()) if err != nil && !zkhelper.ZkErrorEqual(err, zk.ErrNoNode) { return 500, err.Error() } b, err := json.MarshalIndent(map[string]interface{}{ "migrate_slots": migrateSlots, "migrate_task": globalMigrateManager.runningTask, }, " ", " ") return 200, string(b) }
func (t *MigrateTask) preMigrateCheck() error { slots, err := models.GetMigratingSlots(safeZkConn, t.productName) if err != nil { return errors.Trace(err) } // check if there is migrating slot if len(slots) > 1 { return errors.Errorf("more than one slots are migrating, unknown error") } if len(slots) == 1 { slot := slots[0] if t.NewGroupId != slot.State.MigrateStatus.To || t.SlotId != slot.Id { return errors.Errorf("there is a migrating slot %+v, finish it first", slot) } } return nil }