diff --git a/client/client.go b/client/client.go index d9451ef3ffc..e1607051a34 100644 --- a/client/client.go +++ b/client/client.go @@ -33,8 +33,8 @@ import ( "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/tlsutil" - "github.com/tikv/pd/client/tsoutil" + "github.com/tikv/pd/client/utils/tlsutil" + "github.com/tikv/pd/client/utils/tsoutil" "go.uber.org/zap" ) diff --git a/client/client_test.go b/client/client_test.go index 76cded79053..2a26c24e1e2 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -22,8 +22,8 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" - "github.com/tikv/pd/client/testutil" - "github.com/tikv/pd/client/tsoutil" + "github.com/tikv/pd/client/utils/testutil" + "github.com/tikv/pd/client/utils/tsoutil" "go.uber.org/goleak" "google.golang.org/grpc" ) diff --git a/client/meta_storage_client.go b/client/meta_storage_client.go index 200491cf19a..a53d495241f 100644 --- a/client/meta_storage_client.go +++ b/client/meta_storage_client.go @@ -24,7 +24,7 @@ import ( "github.com/pingcap/kvproto/pkg/meta_storagepb" "github.com/prometheus/client_golang/prometheus" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/grpcutil" + "github.com/tikv/pd/client/utils/grpcutil" ) // MetaStorageClient is the interface for meta storage client. diff --git a/client/option_test.go b/client/option_test.go index 6dba0621078..84e5dd3abce 100644 --- a/client/option_test.go +++ b/client/option_test.go @@ -19,7 +19,7 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tikv/pd/client/testutil" + "github.com/tikv/pd/client/utils/testutil" ) func TestDynamicOptionChange(t *testing.T) { diff --git a/client/pd_service_discovery.go b/client/pd_service_discovery.go index 1c42f9b46c0..94c08f5c10d 100644 --- a/client/pd_service_discovery.go +++ b/client/pd_service_discovery.go @@ -30,8 +30,8 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/grpcutil" "github.com/tikv/pd/client/retry" + "github.com/tikv/pd/client/utils/grpcutil" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/client/pd_service_discovery_test.go b/client/pd_service_discovery_test.go index 794b03cc4aa..e553b087d34 100644 --- a/client/pd_service_discovery_test.go +++ b/client/pd_service_discovery_test.go @@ -30,8 +30,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/grpcutil" - "github.com/tikv/pd/client/testutil" + "github.com/tikv/pd/client/utils/grpcutil" + "github.com/tikv/pd/client/utils/testutil" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" pb "google.golang.org/grpc/examples/helloworld/helloworld" diff --git a/client/tso_client.go b/client/tso_client.go index 28f6482c627..d52a221c542 100644 --- a/client/tso_client.go +++ b/client/tso_client.go @@ -26,7 +26,7 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/log" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/grpcutil" + "github.com/tikv/pd/client/utils/grpcutil" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/client/tso_dispatcher.go b/client/tso_dispatcher.go index c8f9642ae50..a59dcaa7c61 100644 --- a/client/tso_dispatcher.go +++ b/client/tso_dispatcher.go @@ -30,8 +30,8 @@ import ( "github.com/pingcap/log" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/retry" - "github.com/tikv/pd/client/timerpool" - "github.com/tikv/pd/client/tsoutil" + "github.com/tikv/pd/client/utils/timerutil" + "github.com/tikv/pd/client/utils/tsoutil" "go.uber.org/zap" ) @@ -48,7 +48,7 @@ func newTSDeadline( done chan struct{}, cancel context.CancelFunc, ) *deadline { - timer := timerpool.GlobalTimerPool.Get(timeout) + timer := timerutil.GlobalTimerPool.Get(timeout) return &deadline{ timer: timer, done: done, @@ -151,11 +151,11 @@ func (td *tsoDispatcher) watchTSDeadline() { log.Error("[tso] tso request is canceled due to timeout", zap.String("dc-location", td.dc), errs.ZapError(errs.ErrClientGetTSOTimeout)) d.cancel() - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) case <-d.done: - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) case <-td.ctx.Done(): - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) return } case <-td.ctx.Done(): diff --git a/client/tso_service_discovery.go b/client/tso_service_discovery.go index fe690ed5f70..634b4211e38 100644 --- a/client/tso_service_discovery.go +++ b/client/tso_service_discovery.go @@ -30,7 +30,7 @@ import ( "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/grpcutil" + "github.com/tikv/pd/client/utils/grpcutil" "go.uber.org/zap" "google.golang.org/grpc" ) diff --git a/client/grpcutil/grpcutil.go b/client/utils/grpcutil/grpcutil.go similarity index 100% rename from client/grpcutil/grpcutil.go rename to client/utils/grpcutil/grpcutil.go diff --git a/client/testutil/check_env_dummy.go b/client/utils/testutil/check_env_dummy.go similarity index 100% rename from client/testutil/check_env_dummy.go rename to client/utils/testutil/check_env_dummy.go diff --git a/client/testutil/check_env_linux.go b/client/utils/testutil/check_env_linux.go similarity index 100% rename from client/testutil/check_env_linux.go rename to client/utils/testutil/check_env_linux.go diff --git a/client/testutil/leak.go b/client/utils/testutil/leak.go similarity index 100% rename from client/testutil/leak.go rename to client/utils/testutil/leak.go diff --git a/client/testutil/tempurl.go b/client/utils/testutil/tempurl.go similarity index 100% rename from client/testutil/tempurl.go rename to client/utils/testutil/tempurl.go diff --git a/client/testutil/testutil.go b/client/utils/testutil/testutil.go similarity index 100% rename from client/testutil/testutil.go rename to client/utils/testutil/testutil.go diff --git a/client/timerpool/pool.go b/client/utils/timerutil/pool.go similarity index 78% rename from client/timerpool/pool.go rename to client/utils/timerutil/pool.go index 28ffacfc629..cee061201c2 100644 --- a/client/timerpool/pool.go +++ b/client/utils/timerutil/pool.go @@ -4,7 +4,7 @@ // Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 -package timerpool +package timerutil import ( "sync" @@ -12,15 +12,15 @@ import ( ) // GlobalTimerPool is a global pool for reusing *time.Timer. -var GlobalTimerPool TimerPool +var GlobalTimerPool timerPool -// TimerPool is a wrapper of sync.Pool which caches *time.Timer for reuse. -type TimerPool struct { +// timerPool is a wrapper of sync.Pool which caches *time.Timer for reuse. +type timerPool struct { pool sync.Pool } // Get returns a timer with a given duration. -func (tp *TimerPool) Get(d time.Duration) *time.Timer { +func (tp *timerPool) Get(d time.Duration) *time.Timer { if v := tp.pool.Get(); v != nil { timer := v.(*time.Timer) timer.Reset(d) @@ -32,7 +32,7 @@ func (tp *TimerPool) Get(d time.Duration) *time.Timer { // Put tries to call timer.Stop() before putting it back into pool, // if the timer.Stop() returns false (it has either already expired or been stopped), // have a shot at draining the channel with residual time if there is one. -func (tp *TimerPool) Put(timer *time.Timer) { +func (tp *timerPool) Put(timer *time.Timer) { if !timer.Stop() { select { case <-timer.C: diff --git a/client/timerpool/pool_test.go b/client/utils/timerutil/pool_test.go similarity index 97% rename from client/timerpool/pool_test.go rename to client/utils/timerutil/pool_test.go index e10291f1027..3e0575daea3 100644 --- a/client/timerpool/pool_test.go +++ b/client/utils/timerutil/pool_test.go @@ -4,7 +4,7 @@ // Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 -package timerpool +package timerutil import ( "testing" @@ -12,7 +12,7 @@ import ( ) func TestTimerPool(t *testing.T) { - var tp TimerPool + var tp timerPool for range 100 { timer := tp.Get(20 * time.Millisecond) diff --git a/client/tlsutil/OWNERS b/client/utils/tlsutil/OWNERS similarity index 100% rename from client/tlsutil/OWNERS rename to client/utils/tlsutil/OWNERS diff --git a/client/tlsutil/tlsconfig.go b/client/utils/tlsutil/tlsconfig.go similarity index 100% rename from client/tlsutil/tlsconfig.go rename to client/utils/tlsutil/tlsconfig.go diff --git a/client/tlsutil/tlsutil.go b/client/utils/tlsutil/tlsutil.go similarity index 100% rename from client/tlsutil/tlsutil.go rename to client/utils/tlsutil/tlsutil.go diff --git a/client/tsoutil/tsoutil.go b/client/utils/tsoutil/tsoutil.go similarity index 100% rename from client/tsoutil/tsoutil.go rename to client/utils/tsoutil/tsoutil.go diff --git a/pkg/timerpool/pool.go b/pkg/utils/timerutil/pool.go similarity index 78% rename from pkg/timerpool/pool.go rename to pkg/utils/timerutil/pool.go index 28ffacfc629..cee061201c2 100644 --- a/pkg/timerpool/pool.go +++ b/pkg/utils/timerutil/pool.go @@ -4,7 +4,7 @@ // Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 -package timerpool +package timerutil import ( "sync" @@ -12,15 +12,15 @@ import ( ) // GlobalTimerPool is a global pool for reusing *time.Timer. -var GlobalTimerPool TimerPool +var GlobalTimerPool timerPool -// TimerPool is a wrapper of sync.Pool which caches *time.Timer for reuse. -type TimerPool struct { +// timerPool is a wrapper of sync.Pool which caches *time.Timer for reuse. +type timerPool struct { pool sync.Pool } // Get returns a timer with a given duration. -func (tp *TimerPool) Get(d time.Duration) *time.Timer { +func (tp *timerPool) Get(d time.Duration) *time.Timer { if v := tp.pool.Get(); v != nil { timer := v.(*time.Timer) timer.Reset(d) @@ -32,7 +32,7 @@ func (tp *TimerPool) Get(d time.Duration) *time.Timer { // Put tries to call timer.Stop() before putting it back into pool, // if the timer.Stop() returns false (it has either already expired or been stopped), // have a shot at draining the channel with residual time if there is one. -func (tp *TimerPool) Put(timer *time.Timer) { +func (tp *timerPool) Put(timer *time.Timer) { if !timer.Stop() { select { case <-timer.C: diff --git a/pkg/timerpool/pool_test.go b/pkg/utils/timerutil/pool_test.go similarity index 97% rename from pkg/timerpool/pool_test.go rename to pkg/utils/timerutil/pool_test.go index e10291f1027..3e0575daea3 100644 --- a/pkg/timerpool/pool_test.go +++ b/pkg/utils/timerutil/pool_test.go @@ -4,7 +4,7 @@ // Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133 -package timerpool +package timerutil import ( "testing" @@ -12,7 +12,7 @@ import ( ) func TestTimerPool(t *testing.T) { - var tp TimerPool + var tp timerPool for range 100 { timer := tp.Get(20 * time.Millisecond) diff --git a/pkg/utils/tsoutil/tso_dispatcher.go b/pkg/utils/tsoutil/tso_dispatcher.go index 4240ce875b4..c4aa96274e1 100644 --- a/pkg/utils/tsoutil/tso_dispatcher.go +++ b/pkg/utils/tsoutil/tso_dispatcher.go @@ -24,9 +24,9 @@ import ( "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" "github.com/tikv/pd/pkg/errs" - "github.com/tikv/pd/pkg/timerpool" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/timerutil" "go.uber.org/zap" "google.golang.org/grpc" ) @@ -209,7 +209,7 @@ func NewTSDeadline( done chan struct{}, cancel context.CancelFunc, ) *TSDeadline { - timer := timerpool.GlobalTimerPool.Get(timeout) + timer := timerutil.GlobalTimerPool.Get(timeout) return &TSDeadline{ timer: timer, done: done, @@ -230,11 +230,11 @@ func WatchTSDeadline(ctx context.Context, tsDeadlineCh <-chan *TSDeadline) { log.Error("tso proxy request processing is canceled due to timeout", errs.ZapError(errs.ErrProxyTSOTimeout)) d.cancel() - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) case <-d.done: - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) case <-ctx.Done(): - timerpool.GlobalTimerPool.Put(d.timer) + timerutil.GlobalTimerPool.Put(d.timer) return } case <-ctx.Done(): diff --git a/tests/integrations/client/client_test.go b/tests/integrations/client/client_test.go index 97cd0c5c043..ea6cc872c08 100644 --- a/tests/integrations/client/client_test.go +++ b/tests/integrations/client/client_test.go @@ -790,7 +790,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetTsoAndRegionByFollowerFor leader := cluster.GetLeaderServer() follower := cluster.GetServer(cluster.GetFollower()) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/grpcutil/unreachableNetwork2", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/utils/grpcutil/unreachableNetwork2", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) cli := setupCli(ctx, re, suite.endpoints, pd.WithForwardingOption(true)) defer cli.Close() @@ -829,7 +829,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetTsoAndRegionByFollowerFor return false }) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/grpcutil/unreachableNetwork2")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/utils/grpcutil/unreachableNetwork2")) testutil.Eventually(re, func() bool { physical, logical, err := cli.GetTS(context.TODO()) if err == nil { @@ -859,7 +859,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromLeaderWhenNetwo leader := cluster.GetLeaderServer() follower := cluster.GetServer(cluster.GetFollower()) - re.NoError(failpoint.Enable("github.com/tikv/pd/client/grpcutil/unreachableNetwork2", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) + re.NoError(failpoint.Enable("github.com/tikv/pd/client/utils/grpcutil/unreachableNetwork2", fmt.Sprintf("return(\"%s\")", follower.GetAddr()))) cli := setupCli(ctx, re, suite.endpoints) defer cli.Close() @@ -877,7 +877,7 @@ func (suite *followerForwardAndHandleTestSuite) TestGetRegionFromLeaderWhenNetwo re.Error(err) re.Nil(r) - re.NoError(failpoint.Disable("github.com/tikv/pd/client/grpcutil/unreachableNetwork2")) + re.NoError(failpoint.Disable("github.com/tikv/pd/client/utils/grpcutil/unreachableNetwork2")) cli.GetServiceDiscovery().CheckMemberChanged() testutil.Eventually(re, func() bool { r, err = cli.GetRegion(context.Background(), []byte("a")) diff --git a/tests/integrations/mcs/resourcemanager/server_test.go b/tests/integrations/mcs/resourcemanager/server_test.go index 5ab8745f7be..7ca83ad6bac 100644 --- a/tests/integrations/mcs/resourcemanager/server_test.go +++ b/tests/integrations/mcs/resourcemanager/server_test.go @@ -24,7 +24,7 @@ import ( rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/stretchr/testify/require" - "github.com/tikv/pd/client/grpcutil" + "github.com/tikv/pd/client/utils/grpcutil" bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/utils/tempurl" "github.com/tikv/pd/pkg/versioninfo" diff --git a/tests/integrations/mcs/tso/proxy_test.go b/tests/integrations/mcs/tso/proxy_test.go index 1d3ba31a8ab..9dfd232348d 100644 --- a/tests/integrations/mcs/tso/proxy_test.go +++ b/tests/integrations/mcs/tso/proxy_test.go @@ -29,7 +29,7 @@ import ( "github.com/pingcap/log" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/tikv/pd/client/tsoutil" + "github.com/tikv/pd/client/utils/tsoutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/tests" "go.uber.org/zap" diff --git a/tests/integrations/realcluster/scheduler_test.go b/tests/integrations/realcluster/scheduler_test.go index c5bb2acee0e..369ca176233 100644 --- a/tests/integrations/realcluster/scheduler_test.go +++ b/tests/integrations/realcluster/scheduler_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/tikv/pd/client/http" - "github.com/tikv/pd/client/testutil" + "github.com/tikv/pd/client/utils/testutil" "github.com/tikv/pd/pkg/schedule/labeler" "github.com/tikv/pd/pkg/schedule/types" ) diff --git a/tests/integrations/tso/client_test.go b/tests/integrations/tso/client_test.go index a2bc138fcf6..41564a4b3de 100644 --- a/tests/integrations/tso/client_test.go +++ b/tests/integrations/tso/client_test.go @@ -29,7 +29,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" pd "github.com/tikv/pd/client" - "github.com/tikv/pd/client/testutil" + "github.com/tikv/pd/client/utils/testutil" bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/slice" diff --git a/tools/pd-api-bench/main.go b/tools/pd-api-bench/main.go index c7af4c61ac6..a61eff39cb1 100644 --- a/tools/pd-api-bench/main.go +++ b/tools/pd-api-bench/main.go @@ -35,7 +35,7 @@ import ( flag "github.com/spf13/pflag" pd "github.com/tikv/pd/client" pdHttp "github.com/tikv/pd/client/http" - "github.com/tikv/pd/client/tlsutil" + "github.com/tikv/pd/client/utils/tlsutil" "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/tools/pd-api-bench/cases" diff --git a/tools/pd-heartbeat-bench/main.go b/tools/pd-heartbeat-bench/main.go index a3200bf773a..996f1bd6839 100644 --- a/tools/pd-heartbeat-bench/main.go +++ b/tools/pd-heartbeat-bench/main.go @@ -39,9 +39,9 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" "github.com/spf13/pflag" - "github.com/tikv/pd/client/grpcutil" pdHttp "github.com/tikv/pd/client/http" - "github.com/tikv/pd/client/tlsutil" + "github.com/tikv/pd/client/utils/grpcutil" + "github.com/tikv/pd/client/utils/tlsutil" "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/statistics"