|
|
@@ -26,7 +26,7 @@ import (
|
|
|
)
|
|
|
|
|
|
type rpcFunc func(ctx context.Context) error
|
|
|
-type retryRpcFunc func(context.Context, rpcFunc) error
|
|
|
+type retryRPCFunc func(context.Context, rpcFunc) error
|
|
|
type retryStopErrFunc func(error) bool
|
|
|
|
|
|
func isReadStopError(err error) bool {
|
|
|
@@ -48,7 +48,7 @@ func isWriteStopError(err error) bool {
|
|
|
return rpctypes.ErrorDesc(err) != "there is no address available"
|
|
|
}
|
|
|
|
|
|
-func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRpcFunc {
|
|
|
+func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRPCFunc {
|
|
|
return func(rpcCtx context.Context, f rpcFunc) error {
|
|
|
for {
|
|
|
select {
|
|
|
@@ -64,10 +64,10 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRpcFunc {
|
|
|
return nil
|
|
|
}
|
|
|
if logger.V(4) {
|
|
|
- logger.Infof("clientv3/retry: error %v on pinned endpoint %s", err, pinned)
|
|
|
+ logger.Infof("clientv3/retry: error %q on pinned endpoint %q", err.Error(), pinned)
|
|
|
}
|
|
|
// mark this before endpoint switch is triggered
|
|
|
- c.balancer.endpointError(pinned, err)
|
|
|
+ c.balancer.hostPortError(pinned, err)
|
|
|
notify := c.balancer.ConnectNotify()
|
|
|
if s, ok := status.FromError(err); ok && s.Code() == codes.Unavailable {
|
|
|
c.balancer.next()
|
|
|
@@ -86,7 +86,7 @@ func (c *Client) newRetryWrapper(isStop retryStopErrFunc) retryRpcFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (c *Client) newAuthRetryWrapper() retryRpcFunc {
|
|
|
+func (c *Client) newAuthRetryWrapper() retryRPCFunc {
|
|
|
return func(rpcCtx context.Context, f rpcFunc) error {
|
|
|
for {
|
|
|
pinned := c.balancer.pinned()
|
|
|
@@ -95,12 +95,15 @@ func (c *Client) newAuthRetryWrapper() retryRpcFunc {
|
|
|
return nil
|
|
|
}
|
|
|
if logger.V(4) {
|
|
|
- logger.Infof("clientv3/auth-retry: error %v on pinned endpoint %s", err, pinned)
|
|
|
+ logger.Infof("clientv3/auth-retry: error %q on pinned endpoint %q", err.Error(), pinned)
|
|
|
}
|
|
|
// always stop retry on etcd errors other than invalid auth token
|
|
|
if rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken {
|
|
|
gterr := c.getToken(rpcCtx)
|
|
|
if gterr != nil {
|
|
|
+ if logger.V(4) {
|
|
|
+ logger.Infof("clientv3/auth-retry: cannot retry due to error %q(%q) on pinned endpoint %q", err.Error(), gterr.Error(), pinned)
|
|
|
+ }
|
|
|
return err // return the original error for simplicity
|
|
|
}
|
|
|
continue
|
|
|
@@ -124,7 +127,7 @@ func RetryKVClient(c *Client) pb.KVClient {
|
|
|
|
|
|
type retryKVClient struct {
|
|
|
*retryWriteKVClient
|
|
|
- readRetry retryRpcFunc
|
|
|
+ readRetry retryRPCFunc
|
|
|
}
|
|
|
|
|
|
func (rkv *retryKVClient) Range(ctx context.Context, in *pb.RangeRequest, opts ...grpc.CallOption) (resp *pb.RangeResponse, err error) {
|
|
|
@@ -137,11 +140,11 @@ func (rkv *retryKVClient) Range(ctx context.Context, in *pb.RangeRequest, opts .
|
|
|
|
|
|
type retryWriteKVClient struct {
|
|
|
pb.KVClient
|
|
|
- retryf retryRpcFunc
|
|
|
+ writeRetry retryRPCFunc
|
|
|
}
|
|
|
|
|
|
func (rkv *retryWriteKVClient) Put(ctx context.Context, in *pb.PutRequest, opts ...grpc.CallOption) (resp *pb.PutResponse, err error) {
|
|
|
- err = rkv.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rkv.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rkv.KVClient.Put(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -149,7 +152,7 @@ func (rkv *retryWriteKVClient) Put(ctx context.Context, in *pb.PutRequest, opts
|
|
|
}
|
|
|
|
|
|
func (rkv *retryWriteKVClient) DeleteRange(ctx context.Context, in *pb.DeleteRangeRequest, opts ...grpc.CallOption) (resp *pb.DeleteRangeResponse, err error) {
|
|
|
- err = rkv.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rkv.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rkv.KVClient.DeleteRange(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -157,7 +160,7 @@ func (rkv *retryWriteKVClient) DeleteRange(ctx context.Context, in *pb.DeleteRan
|
|
|
}
|
|
|
|
|
|
func (rkv *retryWriteKVClient) Txn(ctx context.Context, in *pb.TxnRequest, opts ...grpc.CallOption) (resp *pb.TxnResponse, err error) {
|
|
|
- err = rkv.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rkv.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rkv.KVClient.Txn(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -165,7 +168,7 @@ func (rkv *retryWriteKVClient) Txn(ctx context.Context, in *pb.TxnRequest, opts
|
|
|
}
|
|
|
|
|
|
func (rkv *retryWriteKVClient) Compact(ctx context.Context, in *pb.CompactionRequest, opts ...grpc.CallOption) (resp *pb.CompactionResponse, err error) {
|
|
|
- err = rkv.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rkv.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rkv.KVClient.Compact(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -174,7 +177,7 @@ func (rkv *retryWriteKVClient) Compact(ctx context.Context, in *pb.CompactionReq
|
|
|
|
|
|
type retryLeaseClient struct {
|
|
|
pb.LeaseClient
|
|
|
- retryf retryRpcFunc
|
|
|
+ readRetry retryRPCFunc
|
|
|
}
|
|
|
|
|
|
// RetryLeaseClient implements a LeaseClient that uses the client's FailFast retry policy.
|
|
|
@@ -187,7 +190,7 @@ func RetryLeaseClient(c *Client) pb.LeaseClient {
|
|
|
}
|
|
|
|
|
|
func (rlc *retryLeaseClient) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (resp *pb.LeaseGrantResponse, err error) {
|
|
|
- err = rlc.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rlc.readRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rlc.LeaseClient.LeaseGrant(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -196,7 +199,7 @@ func (rlc *retryLeaseClient) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRe
|
|
|
}
|
|
|
|
|
|
func (rlc *retryLeaseClient) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (resp *pb.LeaseRevokeResponse, err error) {
|
|
|
- err = rlc.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rlc.readRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rlc.LeaseClient.LeaseRevoke(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -205,7 +208,7 @@ func (rlc *retryLeaseClient) LeaseRevoke(ctx context.Context, in *pb.LeaseRevoke
|
|
|
|
|
|
type retryClusterClient struct {
|
|
|
pb.ClusterClient
|
|
|
- retryf retryRpcFunc
|
|
|
+ writeRetry retryRPCFunc
|
|
|
}
|
|
|
|
|
|
// RetryClusterClient implements a ClusterClient that uses the client's FailFast retry policy.
|
|
|
@@ -214,7 +217,7 @@ func RetryClusterClient(c *Client) pb.ClusterClient {
|
|
|
}
|
|
|
|
|
|
func (rcc *retryClusterClient) MemberAdd(ctx context.Context, in *pb.MemberAddRequest, opts ...grpc.CallOption) (resp *pb.MemberAddResponse, err error) {
|
|
|
- err = rcc.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rcc.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rcc.ClusterClient.MemberAdd(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -222,7 +225,7 @@ func (rcc *retryClusterClient) MemberAdd(ctx context.Context, in *pb.MemberAddRe
|
|
|
}
|
|
|
|
|
|
func (rcc *retryClusterClient) MemberRemove(ctx context.Context, in *pb.MemberRemoveRequest, opts ...grpc.CallOption) (resp *pb.MemberRemoveResponse, err error) {
|
|
|
- err = rcc.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rcc.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rcc.ClusterClient.MemberRemove(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -230,7 +233,7 @@ func (rcc *retryClusterClient) MemberRemove(ctx context.Context, in *pb.MemberRe
|
|
|
}
|
|
|
|
|
|
func (rcc *retryClusterClient) MemberUpdate(ctx context.Context, in *pb.MemberUpdateRequest, opts ...grpc.CallOption) (resp *pb.MemberUpdateResponse, err error) {
|
|
|
- err = rcc.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rcc.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rcc.ClusterClient.MemberUpdate(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -239,7 +242,7 @@ func (rcc *retryClusterClient) MemberUpdate(ctx context.Context, in *pb.MemberUp
|
|
|
|
|
|
type retryAuthClient struct {
|
|
|
pb.AuthClient
|
|
|
- retryf retryRpcFunc
|
|
|
+ writeRetry retryRPCFunc
|
|
|
}
|
|
|
|
|
|
// RetryAuthClient implements a AuthClient that uses the client's FailFast retry policy.
|
|
|
@@ -248,7 +251,7 @@ func RetryAuthClient(c *Client) pb.AuthClient {
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) AuthEnable(ctx context.Context, in *pb.AuthEnableRequest, opts ...grpc.CallOption) (resp *pb.AuthEnableResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.AuthEnable(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -256,7 +259,7 @@ func (rac *retryAuthClient) AuthEnable(ctx context.Context, in *pb.AuthEnableReq
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) AuthDisable(ctx context.Context, in *pb.AuthDisableRequest, opts ...grpc.CallOption) (resp *pb.AuthDisableResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.AuthDisable(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -264,7 +267,7 @@ func (rac *retryAuthClient) AuthDisable(ctx context.Context, in *pb.AuthDisableR
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) UserAdd(ctx context.Context, in *pb.AuthUserAddRequest, opts ...grpc.CallOption) (resp *pb.AuthUserAddResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.UserAdd(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -272,7 +275,7 @@ func (rac *retryAuthClient) UserAdd(ctx context.Context, in *pb.AuthUserAddReque
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) UserDelete(ctx context.Context, in *pb.AuthUserDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthUserDeleteResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.UserDelete(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -280,7 +283,7 @@ func (rac *retryAuthClient) UserDelete(ctx context.Context, in *pb.AuthUserDelet
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) UserChangePassword(ctx context.Context, in *pb.AuthUserChangePasswordRequest, opts ...grpc.CallOption) (resp *pb.AuthUserChangePasswordResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.UserChangePassword(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -288,7 +291,7 @@ func (rac *retryAuthClient) UserChangePassword(ctx context.Context, in *pb.AuthU
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) UserGrantRole(ctx context.Context, in *pb.AuthUserGrantRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserGrantRoleResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.UserGrantRole(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -296,7 +299,7 @@ func (rac *retryAuthClient) UserGrantRole(ctx context.Context, in *pb.AuthUserGr
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) UserRevokeRole(ctx context.Context, in *pb.AuthUserRevokeRoleRequest, opts ...grpc.CallOption) (resp *pb.AuthUserRevokeRoleResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.UserRevokeRole(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -304,7 +307,7 @@ func (rac *retryAuthClient) UserRevokeRole(ctx context.Context, in *pb.AuthUserR
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) RoleAdd(ctx context.Context, in *pb.AuthRoleAddRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleAddResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.RoleAdd(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -312,7 +315,7 @@ func (rac *retryAuthClient) RoleAdd(ctx context.Context, in *pb.AuthRoleAddReque
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) RoleDelete(ctx context.Context, in *pb.AuthRoleDeleteRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleDeleteResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.RoleDelete(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -320,7 +323,7 @@ func (rac *retryAuthClient) RoleDelete(ctx context.Context, in *pb.AuthRoleDelet
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) RoleGrantPermission(ctx context.Context, in *pb.AuthRoleGrantPermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleGrantPermissionResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.RoleGrantPermission(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|
|
|
@@ -328,7 +331,7 @@ func (rac *retryAuthClient) RoleGrantPermission(ctx context.Context, in *pb.Auth
|
|
|
}
|
|
|
|
|
|
func (rac *retryAuthClient) RoleRevokePermission(ctx context.Context, in *pb.AuthRoleRevokePermissionRequest, opts ...grpc.CallOption) (resp *pb.AuthRoleRevokePermissionResponse, err error) {
|
|
|
- err = rac.retryf(ctx, func(rctx context.Context) error {
|
|
|
+ err = rac.writeRetry(ctx, func(rctx context.Context) error {
|
|
|
resp, err = rac.AuthClient.RoleRevokePermission(rctx, in, opts...)
|
|
|
return err
|
|
|
})
|