| 13 | ) |
| 14 | |
| 15 | func (s *Topom) CreateGroup(gid int) error { |
| 16 | s.mu.Lock() |
| 17 | defer s.mu.Unlock() |
| 18 | ctx, err := s.newContext() |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | |
| 23 | if gid <= 0 || gid > models.MaxGroupId { |
| 24 | return errors.Errorf("invalid group id = %d, out of range", gid) |
| 25 | } |
| 26 | if ctx.group[gid] != nil { |
| 27 | return errors.Errorf("group-[%d] already exists", gid) |
| 28 | } |
| 29 | defer s.dirtyGroupCache(gid) |
| 30 | |
| 31 | g := &models.Group{ |
| 32 | Id: gid, |
| 33 | Servers: []*models.GroupServer{}, |
| 34 | } |
| 35 | return s.storeCreateGroup(g) |
| 36 | } |
| 37 | |
| 38 | func (s *Topom) RemoveGroup(gid int) error { |
| 39 | s.mu.Lock() |