Browse Source

clientv3: only stop if EtcdError code is not Unavailable, retry with more error codes

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Gyu-Ho Lee 8 years ago
parent
commit
725df70664
1 changed files with 9 additions and 4 deletions
  1. 9 4
      clientv3/retry.go

+ 9 - 4
clientv3/retry.go

@@ -32,7 +32,7 @@ type retryStopErrFunc func(error) bool
 func isRepeatableStopError(err error) bool {
 func isRepeatableStopError(err error) bool {
 	eErr := rpctypes.Error(err)
 	eErr := rpctypes.Error(err)
 	// always stop retry on etcd errors
 	// always stop retry on etcd errors
-	if _, ok := eErr.(rpctypes.EtcdError); ok {
+	if serverErr, ok := eErr.(rpctypes.EtcdError); ok && serverErr.Code() != codes.Unavailable {
 		return true
 		return true
 	}
 	}
 	// only retry if unavailable
 	// only retry if unavailable
@@ -62,11 +62,16 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRPCFunc {
 			if logger.V(4) {
 			if logger.V(4) {
 				logger.Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned)
 				logger.Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned)
 			}
 			}
-			// mark this before endpoint switch is triggered
-			c.balancer.hostPortError(pinned, err)
-			if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable {
+
+			if s, ok := status.FromError(err); ok && (s.Code() == codes.Unavailable || s.Code() == codes.DeadlineExceeded || s.Code() == codes.Internal) {
+				// mark this before endpoint switch is triggered
+				c.balancer.hostPortError(pinned, err)
 				c.balancer.next()
 				c.balancer.next()
+				if logger.V(4) {
+					logger.Infof("clientv3/retry: switching from %q due to error %q", pinned, err.Error())
+				}
 			}
 			}
+
 			if isStop(err) {
 			if isStop(err) {
 				return err
 				return err
 			}
 			}