MCPcopy
hub / github.com/CodisLabs/codis / GroupDelServer

Method GroupDelServer

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

Source from the content-addressed store, hash-verified

143}
144
145func (s *Topom) GroupDelServer(gid int, addr string) error {
146 s.mu.Lock()
147 defer s.mu.Unlock()
148 ctx, err := s.newContext()
149 if err != nil {
150 return err
151 }
152
153 g, err := ctx.getGroup(gid)
154 if err != nil {
155 return err
156 }
157 index, err := ctx.getGroupIndex(g, addr)
158 if err != nil {
159 return err
160 }
161
162 if g.Promoting.State != models.ActionNothing {
163 return errors.Errorf("group-[%d] is promoting", g.Id)
164 }
165
166 if index == 0 {
167 if len(g.Servers) != 1 || ctx.isGroupInUse(g.Id) {
168 return errors.Errorf("group-[%d] can't remove master, still in use", g.Id)
169 }
170 }
171
172 if p := ctx.sentinel; len(p.Servers) != 0 {
173 defer s.dirtySentinelCache()
174 p.OutOfSync = true
175 if err := s.storeUpdateSentinel(p); err != nil {
176 return err
177 }
178 }
179 defer s.dirtyGroupCache(g.Id)
180
181 if index != 0 && g.Servers[index].ReplicaGroup {
182 g.OutOfSync = true
183 }
184
185 var slice = make([]*models.GroupServer, 0, len(g.Servers))
186 for i, x := range g.Servers {
187 if i != index {
188 slice = append(slice, x)
189 }
190 }
191 if len(slice) == 0 {
192 g.OutOfSync = false
193 }
194
195 g.Servers = slice
196
197 return s.storeUpdateGroup(g)
198}
199
200func (s *Topom) GroupPromoteServer(gid int, addr string) error {
201 s.mu.Lock()

Callers 4

TestGroupDelServerFunction · 0.45
TestApiGroupFunction · 0.45
MaintainsMethod · 0.45
handleGroupCommandMethod · 0.45

Calls 9

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

Tested by 2

TestGroupDelServerFunction · 0.36
TestApiGroupFunction · 0.36