XiaoMi / Gaea

Gaea is a mysql proxy, it's developed by xiaomi b2c-dev team.
Apache License 2.0
2.6k stars 418 forks source link

gaea连接etcd,当第一个节点异常时,无法连接配置的其他节点 #244

Open lulufeiacount opened 1 year ago

lulufeiacount commented 1 year ago
gongna-au commented 1 month ago
  • gaea代码
        endpoints := strings.Split(addr, ",")
  config := clientv3.Config{
      Endpoints:            endpoints,
      Username:             username,
      Password:             passwd,
      DialTimeout:          timeout, // 只设定第一次连线时间的逾时,之后不用太担心连线,连线失败后,会自动重连
      DialKeepAliveTimeout: timeout, // 之后维持 etcd 连线的逾时
      TLS:                  tlsConf,
  }
  c, err := clientv3.New(config)
  if err != nil {
      return nil, err
  }
  • etcd中clientv3.New(config)源码
        client.balancer = newHealthBalancer(cfg.Endpoints, cfg.DialTimeout, func(ep string) (bool, error) {
      return grpcHealthCheck(client, ep)
  })

  // use Endpoints[0] so that for https:// without any tls config given, then
  // grpc will assume the certificate server name is the endpoint host.
  conn, err := client.dial(cfg.Endpoints[0], grpc.WithBalancer(client.balancer))
  if err != nil {
      client.cancel()
      client.balancer.Close()
      return nil, err
  }
  client.conn = conn

etcd客户端源码只对于endpoints[0],也就是第一个配置的节点进行连接,如果连接失败就直接返回异常了,这个是不是需要在gaea层面在获取etcd连接的时候进行额外判断,依次获取配置的每个节点的连接,直到获得可用连接为止呢?

感谢您提出这个问题!我们非常重视用户的反馈。 我们会先调研一下新版本的 etcd 是否已经修复了这个问题。如果发现仍然存在这个问题,我们会将其列入开发计划,并在 Gaea 中进行兼容性处理。 再次感谢您的关注和建议!如果您有其他问题或建议,请随时告诉我们。