Exemple #1
0
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)
}
Exemple #2
0
func apiMigrateStatus() (int, string) {
	conn := CreateZkConn()
	defer conn.Close()

	migrateSlots, err := models.GetMigratingSlots(conn, productName)
	if err != nil {
		log.Warning("get slots info error, maybe init slots first? err: ", err)
		return 500, err.Error()
	}

	b, err := json.MarshalIndent(map[string]interface{}{
		"migrate_slots": migrateSlots,
		"migrate_task":  curMigrateTask,
	}, " ", "  ")
	return 200, string(b)
}
Exemple #3
0
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
}
Exemple #4
0
func preMigrateCheck(t *MigrateTask) (bool, error) {
	conn := CreateZkConn()
	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
}