Leader returns a connection pool to the zero leader.
(gid uint32)
| 171 | |
| 172 | // Leader returns a connection pool to the zero leader. |
| 173 | func (s *Server) Leader(gid uint32) *conn.Pool { |
| 174 | s.RLock() |
| 175 | defer s.RUnlock() |
| 176 | if s.state == nil { |
| 177 | return nil |
| 178 | } |
| 179 | var members map[uint64]*pb.Member |
| 180 | if gid == 0 { |
| 181 | members = s.state.Zeros |
| 182 | } else { |
| 183 | group := s.state.Groups[gid] |
| 184 | if group == nil { |
| 185 | return nil |
| 186 | } |
| 187 | members = group.Members |
| 188 | } |
| 189 | var healthyPool *conn.Pool |
| 190 | for _, m := range members { |
| 191 | if pl, err := conn.GetPools().Get(m.Addr); err == nil { |
| 192 | healthyPool = pl |
| 193 | if m.Leader { |
| 194 | return pl |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | return healthyPool |
| 199 | } |
| 200 | |
| 201 | // KnownGroups returns a list of the known groups. |
| 202 | func (s *Server) KnownGroups() []uint32 { |
no test coverage detected