(gid int, master string, cache *redis.InfoCache)
| 345 | } |
| 346 | |
| 347 | func (s *Topom) trySwitchGroupMaster(gid int, master string, cache *redis.InfoCache) error { |
| 348 | ctx, err := s.newContext() |
| 349 | if err != nil { |
| 350 | return err |
| 351 | } |
| 352 | g, err := ctx.getGroup(gid) |
| 353 | if err != nil { |
| 354 | return err |
| 355 | } |
| 356 | |
| 357 | var index = func() int { |
| 358 | for i, x := range g.Servers { |
| 359 | if x.Addr == master { |
| 360 | return i |
| 361 | } |
| 362 | } |
| 363 | for i, x := range g.Servers { |
| 364 | rid1 := cache.GetRunId(master) |
| 365 | rid2 := cache.GetRunId(x.Addr) |
| 366 | if rid1 != "" && rid1 == rid2 { |
| 367 | return i |
| 368 | } |
| 369 | } |
| 370 | return -1 |
| 371 | }() |
| 372 | if index == -1 { |
| 373 | return errors.Errorf("group-[%d] doesn't have server %s with runid = '%s'", g.Id, master, cache.GetRunId(master)) |
| 374 | } |
| 375 | if index == 0 { |
| 376 | return nil |
| 377 | } |
| 378 | defer s.dirtyGroupCache(g.Id) |
| 379 | |
| 380 | log.Warnf("group-[%d] will switch master to server[%d] = %s", g.Id, index, g.Servers[index].Addr) |
| 381 | |
| 382 | g.Servers[0], g.Servers[index] = g.Servers[index], g.Servers[0] |
| 383 | g.OutOfSync = true |
| 384 | return s.storeUpdateGroup(g) |
| 385 | } |
| 386 | |
| 387 | func (s *Topom) EnableReplicaGroups(gid int, addr string, value bool) error { |
| 388 | s.mu.Lock() |
no test coverage detected