MCPcopy Index your code
hub / github.com/CodisLabs/codis / GroupAddServer

Method GroupAddServer

pkg/topom/topom_group.go:104–143  ·  view source on GitHub ↗
(gid int, dc, addr string)

Source from the content-addressed store, hash-verified

102}
103
104func (s *Topom) GroupAddServer(gid int, dc, addr string) error {
105 s.mu.Lock()
106 defer s.mu.Unlock()
107 ctx, err := s.newContext()
108 if err != nil {
109 return err
110 }
111
112 if addr == "" {
113 return errors.Errorf("invalid server address")
114 }
115
116 for _, g := range ctx.group {
117 for _, x := range g.Servers {
118 if x.Addr == addr {
119 return errors.Errorf("server-[%s] already exists", addr)
120 }
121 }
122 }
123
124 g, err := ctx.getGroup(gid)
125 if err != nil {
126 return err
127 }
128 if g.Promoting.State != models.ActionNothing {
129 return errors.Errorf("group-[%d] is promoting", g.Id)
130 }
131
132 if p := ctx.sentinel; len(p.Servers) != 0 {
133 defer s.dirtySentinelCache()
134 p.OutOfSync = true
135 if err := s.storeUpdateSentinel(p); err != nil {
136 return err
137 }
138 }
139 defer s.dirtyGroupCache(g.Id)
140
141 g.Servers = append(g.Servers, &models.GroupServer{Addr: addr, DataCenter: dc})
142 return s.storeUpdateGroup(g)
143}
144
145func (s *Topom) GroupDelServer(gid int, addr string) error {
146 s.mu.Lock()

Callers 4

TestGroupAddServerFunction · 0.45
TestApiSlotsFunction · 0.45
TestApiGroupFunction · 0.45
handleGroupCommandMethod · 0.45

Calls 7

newContextMethod · 0.95
dirtySentinelCacheMethod · 0.95
storeUpdateSentinelMethod · 0.95
dirtyGroupCacheMethod · 0.95
storeUpdateGroupMethod · 0.95
ErrorfMethod · 0.80
getGroupMethod · 0.80

Tested by 3

TestGroupAddServerFunction · 0.36
TestApiSlotsFunction · 0.36
TestApiGroupFunction · 0.36