Skip to content

Commit

Permalink
Merge branch 'master' into fix-panic6
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Dec 19, 2024
2 parents 68993a3 + ac59675 commit 7f3cf27
Show file tree
Hide file tree
Showing 601 changed files with 5,403 additions and 1,385 deletions.
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters:
- protogetter
- reassign
- intrange
- gci
linters-settings:
gocritic:
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
Expand Down Expand Up @@ -233,6 +234,13 @@ linters-settings:
desc: "Use 'sync/atomic' instead of 'go.uber.org/atomic'"
- pkg: github.com/pkg/errors
desc: "Use 'github.com/pingcap/errors' instead of 'github.com/pkg/errors'"
gci:
sections:
- standard
- default
- prefix(github.com/pingcap)
- prefix(github.com/tikv/pd)
- blank
issues:
exclude-rules:
- path: (_test\.go|pkg/mock/.*\.go|tests/.*\.go)
Expand Down
49 changes: 36 additions & 13 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ import (
"time"

"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"
"github.com/prometheus/client_golang/prometheus"

"github.com/tikv/pd/client/clients/metastorage"
"github.com/tikv/pd/client/clients/router"
"github.com/tikv/pd/client/clients/tso"
Expand All @@ -37,9 +42,9 @@ import (
"github.com/tikv/pd/client/metrics"
"github.com/tikv/pd/client/opt"
"github.com/tikv/pd/client/pkg/caller"
cb "github.com/tikv/pd/client/pkg/circuitbreaker"
"github.com/tikv/pd/client/pkg/utils/tlsutil"
sd "github.com/tikv/pd/client/servicediscovery"
"go.uber.org/zap"
)

// GlobalConfigItem standard format of KV pair in GlobalConfig client
Expand Down Expand Up @@ -456,6 +461,12 @@ func (c *client) UpdateOption(option opt.DynamicOption, value any) error {
return errors.New("[pd] invalid value type for TSOClientRPCConcurrency option, it should be int")
}
c.inner.option.SetTSOClientRPCConcurrency(value)
case opt.RegionMetadataCircuitBreakerSettings:
applySettingsChange, ok := value.(func(config *cb.Settings))
if !ok {
return errors.New("[pd] invalid value type for RegionMetadataCircuitBreakerSettings option, it should be pd.Settings")
}
c.inner.regionMetaCircuitBreaker.ChangeSettings(applySettingsChange)
default:
return errors.New("[pd] unsupported client option")
}
Expand Down Expand Up @@ -501,10 +512,10 @@ func (c *client) GetTSAsync(ctx context.Context) tso.TSFuture {
return c.inner.dispatchTSORequestWithRetry(ctx)
}

// GetLocalTSAsync implements the TSOClient interface.
//
// Deprecated: Local TSO will be completely removed in the future. Currently, regardless of the
// parameters passed in, this method will default to returning the global TSO.
// Deprecated: the Local TSO feature has been deprecated. Regardless of the
// parameters passed, the behavior of this interface will be equivalent to
// `GetTSAsync`. If you want to use a separately deployed TSO service,
// please refer to the deployment of the TSO microservice.
func (c *client) GetLocalTSAsync(ctx context.Context, _ string) tso.TSFuture {
return c.GetTSAsync(ctx)
}
Expand All @@ -515,10 +526,10 @@ func (c *client) GetTS(ctx context.Context) (physical int64, logical int64, err
return resp.Wait()
}

