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

Method trySwitchMaster

pkg/proxy/router.go:250–276  ·  view source on GitHub ↗
(id int, masters map[int]string, cache *redis.InfoCache)

Source from the content-addressed store, hash-verified

248}
249
250func (s *Router) trySwitchMaster(id int, masters map[int]string, cache *redis.InfoCache) {
251 var switched bool
252 var m = s.slots[id].snapshot()
253
254 hasSameRunId := func(addr1, addr2 string) bool {
255 if addr1 != addr2 {
256 rid1 := cache.GetRunId(addr1)
257 rid2 := cache.GetRunId(addr2)
258 return rid1 != "" && rid1 == rid2
259 }
260 return true
261 }
262
263 if addr := masters[m.BackendAddrGroupId]; addr != "" {
264 if !hasSameRunId(addr, m.BackendAddr) {
265 m.BackendAddr, switched = addr, true
266 }
267 }
268 if addr := masters[m.MigrateFromGroupId]; addr != "" {
269 if !hasSameRunId(addr, m.MigrateFrom) {
270 m.MigrateFrom, switched = addr, true
271 }
272 }
273 if switched {
274 s.fillSlot(m, true, nil)
275 }
276}

Callers 1

SwitchMastersMethod · 0.95

Calls 3

fillSlotMethod · 0.95
snapshotMethod · 0.80
GetRunIdMethod · 0.80

Tested by

no test coverage detected