Repository: zeromicro/go-zero
Pull request #1245 (2021-11-15 15:14:20)

Revert "feat: enable retry for zrpc (#1237)"
This reverts commit 09eb53f30819f14b434f6459077f74dadb35b4fc.


Patch:
diff --git a/zrpc/client.go b/zrpc/client.go
index 262c5523..91216606 100644
--- a/zrpc/client.go
+++ b/zrpc/client.go
@@ -19,7 +19,9 @@ var (
 	// WithTimeout is an alias of internal.WithTimeout.
 	WithTimeout = internal.WithTimeout
 	// WithRetry is an alias of internal.WithRetry.
-	WithRetry = internal.WithRetry
+	// TODO: enable it in v1.2.4
+	// WithRetry = internal.WithRetry
+
 	// WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
 	WithTransportCredentials = internal.WithTransportCredentials
 	// WithUnaryClientInterceptor is an alias of internal.WithUnaryClientInterceptor.
@@ -63,9 +65,10 @@ func NewClient(c RpcClientConf, options ...ClientOption) (Client, error) {
 	if c.Timeout > 0 {
 		opts = append(opts, WithTimeout(time.Duration(c.Timeout)*time.Millisecond))
 	}
-	if c.Retry {
-		opts = append(opts, WithRetry())
-	}
+	// TODO: enable it in v1.2.4
+	// if c.Retry {
+	// 	opts = append(opts, WithRetry())
+	// }
 	opts = append(opts, options...)
 
 	var target string
diff --git a/zrpc/config.go b/zrpc/config.go
index b3d33c89..69a5c2a4 100644
--- a/zrpc/config.go
+++ b/zrpc/config.go
@@ -18,7 +18,8 @@ type (
 		// setting 0 means no timeout
 		Timeout      int64 `json:",default=2000"`
 		CpuThreshold int64 `json:",default=900,range=[0:1000]"`
-		MaxRetries   int   `json:",default=0,range=[0:]"`
+		// TODO: enable it in v1.2.4
+		// MaxRetries   int   `json:",default=0,range=[0:]"`
 	}
 
 	// A RpcClientConf is a rpc client config.
@@ -29,8 +30,9 @@ type (
 		App       string          `json:",optional"`
 		Token     string          `json:",optional"`
 		NonBlock  bool            `json:",optional"`
-		Retry     bool            `json:",optional"` // grpc auto retry
-		Timeout   int64           `json:",default=2000"`
+		// TODO: enable it in v1.2.4
+		// Retry     bool            `json:",optional"` // grpc auto retry
+		Timeout int64 `json:",default=2000"`
 	}
 )
 
diff --git a/zrpc/server.go b/zrpc/server.go
index 34fe19d0..480d1124 100644
--- a/zrpc/server.go
+++ b/zrpc/server.go
@@ -38,10 +38,9 @@ func NewServer(c RpcServerConf, register internal.RegisterFn) (*RpcServer, error
 
 	var server internal.Server
 	metrics := stat.NewMetrics(c.ListenOn)
-	serverOptions := []internal.ServerOption{
-		internal.WithMetrics(metrics),
-		internal.WithMaxRetries(c.MaxRetries),
-	}
+	// TODO: enable it in v1.2.4
+	// serverOptions := []internal.ServerOption{internal.WithMetrics(metrics), internal.WithMaxRetries(c.MaxRetries)}
+	serverOptions := []internal.ServerOption{internal.WithMetrics(metrics)}
 
 	if c.HasEtcd() {
 		server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, serverOptions...)


Test patch:
diff --git a/core/hash/consistenthash_test.go b/core/hash/consistenthash_test.go
index 989a8d51..8d36366e 100644
--- a/core/hash/consistenthash_test.go
+++ b/core/hash/consistenthash_test.go
@@ -74,12 +74,12 @@ func TestConsistentHashIncrementalTransfer(t *testing.T) {
 		laterCh := create()
 		laterCh.AddWithWeight(node, 10*(i+1))
 
-		for i := 0; i < requestSize; i++ {
-			key, ok := laterCh.Get(requestSize + i)
+		for j := 0; j < requestSize; j++ {
+			key, ok := laterCh.Get(requestSize + j)
 			assert.True(t, ok)
 			assert.NotNil(t, key)
 			value := key.(string)
-			assert.True(t, value == keys[i] || value == node)
+			assert.True(t, value == keys[j] || value == node)
 		}
 	}
 }
diff --git a/zrpc/client_test.go b/zrpc/client_test.go
index 795fe24f..fe24c6cd 100644
--- a/zrpc/client_test.go
+++ b/zrpc/client_test.go
@@ -96,20 +96,21 @@ func TestDepositServer_Deposit(t *testing.T) {
 			return invoker(ctx, method, req, reply, cc, opts...)
 		}),
 	)
-	retryClient := MustNewClient(
-		RpcClientConf{
-			Endpoints: []string{"foo"},
-			App:       "foo",
-			Token:     "bar",
-			Timeout:   1000,
-			Retry:     true,
-		},
-		WithDialOption(grpc.WithContextDialer(dialer())),
-		WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
-			cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
-			return invoker(ctx, method, req, reply, cc, opts...)
-		}),
-	)
+	// TODO: enable it in v1.2.4
+	// retryClient := MustNewClient(
+	// 	RpcClientConf{
+	// 		Endpoints: []string{"foo"},
+	// 		App:       "foo",
+	// 		Token:     "bar",
+	// 		Timeout:   1000,
+	// 		Retry:     true,
+	// 	},
+	// 	WithDialOption(grpc.WithContextDialer(dialer())),
+	// 	WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
+	// 		cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+	// 		return invoker(ctx, method, req, reply, cc, opts...)
+	// 	}),
+	// )
 	tarConfClient := MustNewClient(
 		RpcClientConf{
 			Target:  "foo",
@@ -134,7 +135,8 @@ func TestDepositServer_Deposit(t *testing.T) {
 	clients := []Client{
 		directClient,
 		nonBlockClient,
-		retryClient,
+		// TODO: enable it in v1.2.4
+		// retryClient,
 		tarConfClient,
 		targetClient,
 	}