(ctx context.Context, sentinel string, timeout time.Duration)
| 298 | } |
| 299 | |
| 300 | func (s *Sentinel) mastersDispatch(ctx context.Context, sentinel string, timeout time.Duration) (map[int]*SentinelMaster, error) { |
| 301 | var masters = make(map[int]*SentinelMaster) |
| 302 | var err = s.dispatch(ctx, sentinel, timeout, func(c *Client) error { |
| 303 | p, err := s.mastersCommand(c) |
| 304 | if err != nil { |
| 305 | return err |
| 306 | } |
| 307 | for gid, master := range p { |
| 308 | epoch, err := strconv.ParseInt(master["config-epoch"], 10, 64) |
| 309 | if err != nil { |
| 310 | s.printf("sentinel-[%s] masters parse %s failed, config-epoch = '%s', %s", |
| 311 | sentinel, master["name"], master["config-epoch"], err) |
| 312 | continue |
| 313 | } |
| 314 | var ip, port = master["ip"], master["port"] |
| 315 | if ip == "" || port == "" { |
| 316 | s.printf("sentinel-[%s] masters parse %s failed, ip:port = '%s:%s'", |
| 317 | sentinel, master["name"], ip, port) |
| 318 | continue |
| 319 | } |
| 320 | masters[gid] = &SentinelMaster{ |
| 321 | Addr: net.JoinHostPort(ip, port), |
| 322 | Info: master, Epoch: epoch, |
| 323 | } |
| 324 | } |
| 325 | return nil |
| 326 | }) |
| 327 | if err != nil { |
| 328 | switch errors.Cause(err) { |
| 329 | case context.Canceled: |
| 330 | return nil, nil |
| 331 | default: |
| 332 | return nil, err |
| 333 | } |
| 334 | } |
| 335 | return masters, nil |
| 336 | } |
| 337 | |
| 338 | type SentinelMaster struct { |
| 339 | Addr string |
no test coverage detected