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

Method toReplicaGroups

pkg/topom/context.go:128–168  ·  view source on GitHub ↗
(gid int, p *models.Proxy)

Source from the content-addressed store, hash-verified

126}
127
128func (ctx *context) toReplicaGroups(gid int, p *models.Proxy) [][]string {
129 g := ctx.group[gid]
130 switch {
131 case g == nil:
132 return nil
133 case g.Promoting.State != models.ActionNothing:
134 return nil
135 case len(g.Servers) <= 1:
136 return nil
137 }
138 var dc string
139 var ip net.IP
140 if p != nil {
141 dc = p.DataCenter
142 ip = ctx.lookupIPAddr(p.AdminAddr)
143 }
144 getPriority := func(s *models.GroupServer) int {
145 if ip == nil || dc != s.DataCenter {
146 return 2
147 }
148 if ip.Equal(ctx.lookupIPAddr(s.Addr)) {
149 return 0
150 } else {
151 return 1
152 }
153 }
154 var groups [3][]string
155 for _, s := range g.Servers {
156 if s.ReplicaGroup {
157 p := getPriority(s)
158 groups[p] = append(groups[p], s.Addr)
159 }
160 }
161 var replicas [][]string
162 for _, l := range groups {
163 if len(l) != 0 {
164 replicas = append(replicas, l)
165 }
166 }
167 return replicas
168}
169
170func (ctx *context) toSlotSlice(slots []*models.SlotMapping, p *models.Proxy) []*models.Slot {
171 var slice = make([]*models.Slot, len(slots))

Callers 1

toSlotMethod · 0.95

Calls 1

lookupIPAddrMethod · 0.95

Tested by

no test coverage detected