// GetLocalTS implements the TSOClient interface.
//
// Deprecated: Local TSO will be completely removed in the future. Currently, regardless of the
// parameters passed in, this method will default to returning the global TSO.
// Deprecated: the Local TSO feature has been deprecated. Regardless of the
// parameters passed, the behavior of this interface will be equivalent to
// `GetTS`. If you want to use a separately deployed TSO service,
// please refer to the deployment of the TSO microservice.
func (c *client) GetLocalTS(ctx context.Context, _ string) (physical int64, logical int64, err error) {
return c.GetTS(ctx)
}
Expand Down Expand Up @@ -650,7 +661,13 @@ func (c *client) GetRegion(ctx context.Context, key []byte, opts ...opt.GetRegio
if serviceClient == nil {
return nil, errs.ErrClientGetProtoClient
}
resp, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetRegion(cctx, req)
resp, err := c.inner.regionMetaCircuitBreaker.Execute(func() (*pdpb.GetRegionResponse, cb.Overloading, error) {
region, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetRegion(cctx, req)
failpoint.Inject("triggerCircuitBreaker", func() {
err = status.Error(codes.ResourceExhausted, "resource exhausted")
})
return region, isOverloaded(err), err
})
if serviceClient.NeedRetry(resp.GetHeader().GetError(), err) {
protoClient, cctx := c.getClientAndContext(ctx)
if protoClient == nil {
Expand Down Expand Up @@ -690,7 +707,10 @@ func (c *client) GetPrevRegion(ctx context.Context, key []byte, opts ...opt.GetR
if serviceClient == nil {
return nil, errs.ErrClientGetProtoClient
}
resp, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetPrevRegion(cctx, req)
resp, err := c.inner.regionMetaCircuitBreaker.Execute(func() (*pdpb.GetRegionResponse, cb.Overloading, error) {
resp, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetPrevRegion(cctx, req)
return resp, isOverloaded(err), err
})
if serviceClient.NeedRetry(resp.GetHeader().GetError(), err) {
protoClient, cctx := c.getClientAndContext(ctx)
if protoClient == nil {
Expand Down Expand Up @@ -730,7 +750,10 @@ func (c *client) GetRegionByID(ctx context.Context, regionID uint64, opts ...opt
if serviceClient == nil {
return nil, errs.ErrClientGetProtoClient
}
resp, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetRegionByID(cctx, req)
resp, err := c.inner.regionMetaCircuitBreaker.Execute(func() (*pdpb.GetRegionResponse, cb.Overloading, error) {
resp, err := pdpb.NewPDClient(serviceClient.GetClientConn()).GetRegionByID(cctx, req)
return resp, isOverloaded(err), err
})
if serviceClient.NeedRetry(resp.GetHeader().GetError(), err) {
protoClient, cctx := c.getClientAndContext(ctx)
if protoClient == nil {
Expand Down
3 changes: 2 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"time"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/tikv/pd/client/opt"
"github.com/tikv/pd/client/pkg/caller"
"github.com/tikv/pd/client/pkg/utils/testutil"
"github.com/tikv/pd/client/pkg/utils/tsoutil"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
Expand Down
1 change: 1 addition & 0 deletions client/clients/metastorage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"

"github.com/pingcap/kvproto/pkg/meta_storagepb"

"github.com/tikv/pd/client/opt"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"

"github.com/pingcap/kvproto/pkg/metapb"

"github.com/tikv/pd/client/opt"
)

Expand Down
28 changes: 15 additions & 13 deletions client/clients/tso/tso_client.go → client/clients/tso/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ import (
"sync/atomic"
"time"

"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"

"github.com/tikv/pd/client/constants"
"github.com/tikv/pd/client/errs"
"github.com/tikv/pd/client/metrics"
"github.com/tikv/pd/client/opt"
"github.com/tikv/pd/client/pkg/utils/grpcutil"
"github.com/tikv/pd/client/pkg/utils/tlsutil"
sd "github.com/tikv/pd/client/servicediscovery"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
)

const (
Expand All @@ -56,15 +58,15 @@ type Client interface {
// the TSO microservice.
GetMinTS(ctx context.Context) (int64, int64, error)

// GetLocalTS gets a local timestamp from PD or TSO microservice.
//
// Deprecated: Local TSO will be completely removed in the future. Currently, regardless of the
// parameters passed in, this method will default to returning the global TSO.
// Deprecated: the Local TSO feature has been deprecated. Regardless of the
// parameters passed, the behavior of this interface will be equivalent to
// `GetTS`. If you want to use a separately deployed TSO service,
// please refer to the deployment of the TSO microservice.
GetLocalTS(ctx context.Context, _ string) (int64, int64, error)
// GetLocalTSAsync gets a local timestamp from PD or TSO microservice, without block the caller.
//
// Deprecated: Local TSO will be completely removed in the future. Currently, regardless of the
// parameters passed in, this method will default to returning the global TSO.
// Deprecated: the Local TSO feature has been deprecated. Regardless of the
// parameters passed, the behavior of this interface will be equivalent to
// `GetTSAsync`. If you want to use a separately deployed TSO service,
// please refer to the deployment of the TSO microservice.
GetLocalTSAsync(ctx context.Context, _ string) TSFuture
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import (
"time"

"github.com/opentracing/opentracing-go"
"go.uber.org/zap"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"

"github.com/tikv/pd/client/constants"
"github.com/tikv/pd/client/errs"
"github.com/tikv/pd/client/metrics"
Expand All @@ -37,7 +40,6 @@ import (
"github.com/tikv/pd/client/pkg/utils/timerutil"
"github.com/tikv/pd/client/pkg/utils/tsoutil"
sd "github.com/tikv/pd/client/servicediscovery"
"go.uber.org/zap"
)

// deadline is used to control the TS request timeout manually,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/zap/zapcore"

"github.com/pingcap/failpoint"
"github.com/pingcap/log"

"github.com/tikv/pd/client/opt"
sd "github.com/tikv/pd/client/servicediscovery"
"go.uber.org/zap/zapcore"
)

type mockTSOServiceProvider struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/pingcap/errors"

"github.com/tikv/pd/client/metrics"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
"context"
"testing"

"github.com/pingcap/errors"
"github.com/stretchr/testify/require"

"github.com/pingcap/errors"
)

func TestTsoRequestWait(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ import (
"sync/atomic"
"time"

"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"google.golang.org/grpc"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/kvproto/pkg/tsopb"
"github.com/pingcap/log"
"github.com/prometheus/client_golang/prometheus"

"github.com/tikv/pd/client/constants"
"github.com/tikv/pd/client/errs"
"github.com/tikv/pd/client/metrics"
"go.uber.org/zap"
"google.golang.org/grpc"
)

// TSO Stream Builder Factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"testing"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/tikv/pd/client/errs"
"go.uber.org/zap/zapcore"

"github.com/pingcap/errors"
"github.com/pingcap/log"

"github.com/tikv/pd/client/errs"
)

const mockStreamURL = "mock:///"
Expand Down
1 change: 1 addition & 0 deletions client/errs/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
ErrClientGetServingEndpoint = errors.Normalize("get serving endpoint failed", errors.RFCCodeText("PD:client:ErrClientGetServingEndpoint"))
ErrClientFindGroupByKeyspaceID = errors.Normalize("can't find keyspace group by keyspace id", errors.RFCCodeText("PD:client:ErrClientFindGroupByKeyspaceID"))
ErrClientWatchGCSafePointV2Stream = errors.Normalize("watch gc safe point v2 stream failed", errors.RFCCodeText("PD:client:ErrClientWatchGCSafePointV2Stream"))
ErrCircuitBreakerOpen = errors.Normalize("circuit breaker is open", errors.RFCCodeText("PD:client:ErrCircuitBreakerOpen"))
)

// grpcutil errors
Expand Down
3 changes: 2 additions & 1 deletion client/errs/errs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package errs
import (
"strings"

"github.com/pingcap/errors"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/grpc/codes"

"github.com/pingcap/errors"
)

// IsLeaderChange will determine whether there is a leader/primary change.
Expand Down
4 changes: 3 additions & 1 deletion client/gc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import (
"time"

"github.com/opentracing/opentracing-go"
"go.uber.org/zap"

"github.com/pingcap/kvproto/pkg/pdpb"
"github.com/pingcap/log"

"github.com/tikv/pd/client/errs"
"github.com/tikv/pd/client/metrics"
"go.uber.org/zap"
)

// GCClient is a client for doing GC
Expand Down
23 changes: 12 additions & 11 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/kvproto v0.0.0-20241120071417-b5b7843d9037
github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3
github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.8.2
github.com/prometheus/client_golang v1.20.5
github.com/stretchr/testify v1.9.0
go.uber.org/goleak v1.1.11
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4
Expand All @@ -24,22 +24,23 @@ require (
require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.46.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 7f3cf27

Please sign in to comment.