Skip to content

Commit

Permalink
Merge pull request #8659 from gyuho/pinned
Browse files Browse the repository at this point in the history
clientv3: add pinned() method to 'balancer'
  • Loading branch information
gyuho authored Oct 6, 2017
2 parents 077b361 + bed5f38 commit e8e3467
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions clientv3/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type balancer interface {

endpoint(host string) string
endpoints() []string
// pinned returns the current pinned endpoint.
pinned() string

// up is Up but includes whether the balancer will use the connection.
up(addr grpc.Address) (func(error), bool)
Expand Down Expand Up @@ -142,6 +144,12 @@ func (b *simpleBalancer) endpoints() []string {
return b.eps
}

func (b *simpleBalancer) pinned() string {
b.mu.RLock()
defer b.mu.RUnlock()
return b.pinAddr
}

func getHost2ep(eps []string) map[string]string {
hm := make(map[string]string, len(eps))
for i := range eps {
Expand Down
6 changes: 4 additions & 2 deletions clientv3/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRpcFunc {
case <-c.ctx.Done():
return c.ctx.Err()
}
pinned := c.balancer.pinned()
err := f(rpcCtx)
if err == nil {
return nil
}
if logger.V(4) {
logger.Infof("clientv3/retry: retry for error %v", err)
logger.Infof("clientv3/retry: error %v on pinned endpoint %s", err, pinned)
}
notify := c.balancer.ConnectNotify()
if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable {
Expand All @@ -86,12 +87,13 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRpcFunc {
func (c *Client) newAuthRetryWrapper() retryRpcFunc {
return func(rpcCtx context.Context, f rpcFunc) error {
for {
pinned := c.balancer.pinned()
err := f(rpcCtx)
if err == nil {
return nil
}
if logger.V(4) {
logger.Infof("clientv3/auth-retry: retry for error %v", err)
logger.Infof("clientv3/auth-retry: error %v on pinned endpoint %s", err, pinned)
}
// always stop retry on etcd errors other than invalid auth token
if rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken {
Expand Down

0 comments on commit e8e3467

Please sign in to comment.