예제 #1
0
func apiMigrateStatus() (int, string) {
	conn := CreateCoordConn()
	defer conn.Close()

	migrateSlots, err := models.GetMigratingSlots(conn, 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)
}
예제 #2
0
func preMigrateCheck(t *MigrateTask) (bool, error) {
	conn := CreateCoordConn()
	defer conn.Close()

	slots, err := models.GetMigratingSlots(conn, t.productName)

	if err != nil {
		return false, errors.Trace(err)
	}
	// check if there is migrating slot
	if len(slots) > 1 {
		return false, errors.New("more than one slots are migrating, unknown error")
	}
	if len(slots) == 1 {
		slot := slots[0]
		if t.NewGroupId != slot.State.MigrateStatus.To || t.FromSlot != slot.Id || t.ToSlot != slot.Id {
			return false, errors.Errorf("there is a migrating slot %+v, finish it first", slot)
		}
	}
	return true, nil
}