(client *Client, sentniel string, config *MonitorConfig, groups map[int]*net.TCPAddr)
| 417 | } |
| 418 | |
| 419 | func (s *Sentinel) monitorGroupsCommand(client *Client, sentniel string, config *MonitorConfig, groups map[int]*net.TCPAddr) error { |
| 420 | var names []string |
| 421 | for gid := range groups { |
| 422 | names = append(names, s.NodeName(gid)) |
| 423 | } |
| 424 | if err := s.removeCommand(client, names); err != nil { |
| 425 | return err |
| 426 | } |
| 427 | go func() { |
| 428 | for gid, tcpAddr := range groups { |
| 429 | var ip, port = tcpAddr.IP.String(), tcpAddr.Port |
| 430 | client.Send("SENTINEL", "monitor", s.NodeName(gid), ip, port, config.Quorum) |
| 431 | } |
| 432 | if len(groups) != 0 { |
| 433 | client.Flush() |
| 434 | } |
| 435 | }() |
| 436 | for range groups { |
| 437 | _, err := client.Receive() |
| 438 | if err != nil { |
| 439 | return errors.Trace(err) |
| 440 | } |
| 441 | } |
| 442 | go func() { |
| 443 | for gid := range groups { |
| 444 | var args = []interface{}{"set", s.NodeName(gid)} |
| 445 | if config.ParallelSyncs != 0 { |
| 446 | args = append(args, "parallel-syncs", config.ParallelSyncs) |
| 447 | } |
| 448 | if config.DownAfter != 0 { |
| 449 | args = append(args, "down-after-milliseconds", int(config.DownAfter/time.Millisecond)) |
| 450 | } |
| 451 | if config.FailoverTimeout != 0 { |
| 452 | args = append(args, "failover-timeout", int(config.FailoverTimeout/time.Millisecond)) |
| 453 | } |
| 454 | if s.Auth != "" { |
| 455 | args = append(args, "auth-pass", s.Auth) |
| 456 | } |
| 457 | if config.NotificationScript != "" { |
| 458 | args = append(args, "notification-script", config.NotificationScript) |
| 459 | } |
| 460 | if config.ClientReconfigScript != "" { |
| 461 | args = append(args, "client-reconfig-script", config.ClientReconfigScript) |
| 462 | } |
| 463 | client.Send("SENTINEL", args...) |
| 464 | } |
| 465 | if len(groups) != 0 { |
| 466 | client.Flush() |
| 467 | } |
| 468 | }() |
| 469 | for range groups { |
| 470 | _, err := client.Receive() |
| 471 | if err != nil { |
| 472 | return errors.Trace(err) |
| 473 | } |
| 474 | } |
| 475 | return nil |
| 476 | } |
no test coverage detected