Gaea
Gaea copied to clipboard
gaea连接etcd,当第一个节点异常时,无法连接配置的其他节点
- 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连接的时候进行额外判断,依次获取配置的每个节点的连接,直到获得可用连接为止呢?