(groupFrom, groupTo int, numSlots int)
| 51 | } |
| 52 | |
| 53 | func (s *Topom) SlotCreateActionSome(groupFrom, groupTo int, numSlots int) error { |
| 54 | s.mu.Lock() |
| 55 | defer s.mu.Unlock() |
| 56 | ctx, err := s.newContext() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | |
| 61 | g, err := ctx.getGroup(groupTo) |
| 62 | if err != nil { |
| 63 | return err |
| 64 | } |
| 65 | if len(g.Servers) == 0 { |
| 66 | return errors.Errorf("group-[%d] is empty", g.Id) |
| 67 | } |
| 68 | |
| 69 | var pending []int |
| 70 | for _, m := range ctx.slots { |
| 71 | if len(pending) >= numSlots { |
| 72 | break |
| 73 | } |
| 74 | if m.Action.State != models.ActionNothing { |
| 75 | continue |
| 76 | } |
| 77 | if m.GroupId != groupFrom { |
| 78 | continue |
| 79 | } |
| 80 | if m.GroupId == g.Id { |
| 81 | continue |
| 82 | } |
| 83 | pending = append(pending, m.Id) |
| 84 | } |
| 85 | |
| 86 | for _, sid := range pending { |
| 87 | m, err := ctx.getSlotMapping(sid) |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | defer s.dirtySlotsCache(m.Id) |
| 92 | |
| 93 | m.Action.State = models.ActionPending |
| 94 | m.Action.Index = ctx.maxSlotActionIndex() + 1 |
| 95 | m.Action.TargetId = g.Id |
| 96 | if err := s.storeUpdateSlotMapping(m); err != nil { |
| 97 | return err |
| 98 | } |
| 99 | } |
| 100 | return nil |
| 101 | } |
| 102 | |
| 103 | func (s *Topom) SlotCreateActionRange(beg, end int, gid int, must bool) error { |
| 104 | s.mu.Lock() |
no test coverage detected