clientv3: handle stale endpoint in health balancer

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyu-Ho Lee 2017-10-19 11:18:23 -07:00
parent a8f9de2abf
commit ad24700252

View File

@ -143,6 +143,13 @@ func (hb *healthBalancer) updateUnhealthy(timeout time.Duration) {
case <-time.After(timeout):
hb.mu.Lock()
for k, v := range hb.unhealthy {
if _, ok := hb.host2ep[k]; !ok {
delete(hb.unhealthy, k)
if logger.V(4) {
logger.Infof("clientv3/health-balancer: removes stale host:port %q from unhealthy", k)
}
continue
}
if time.Since(v) > timeout {
delete(hb.unhealthy, k)
if logger.V(4) {
@ -189,6 +196,10 @@ func (hb *healthBalancer) endpointError(addr string, err error) {
func (hb *healthBalancer) mayPin(addr grpc.Address) bool {
hb.mu.RLock()
if _, ok := hb.host2ep[addr.Addr]; !ok { // stale endpoint
hb.mu.RUnlock()
return false
}
skip := len(hb.addrs) == 1 || len(hb.unhealthy) == 0 || len(hb.addrs) == len(hb.unhealthy)
failedTime, bad := hb.unhealthy[addr.Addr]
dur := hb.healthCheckTimeout