Exemplo n.º 1
0
Arquivo: slot.go Projeto: banyue/codis
func runSlotRangeSet(fromSlotId, toSlotId int, groupId int, status string) error {
	err := models.SetSlotRange(zkConn, productName, fromSlotId, toSlotId, groupId, models.SlotStatus(status))
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
Exemplo n.º 2
0
Arquivo: slot.go Projeto: banyue/codis
func runSlotSet(slotId int, groupId int, status string) error {
	slot := models.NewSlot(productName, slotId)
	slot.GroupId = groupId
	slot.State.Status = models.SlotStatus(status)
	ts := time.Now().Unix()
	slot.State.LastOpTs = strconv.FormatInt(ts, 10)
	if err := slot.Update(zkConn); err != nil {
		return errors.Trace(err)
	}
	return nil
}
Exemplo n.º 3
0
func apiSlotRangeSet(task RangeSetTask) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	lock.Lock(fmt.Sprintf("set slot range, %+v", task))
	defer func() {
		err := lock.Unlock()
		if err != nil {
			log.Warning(err)
		}
	}()

	// default set online
	if len(task.Status) == 0 {
		task.Status = string(models.SLOT_STATUS_ONLINE)
	}

	err := models.SetSlotRange(safeZkConn, globalEnv.ProductName(), task.FromSlot, task.ToSlot, task.NewGroupId, models.SlotStatus(task.Status))
	if err != nil {
		log.Warning(err)
		return 500, err.Error()
	}

	return jsonRetSucc()
}
Exemplo n.º 4
0
func apiSlotRangeSet(task RangeSetTask) (int, string) {
	lock := utils.GetZkLock(safeZkConn, globalEnv.ProductName())
	if err := lock.LockWithTimeout(0, fmt.Sprintf("set slot range, %+v", task)); err != nil {
		return 500, err.Error()
	}
	defer func() {
		err := lock.Unlock()
		if err != nil && err != zk.ErrNoNode {
			log.ErrorErrorf(err, "unlock node failed")
		}
	}()

	// default set online
	if len(task.Status) == 0 {
		task.Status = string(models.SLOT_STATUS_ONLINE)
	}

	err := models.SetSlotRange(safeZkConn, globalEnv.ProductName(), task.FromSlot, task.ToSlot, task.NewGroupId, models.SlotStatus(task.Status))
	if err != nil {
		log.ErrorErrorf(err, "set slot range [%d,%d] failed", task.FromSlot, task.ToSlot)
		return 500, err.Error()
	}

	return jsonRetSucc()
}