Repository: tikv/client-go
Pull request #186 (2021-06-29 04:17:37)

*: move retry to internal package
Fix https://github.com/tikv/client-go/issues/185


Patch:
diff --git a/client/client_batch.go b/client/client_batch.go
index 68b1318..9b3e826 100644
--- a/client/client_batch.go
+++ b/client/client_batch.go
@@ -46,9 +46,9 @@ import (
 	"github.com/pingcap/parser/terror"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/tikv/client-go/v2/config"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	"go.uber.org/zap"
diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go
index a2333b9..f5fb472 100644
--- a/internal/locate/region_cache.go
+++ b/internal/locate/region_cache.go
@@ -51,10 +51,10 @@ import (
 	"github.com/pingcap/parser/terror"
 	"github.com/tikv/client-go/v2/client"
 	"github.com/tikv/client-go/v2/config"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	pd "github.com/tikv/pd/client"
diff --git a/internal/locate/region_request.go b/internal/locate/region_request.go
index 3fce0dc..fd7ea83 100644
--- a/internal/locate/region_request.go
+++ b/internal/locate/region_request.go
@@ -53,11 +53,11 @@ import (
 	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
 	"github.com/tikv/client-go/v2/oracle"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 )
diff --git a/retry/backoff.go b/internal/retry/backoff.go
similarity index 100%
rename from retry/backoff.go
rename to internal/retry/backoff.go
diff --git a/retry/backoff_test.go b/internal/retry/backoff_test.go
similarity index 100%
rename from retry/backoff_test.go
rename to internal/retry/backoff_test.go
diff --git a/retry/config.go b/internal/retry/config.go
similarity index 100%
rename from retry/config.go
rename to internal/retry/config.go
diff --git a/retry/main_test.go b/internal/retry/main_test.go
similarity index 100%
rename from retry/main_test.go
rename to internal/retry/main_test.go
diff --git a/retry/retry.go b/retry/retry.go
new file mode 100644
index 0000000..f5c6ae7
--- /dev/null
+++ b/retry/retry.go
@@ -0,0 +1,25 @@
+// Copyright 2021 TiKV Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package retry
+
+import "github.com/tikv/client-go/v2/internal/retry"
+
+// Re-export internal/retry for compatibility.
+// TODO: Remove it.
+
+// NewNoopBackoff create a Backoffer do nothing just return error directly
+var NewNoopBackoff = retry.NewNoopBackoff
+
+// BoTiFlashRPC is the backoff config for TiFlash RPCs.
+var BoTiFlashRPC = retry.BoTiFlashRPC
diff --git a/tikv/2pc.go b/tikv/2pc.go
index b455f95..fe86222 100644
--- a/tikv/2pc.go
+++ b/tikv/2pc.go
@@ -52,12 +52,12 @@ import (
 	"github.com/tikv/client-go/v2/config"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/internal/unionstore"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
 	"github.com/tikv/client-go/v2/oracle"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	zap "go.uber.org/zap"
diff --git a/tikv/backoff.go b/tikv/backoff.go
index 82505e6..b8f13ed 100644
--- a/tikv/backoff.go
+++ b/tikv/backoff.go
@@ -35,8 +35,8 @@ package tikv
 import (
 	"context"
 
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
-	"github.com/tikv/client-go/v2/retry"
 )
 
 // Backoffer is a utility for retrying queries.
@@ -103,3 +103,6 @@ func BoTiKVRPC() *BackoffConfig {
 func NewGcResolveLockMaxBackoffer(ctx context.Context) *Backoffer {
 	return retry.NewBackofferWithVars(ctx, gcResolveLockMaxBackoff, nil)
 }
+
+// NewNoopBackoff create a Backoffer do nothing just return error directly
+var NewNoopBackoff = retry.NewNoopBackoff
diff --git a/tikv/cleanup.go b/tikv/cleanup.go
index e21fb1d..db15492 100644
--- a/tikv/cleanup.go
+++ b/tikv/cleanup.go
@@ -37,9 +37,9 @@ import (
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/tikv/client-go/v2/client"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"go.uber.org/zap"
 )
diff --git a/tikv/commit.go b/tikv/commit.go
index 00d28c3..033b041 100644
--- a/tikv/commit.go
+++ b/tikv/commit.go
@@ -43,9 +43,9 @@ import (
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"go.uber.org/zap"
 )
diff --git a/tikv/delete_range.go b/tikv/delete_range.go
index 00f57fa..ee1bb87 100644
--- a/tikv/delete_range.go
+++ b/tikv/delete_range.go
@@ -40,8 +40,8 @@ import (
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 )
 
diff --git a/tikv/gc.go b/tikv/gc.go
index 5e988f9..9ca42fd 100644
--- a/tikv/gc.go
+++ b/tikv/gc.go
@@ -21,9 +21,9 @@ import (
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	zap "go.uber.org/zap"
 )
diff --git a/tikv/kv.go b/tikv/kv.go
index d0aaf56..a7a128b 100644
--- a/tikv/kv.go
+++ b/tikv/kv.go
@@ -52,12 +52,12 @@ import (
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/latch"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
 	"github.com/tikv/client-go/v2/oracle"
 	"github.com/tikv/client-go/v2/oracle/oracles"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	pd "github.com/tikv/pd/client"
diff --git a/tikv/lock_resolver.go b/tikv/lock_resolver.go
index 4d51943..3810cf4 100644
--- a/tikv/lock_resolver.go
+++ b/tikv/lock_resolver.go
@@ -48,10 +48,10 @@ import (
 	"github.com/tikv/client-go/v2/config"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
 	"github.com/tikv/client-go/v2/oracle"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	pd "github.com/tikv/pd/client"
diff --git a/tikv/pessimistic.go b/tikv/pessimistic.go
index c719c8b..2fa0cf9 100644
--- a/tikv/pessimistic.go
+++ b/tikv/pessimistic.go
@@ -45,10 +45,10 @@ import (
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	"go.uber.org/zap"
diff --git a/tikv/prewrite.go b/tikv/prewrite.go
index de7859d..2d4f649 100644
--- a/tikv/prewrite.go
+++ b/tikv/prewrite.go
@@ -46,9 +46,9 @@ import (
 	"github.com/tikv/client-go/v2/config"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	"go.uber.org/zap"
diff --git a/tikv/range_task.go b/tikv/range_task.go
index 8e154cf..a21a2be 100644
--- a/tikv/range_task.go
+++ b/tikv/range_task.go
@@ -40,10 +40,10 @@ import (
 	"time"
 
 	"github.com/pingcap/errors"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"go.uber.org/zap"
 )
 
diff --git a/tikv/rawkv.go b/tikv/rawkv.go
index 88ae664..70fbfe2 100644
--- a/tikv/rawkv.go
+++ b/tikv/rawkv.go
@@ -43,8 +43,8 @@ import (
 	"github.com/tikv/client-go/v2/config"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	pd "github.com/tikv/pd/client"
 )
diff --git a/tikv/scan.go b/tikv/scan.go
index 8a40431..9da4ee0 100644
--- a/tikv/scan.go
+++ b/tikv/scan.go
@@ -41,9 +41,9 @@ import (
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"go.uber.org/zap"
 )
diff --git a/tikv/snapshot.go b/tikv/snapshot.go
index 440eb70..cf53f27 100644
--- a/tikv/snapshot.go
+++ b/tikv/snapshot.go
@@ -49,10 +49,10 @@ import (
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	"go.uber.org/zap"
diff --git a/tikv/split_region.go b/tikv/split_region.go
index d988513..830f853 100644
--- a/tikv/split_region.go
+++ b/tikv/split_region.go
@@ -46,9 +46,9 @@ import (
 	"github.com/tikv/client-go/v2/client"
 	tikverr "github.com/tikv/client-go/v2/error"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"github.com/tikv/client-go/v2/util"
 	pd "github.com/tikv/pd/client"
diff --git a/tikv/txn.go b/tikv/txn.go
index 3b3466c..273297f 100644
--- a/tikv/txn.go
+++ b/tikv/txn.go
@@ -49,12 +49,12 @@ import (
 	"github.com/pingcap/errors"
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	tikverr "github.com/tikv/client-go/v2/error"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/internal/unionstore"
 	tikv "github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/logutil"
 	"github.com/tikv/client-go/v2/metrics"
 	"github.com/tikv/client-go/v2/oracle"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/util"
 	"go.uber.org/zap"
 )


Test patch:
diff --git a/internal/locate/region_cache_test.go b/internal/locate/region_cache_test.go
index 98a181b..efd2dbd 100644
--- a/internal/locate/region_cache_test.go
+++ b/internal/locate/region_cache_test.go
@@ -46,10 +46,10 @@ import (
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/stretchr/testify/suite"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/mockstore/mocktikv"
 	"github.com/tikv/client-go/v2/oracle"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	pd "github.com/tikv/pd/client"
 )
diff --git a/internal/locate/region_request3_test.go b/internal/locate/region_request3_test.go
index 79da3a5..83a9421 100644
--- a/internal/locate/region_request3_test.go
+++ b/internal/locate/region_request3_test.go
@@ -45,9 +45,9 @@ import (
 	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/stretchr/testify/suite"
 	tikverr "github.com/tikv/client-go/v2/error"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/mockstore/mocktikv"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 )
 
diff --git a/internal/locate/region_request_test.go b/internal/locate/region_request_test.go
index 3427a73..0bb6e60 100644
--- a/internal/locate/region_request_test.go
+++ b/internal/locate/region_request_test.go
@@ -51,8 +51,8 @@ import (
 	"github.com/stretchr/testify/suite"
 	"github.com/tikv/client-go/v2/client"
 	"github.com/tikv/client-go/v2/config"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/mockstore/mocktikv"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	"google.golang.org/grpc"
 )
diff --git a/tikv/rawkv_test.go b/tikv/rawkv_test.go
index 7f29322..94ceede 100644
--- a/tikv/rawkv_test.go
+++ b/tikv/rawkv_test.go
@@ -38,9 +38,9 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/suite"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/kv"
 	"github.com/tikv/client-go/v2/mockstore/mocktikv"
-	"github.com/tikv/client-go/v2/retry"
 )
 
 func TestRawKV(t *testing.T) {
diff --git a/tikv/test_probe.go b/tikv/test_probe.go
index e2c7cc6..6d5d5b8 100644
--- a/tikv/test_probe.go
+++ b/tikv/test_probe.go
@@ -42,8 +42,8 @@ import (
 	"github.com/pingcap/kvproto/pkg/kvrpcpb"
 	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/tikv/client-go/v2/internal/locate"
+	"github.com/tikv/client-go/v2/internal/retry"
 	"github.com/tikv/client-go/v2/internal/unionstore"
-	"github.com/tikv/client-go/v2/retry"
 	"github.com/tikv/client-go/v2/tikvrpc"
 	pd "github.com/tikv/pd/client"
 )