Skip to content

Commit

Permalink
Merge pull request #8840 from gyuho/health-balancer
Browse files Browse the repository at this point in the history
*: refactor clientv3 balancer, upgrade gRPC to v1.7.2
  • Loading branch information
gyuho authored Nov 10, 2017
2 parents 64acd71 + c669ff9 commit b64c1bf
Show file tree
Hide file tree
Showing 37 changed files with 3,088 additions and 2,248 deletions.
439 changes: 0 additions & 439 deletions clientv3/balancer.go

This file was deleted.

19 changes: 16 additions & 3 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ func (c *Client) SetEndpoints(eps ...string) {
c.cfg.Endpoints = eps
c.mu.Unlock()
c.balancer.updateAddrs(eps...)

// updating notifyCh can trigger new connections,
// need update addrs if all connections are down
// or addrs does not include pinAddr.
c.balancer.mu.RLock()
update := !hasAddr(c.balancer.addrs, c.balancer.pinAddr)
c.balancer.mu.RUnlock()
if update {
select {
case c.balancer.updateAddrsC <- notifyNext:
case <-c.balancer.stopc:
}
}
}

// Sync synchronizes client's endpoints with the known endpoints from the etcd membership.
Expand Down Expand Up @@ -378,9 +391,9 @@ func newClient(cfg *Config) (*Client, error) {
client.Password = cfg.Password
}

sb := newSimpleBalancer(cfg.Endpoints)
hc := func(ep string) (bool, error) { return grpcHealthCheck(client, ep) }
client.balancer = newHealthBalancer(sb, cfg.DialTimeout, hc)
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.
Expand Down
Loading

0 comments on commit b64c1bf

Please sign in to comment.