Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: aggregate the utils package within the client #8799

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion client/meta_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion client/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion client/pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions client/pd_service_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion client/tso_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions client/tso_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion client/tso_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions client/timerpool/pool.go → client/utils/timerutil/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133

package timerpool
package timerutil

import (
"sync"
"time"
)

// 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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133

package timerpool
package timerutil

import (
"testing"
"time"
)

func TestTimerPool(t *testing.T) {
var tp TimerPool
var tp timerPool

for range 100 {
timer := tp.Get(20 * time.Millisecond)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions pkg/timerpool/pool.go → pkg/utils/timerutil/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133

package timerpool
package timerutil

import (
"sync"
"time"
)

// 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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

// Note: This file is copied from https://go-review.googlesource.com/c/go/+/276133

package timerpool
package timerutil

import (
"testing"
"time"
)

func TestTimerPool(t *testing.T) {
var tp TimerPool
var tp timerPool

for range 100 {
timer := tp.Get(20 * time.Millisecond)
Expand Down
10 changes: 5 additions & 5 deletions pkg/utils/tsoutil/tso_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/resourcemanager/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/mcs/tso/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/realcluster/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/tso/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tools/pd-api-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-heartbeat-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down