diff --git a/.golangci.yml b/.golangci.yml index e13feb04ba5..a44052b22e8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -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) diff --git a/client/client.go b/client/client.go index 49ce73bf9fb..272d6c597b5 100644 --- a/client/client.go +++ b/client/client.go @@ -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" @@ -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 @@ -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") } @@ -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) } @@ -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) } @@ -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 { @@ -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 { @@ -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 { diff --git a/client/client_test.go b/client/client_test.go index f4f914900cd..305d054fa18 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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) { diff --git a/client/clients/metastorage/client.go b/client/clients/metastorage/client.go index dba1127f9f5..baac1ab7539 100644 --- a/client/clients/metastorage/client.go +++ b/client/clients/metastorage/client.go @@ -18,6 +18,7 @@ import ( "context" "github.com/pingcap/kvproto/pkg/meta_storagepb" + "github.com/tikv/pd/client/opt" ) diff --git a/client/clients/router/router_client.go b/client/clients/router/client.go similarity index 99% rename from client/clients/router/router_client.go rename to client/clients/router/client.go index 667c82a6805..48cebfa950e 100644 --- a/client/clients/router/router_client.go +++ b/client/clients/router/client.go @@ -20,6 +20,7 @@ import ( "net/url" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/client/opt" ) diff --git a/client/clients/tso/tso_client.go b/client/clients/tso/client.go similarity index 96% rename from client/clients/tso/tso_client.go rename to client/clients/tso/client.go index 9c7075fe3bb..c26dd25f2ad 100644 --- a/client/clients/tso/tso_client.go +++ b/client/clients/tso/client.go @@ -22,9 +22,16 @@ 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" @@ -32,11 +39,6 @@ import ( "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 ( @@ -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 } diff --git a/client/clients/tso/tso_dispatcher.go b/client/clients/tso/dispatcher.go similarity index 99% rename from client/clients/tso/tso_dispatcher.go rename to client/clients/tso/dispatcher.go index 1b805395904..bdac8096f85 100644 --- a/client/clients/tso/tso_dispatcher.go +++ b/client/clients/tso/dispatcher.go @@ -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" @@ -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, diff --git a/client/clients/tso/tso_dispatcher_test.go b/client/clients/tso/dispatcher_test.go similarity index 99% rename from client/clients/tso/tso_dispatcher_test.go rename to client/clients/tso/dispatcher_test.go index 2b5fd1e52e8..cefc53f3944 100644 --- a/client/clients/tso/tso_dispatcher_test.go +++ b/client/clients/tso/dispatcher_test.go @@ -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 { diff --git a/client/clients/tso/tso_request.go b/client/clients/tso/request.go similarity index 99% rename from client/clients/tso/tso_request.go rename to client/clients/tso/request.go index 0c9f54f8b2b..9c0d8e6bea6 100644 --- a/client/clients/tso/tso_request.go +++ b/client/clients/tso/request.go @@ -21,6 +21,7 @@ import ( "time" "github.com/pingcap/errors" + "github.com/tikv/pd/client/metrics" ) diff --git a/client/clients/tso/tso_request_test.go b/client/clients/tso/request_test.go similarity index 99% rename from client/clients/tso/tso_request_test.go rename to client/clients/tso/request_test.go index 6887ee28124..4be50eaea68 100644 --- a/client/clients/tso/tso_request_test.go +++ b/client/clients/tso/request_test.go @@ -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) { diff --git a/client/clients/tso/tso_stream.go b/client/clients/tso/stream.go similarity index 99% rename from client/clients/tso/tso_stream.go rename to client/clients/tso/stream.go index 6baf63c8882..291d1d31b65 100644 --- a/client/clients/tso/tso_stream.go +++ b/client/clients/tso/stream.go @@ -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 diff --git a/client/clients/tso/tso_stream_test.go b/client/clients/tso/stream_test.go similarity index 99% rename from client/clients/tso/tso_stream_test.go rename to client/clients/tso/stream_test.go index 0244c06e024..4791b90bb81 100644 --- a/client/clients/tso/tso_stream_test.go +++ b/client/clients/tso/stream_test.go @@ -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:///" diff --git a/client/errs/errno.go b/client/errs/errno.go index df8b677525a..25665f01017 100644 --- a/client/errs/errno.go +++ b/client/errs/errno.go @@ -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 diff --git a/client/errs/errs.go b/client/errs/errs.go index 67a5dd8ec92..868faa6a77a 100644 --- a/client/errs/errs.go +++ b/client/errs/errs.go @@ -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. diff --git a/client/gc_client.go b/client/gc_client.go index f30521905c3..45fc8b40b91 100644 --- a/client/gc_client.go +++ b/client/gc_client.go @@ -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 diff --git a/client/go.mod b/client/go.mod index ba7b077f46d..b26abcbea55 100644 --- a/client/go.mod +++ b/client/go.mod @@ -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 @@ -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 ) diff --git a/client/go.sum b/client/go.sum index e229c47ee96..36c58efb823 100644 --- a/client/go.sum +++ b/client/go.sum @@ -7,8 +7,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 h1:BjkPE3785EwPhhyuFkbINB+2a1xATwk8SNDWnJiD41g= github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5/go.mod h1:jtAfVaU/2cu1+wdSRPWE2c1N2qeAA3K4RH9pYgqwets= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cloudfoundry/gosigar v1.3.6 h1:gIc08FbB3QPb+nAQhINIK/qhf5REKkY0FTGgRGXkcVc= github.com/cloudfoundry/gosigar v1.3.6/go.mod h1:lNWstu5g5gw59O09Y+wsMNFzBSnU8a0u+Sfx4dq360E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -26,12 +26,16 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= @@ -55,28 +59,25 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= -github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y= -github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= @@ -111,8 +112,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -123,13 +124,13 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -138,8 +139,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -153,8 +154,8 @@ google.golang.org/grpc/examples v0.0.0-20231221225426-4f03f3ff32c9 h1:ATnmU8nL2N google.golang.org/grpc/examples v0.0.0-20231221225426-4f03f3ff32c9/go.mod h1:j5uROIAAgi3YmtiETMt1LW0d/lHqQ7wwrIY4uGRXLQ4= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/client/http/client.go b/client/http/client.go index c813474fcf6..fa9801cf764 100644 --- a/client/http/client.go +++ b/client/http/client.go @@ -23,13 +23,15 @@ import ( "net/http" "time" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/pkg/retry" sd "github.com/tikv/pd/client/servicediscovery" - "go.uber.org/zap" ) const ( diff --git a/client/http/client_test.go b/client/http/client_test.go index a14691eed02..b6c2105bd4a 100644 --- a/client/http/client_test.go +++ b/client/http/client_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/pkg/retry" ) diff --git a/client/http/interface.go b/client/http/interface.go index 772599e27fb..1aabd1ae331 100644 --- a/client/http/interface.go +++ b/client/http/interface.go @@ -26,6 +26,7 @@ import ( "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/client/pkg/retry" ) diff --git a/client/http/request_info.go b/client/http/request_info.go index 1e3449b59a0..d1930800304 100644 --- a/client/http/request_info.go +++ b/client/http/request_info.go @@ -17,8 +17,9 @@ package http import ( "fmt" - "github.com/tikv/pd/client/pkg/retry" "go.uber.org/zap" + + "github.com/tikv/pd/client/pkg/retry" ) // The following constants are the names of the requests. diff --git a/client/http/types.go b/client/http/types.go index cab564e99ac..83e8badf334 100644 --- a/client/http/types.go +++ b/client/http/types.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/pingcap/kvproto/pkg/pdpb" + pd "github.com/tikv/pd/client/clients/router" ) diff --git a/client/inner_client.go b/client/inner_client.go index 7be35e9a3b9..91f999dd3b5 100644 --- a/client/inner_client.go +++ b/client/inner_client.go @@ -6,16 +6,21 @@ import ( "sync" "time" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/client/clients/tso" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/metrics" "github.com/tikv/pd/client/opt" + cb "github.com/tikv/pd/client/pkg/circuitbreaker" sd "github.com/tikv/pd/client/servicediscovery" - "go.uber.org/zap" - "google.golang.org/grpc" ) const ( @@ -24,10 +29,11 @@ const ( ) type innerClient struct { - keyspaceID uint32 - svrUrls []string - pdSvcDiscovery sd.ServiceDiscovery - tokenDispatcher *tokenDispatcher + keyspaceID uint32 + svrUrls []string + pdSvcDiscovery sd.ServiceDiscovery + tokenDispatcher *tokenDispatcher + regionMetaCircuitBreaker *cb.CircuitBreaker[*pdpb.GetRegionResponse] // For service mode switching. serviceModeKeeper @@ -53,6 +59,7 @@ func (c *innerClient) init(updateKeyspaceIDCb sd.UpdateKeyspaceIDFunc) error { } return err } + c.regionMetaCircuitBreaker = cb.NewCircuitBreaker[*pdpb.GetRegionResponse]("region_meta", c.option.RegionMetaCircuitBreakerSettings) return nil } @@ -245,3 +252,12 @@ func (c *innerClient) dispatchTSORequestWithRetry(ctx context.Context) tso.TSFut } return req } + +func isOverloaded(err error) cb.Overloading { + switch status.Code(errors.Cause(err)) { + case codes.DeadlineExceeded, codes.Unavailable, codes.ResourceExhausted: + return cb.Yes + default: + return cb.No + } +} diff --git a/client/keyspace_client.go b/client/keyspace_client.go index ce0cc0bc426..84bc29054eb 100644 --- a/client/keyspace_client.go +++ b/client/keyspace_client.go @@ -19,8 +19,10 @@ import ( "time" "github.com/opentracing/opentracing-go" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/metrics" ) diff --git a/client/meta_storage_client.go b/client/meta_storage_client.go index 45bcb8d3d65..fbabd60debd 100644 --- a/client/meta_storage_client.go +++ b/client/meta_storage_client.go @@ -19,10 +19,12 @@ import ( "time" "github.com/opentracing/opentracing-go" + "github.com/prometheus/client_golang/prometheus" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/meta_storagepb" - "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/metrics" "github.com/tikv/pd/client/opt" diff --git a/client/metrics/metrics.go b/client/metrics/metrics.go index da36217eb34..67268c826f5 100644 --- a/client/metrics/metrics.go +++ b/client/metrics/metrics.go @@ -56,6 +56,8 @@ var ( OngoingRequestCountGauge *prometheus.GaugeVec // EstimateTSOLatencyGauge is the gauge to indicate the estimated latency of TSO requests. EstimateTSOLatencyGauge *prometheus.GaugeVec + // CircuitBreakerCounters is a vector for different circuit breaker counters + CircuitBreakerCounters *prometheus.CounterVec ) func initMetrics(constLabels prometheus.Labels) { @@ -144,6 +146,15 @@ func initMetrics(constLabels prometheus.Labels) { Help: "Estimated latency of an RTT of getting TSO", ConstLabels: constLabels, }, []string{"stream"}) + + CircuitBreakerCounters = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "pd_client", + Subsystem: "request", + Name: "circuit_breaker_count", + Help: "Circuit breaker counters", + ConstLabels: constLabels, + }, []string{"name", "success"}) } // CmdDurationXXX and CmdFailedDurationXXX are the durations of the client commands. @@ -259,4 +270,5 @@ func registerMetrics() { prometheus.MustRegister(TSOBatchSendLatency) prometheus.MustRegister(RequestForwarded) prometheus.MustRegister(EstimateTSOLatencyGauge) + prometheus.MustRegister(CircuitBreakerCounters) } diff --git a/client/opt/option.go b/client/opt/option.go index faeb232195f..af95a225fab 100644 --- a/client/opt/option.go +++ b/client/opt/option.go @@ -18,10 +18,13 @@ import ( "sync/atomic" "time" - "github.com/pingcap/errors" "github.com/prometheus/client_golang/prometheus" - "github.com/tikv/pd/client/pkg/retry" "google.golang.org/grpc" + + "github.com/pingcap/errors" + + cb "github.com/tikv/pd/client/pkg/circuitbreaker" + "github.com/tikv/pd/client/pkg/retry" ) const ( @@ -47,6 +50,8 @@ const ( EnableFollowerHandle // TSOClientRPCConcurrency controls the amount of ongoing TSO RPC requests at the same time in a single TSO client. TSOClientRPCConcurrency + // RegionMetadataCircuitBreakerSettings controls settings for circuit breaker for region metadata requests. + RegionMetadataCircuitBreakerSettings dynamicOptionCount ) @@ -67,16 +72,18 @@ type Option struct { // Dynamic options. dynamicOptions [dynamicOptionCount]atomic.Value - EnableTSOFollowerProxyCh chan struct{} + EnableTSOFollowerProxyCh chan struct{} + RegionMetaCircuitBreakerSettings cb.Settings } // NewOption creates a new PD client option with the default values set. func NewOption() *Option { co := &Option{ - Timeout: defaultPDTimeout, - MaxRetryTimes: maxInitClusterRetries, - EnableTSOFollowerProxyCh: make(chan struct{}, 1), - InitMetrics: true, + Timeout: defaultPDTimeout, + MaxRetryTimes: maxInitClusterRetries, + EnableTSOFollowerProxyCh: make(chan struct{}, 1), + InitMetrics: true, + RegionMetaCircuitBreakerSettings: cb.AlwaysClosedSettings, } co.dynamicOptions[MaxTSOBatchWaitInterval].Store(defaultMaxTSOBatchWaitInterval) @@ -147,6 +154,11 @@ func (o *Option) GetTSOClientRPCConcurrency() int { return o.dynamicOptions[TSOClientRPCConcurrency].Load().(int) } +// GetRegionMetadataCircuitBreakerSettings gets circuit breaker settings for PD region metadata calls. +func (o *Option) GetRegionMetadataCircuitBreakerSettings() cb.Settings { + return o.dynamicOptions[RegionMetadataCircuitBreakerSettings].Load().(cb.Settings) +} + // ClientOption configures client. type ClientOption func(*Option) @@ -201,6 +213,13 @@ func WithInitMetricsOption(initMetrics bool) ClientOption { } } +// WithRegionMetaCircuitBreaker configures the client with circuit breaker for region meta calls +func WithRegionMetaCircuitBreaker(config cb.Settings) ClientOption { + return func(op *Option) { + op.RegionMetaCircuitBreakerSettings = config + } +} + // WithBackoffer configures the client with backoffer. func WithBackoffer(bo *retry.Backoffer) ClientOption { return func(op *Option) { diff --git a/client/opt/option_test.go b/client/opt/option_test.go index 26760fac7f2..fa0decbb3a1 100644 --- a/client/opt/option_test.go +++ b/client/opt/option_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/client/pkg/utils/testutil" ) diff --git a/client/pkg/batch/batch_controller.go b/client/pkg/batch/batch_controller.go index 32f0aaba1ae..322502b754a 100644 --- a/client/pkg/batch/batch_controller.go +++ b/client/pkg/batch/batch_controller.go @@ -60,13 +60,18 @@ func NewController[T any](maxBatchSize int, finisher FinisherFunc[T], bestBatchO // It returns nil error if everything goes well, otherwise a non-nil error which means we should stop the service. // It's guaranteed that if this function failed after collecting some requests, then these requests will be cancelled // when the function returns, so the caller don't need to clear them manually. +// `tokenCh` is an optional parameter: +// - If it's nil, the batching process will not wait for the token to arrive to continue. +// - If it's not nil, the batching process will wait for a token to arrive before continuing. +// The token will be given back if any error occurs, otherwise it's the caller's responsibility +// to decide when to recycle the signal. func (bc *Controller[T]) FetchPendingRequests(ctx context.Context, requestCh <-chan T, tokenCh chan struct{}, maxBatchWaitInterval time.Duration) (errRet error) { var tokenAcquired bool defer func() { if errRet != nil { // Something went wrong when collecting a batch of requests. Release the token and cancel collected requests // if any. - if tokenAcquired { + if tokenAcquired && tokenCh != nil { tokenCh <- struct{}{} } bc.FinishCollectedRequests(bc.finisher, errRet) @@ -80,6 +85,9 @@ func (bc *Controller[T]) FetchPendingRequests(ctx context.Context, requestCh <-c // If the batch size reaches the maxBatchSize limit but the token haven't arrived yet, don't receive more // requests, and return when token is ready. if bc.collectedRequestCount >= bc.maxBatchSize && !tokenAcquired { + if tokenCh == nil { + return nil + } select { case <-ctx.Done(): return ctx.Err() @@ -88,20 +96,23 @@ func (bc *Controller[T]) FetchPendingRequests(ctx context.Context, requestCh <-c } } - select { - case <-ctx.Done(): - return ctx.Err() - case req := <-requestCh: - // Start to batch when the first request arrives. - bc.pushRequest(req) - // A request arrives but the token is not ready yet. Continue waiting, and also allowing collecting the next - // request if it arrives. - continue - case <-tokenCh: - tokenAcquired = true + if tokenCh != nil { + select { + case <-ctx.Done(): + return ctx.Err() + case req := <-requestCh: + // Start to batch when the first request arrives. + bc.pushRequest(req) + // A request arrives but the token is not ready yet. Continue waiting, and also allowing collecting the next + // request if it arrives. + continue + case <-tokenCh: + tokenAcquired = true + } } - // The token is ready. If the first request didn't arrive, wait for it. + // After the token is ready or it's working without token, + // wait for the first request to arrive. if bc.collectedRequestCount == 0 { select { case <-ctx.Done(): diff --git a/client/pkg/batch/batch_controller_test.go b/client/pkg/batch/batch_controller_test.go index 7c9ffa6944f..92aef14bd35 100644 --- a/client/pkg/batch/batch_controller_test.go +++ b/client/pkg/batch/batch_controller_test.go @@ -21,9 +21,11 @@ import ( "github.com/stretchr/testify/require" ) +const testMaxBatchSize = 20 + func TestAdjustBestBatchSize(t *testing.T) { re := require.New(t) - bc := NewController[int](20, nil, nil) + bc := NewController[int](testMaxBatchSize, nil, nil) re.Equal(defaultBestBatchSize, bc.bestBatchSize) bc.AdjustBestBatchSize() re.Equal(defaultBestBatchSize-1, bc.bestBatchSize) @@ -52,7 +54,7 @@ type testRequest struct { func TestFinishCollectedRequests(t *testing.T) { re := require.New(t) - bc := NewController[*testRequest](20, nil, nil) + bc := NewController[*testRequest](testMaxBatchSize, nil, nil) // Finish with zero request count. re.Zero(bc.collectedRequestCount) bc.FinishCollectedRequests(nil, nil) @@ -81,3 +83,58 @@ func TestFinishCollectedRequests(t *testing.T) { re.Equal(context.Canceled, requests[i].err) } } + +func TestFetchPendingRequests(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + re := require.New(t) + bc := NewController[int](testMaxBatchSize, nil, nil) + requestCh := make(chan int, testMaxBatchSize+1) + // Fetch a nil `tokenCh`. + requestCh <- 1 + re.NoError(bc.FetchPendingRequests(ctx, requestCh, nil, 0)) + re.Empty(requestCh) + re.Equal(1, bc.collectedRequestCount) + // Fetch a nil `tokenCh` with max batch size. + for i := range testMaxBatchSize { + requestCh <- i + } + re.NoError(bc.FetchPendingRequests(ctx, requestCh, nil, 0)) + re.Empty(requestCh) + re.Equal(testMaxBatchSize, bc.collectedRequestCount) + // Fetch a nil `tokenCh` with max batch size + 1. + for i := range testMaxBatchSize + 1 { + requestCh <- i + } + re.NoError(bc.FetchPendingRequests(ctx, requestCh, nil, 0)) + re.Len(requestCh, 1) + re.Equal(testMaxBatchSize, bc.collectedRequestCount) + // Drain the requestCh. + <-requestCh + // Fetch a non-nil `tokenCh`. + tokenCh := make(chan struct{}, 1) + requestCh <- 1 + tokenCh <- struct{}{} + re.NoError(bc.FetchPendingRequests(ctx, requestCh, tokenCh, 0)) + re.Empty(requestCh) + re.Equal(1, bc.collectedRequestCount) + // Fetch a non-nil `tokenCh` with max batch size. + for i := range testMaxBatchSize { + requestCh <- i + } + tokenCh <- struct{}{} + re.NoError(bc.FetchPendingRequests(ctx, requestCh, tokenCh, 0)) + re.Empty(requestCh) + re.Equal(testMaxBatchSize, bc.collectedRequestCount) + // Fetch a non-nil `tokenCh` with max batch size + 1. + for i := range testMaxBatchSize + 1 { + requestCh <- i + } + tokenCh <- struct{}{} + re.NoError(bc.FetchPendingRequests(ctx, requestCh, tokenCh, 0)) + re.Len(requestCh, 1) + re.Equal(testMaxBatchSize, bc.collectedRequestCount) + // Drain the requestCh. + <-requestCh +} diff --git a/client/pkg/circuitbreaker/circuit_breaker.go b/client/pkg/circuitbreaker/circuit_breaker.go new file mode 100644 index 00000000000..2c65f4f1965 --- /dev/null +++ b/client/pkg/circuitbreaker/circuit_breaker.go @@ -0,0 +1,311 @@ +// Copyright 2024 TiKV Project 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, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package circuitbreaker + +import ( + "fmt" + "strings" + "sync" + "time" + + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + + "github.com/pingcap/log" + + "github.com/tikv/pd/client/errs" + m "github.com/tikv/pd/client/metrics" +) + +// Overloading is a type describing service return value +type Overloading bool + +const ( + // No means the service is not overloaded + No = false + // Yes means the service is overloaded + Yes = true +) + +// Settings describes configuration for Circuit Breaker +type Settings struct { + // Defines the error rate threshold to trip the circuit breaker. + ErrorRateThresholdPct uint32 + // Defines the average qps over the `error_rate_window` that must be met before evaluating the error rate threshold. + MinQPSForOpen uint32 + // Defines how long to track errors before evaluating error_rate_threshold. + ErrorRateWindow time.Duration + // Defines how long to wait after circuit breaker is open before go to half-open state to send a probe request. + CoolDownInterval time.Duration + // Defines how many subsequent requests to test after cooldown period before fully close the circuit. + HalfOpenSuccessCount uint32 +} + +// AlwaysClosedSettings is a configuration that never trips the circuit breaker. +var AlwaysClosedSettings = Settings{ + ErrorRateThresholdPct: 0, // never trips + ErrorRateWindow: 10 * time.Second, // effectively results in testing for new settings every 10 seconds + MinQPSForOpen: 10, + CoolDownInterval: 10 * time.Second, + HalfOpenSuccessCount: 1, +} + +// CircuitBreaker is a state machine to prevent sending requests that are likely to fail. +type CircuitBreaker[T any] struct { + config *Settings + name string + + mutex sync.Mutex + state *State[T] + + successCounter prometheus.Counter + errorCounter prometheus.Counter + overloadCounter prometheus.Counter + fastFailCounter prometheus.Counter +} + +// StateType is a type that represents a state of CircuitBreaker. +type StateType int + +// States of CircuitBreaker. +const ( + StateClosed StateType = iota + StateOpen + StateHalfOpen +) + +// String implements stringer interface. +func (s StateType) String() string { + switch s { + case StateClosed: + return "closed" + case StateOpen: + return "open" + case StateHalfOpen: + return "half-open" + default: + return fmt.Sprintf("unknown state: %d", s) + } +} + +var replacer = strings.NewReplacer(" ", "_", "-", "_") + +// NewCircuitBreaker returns a new CircuitBreaker configured with the given Settings. +func NewCircuitBreaker[T any](name string, st Settings) *CircuitBreaker[T] { + cb := new(CircuitBreaker[T]) + cb.name = name + cb.config = &st + cb.state = cb.newState(time.Now(), StateClosed) + + metricName := replacer.Replace(name) + cb.successCounter = m.CircuitBreakerCounters.WithLabelValues(metricName, "success") + cb.errorCounter = m.CircuitBreakerCounters.WithLabelValues(metricName, "error") + cb.overloadCounter = m.CircuitBreakerCounters.WithLabelValues(metricName, "overload") + cb.fastFailCounter = m.CircuitBreakerCounters.WithLabelValues(metricName, "fast_fail") + return cb +} + +// ChangeSettings changes the CircuitBreaker settings. +// The changes will be reflected only in the next evaluation window. +func (cb *CircuitBreaker[T]) ChangeSettings(apply func(config *Settings)) { + cb.mutex.Lock() + defer cb.mutex.Unlock() + + apply(cb.config) + log.Info("circuit breaker settings changed", zap.Any("config", cb.config)) +} + +// Execute calls the given function if the CircuitBreaker is closed and returns the result of execution. +// Execute returns an error instantly if the CircuitBreaker is open. +// https://github.com/tikv/rfcs/blob/master/text/0115-circuit-breaker.md +func (cb *CircuitBreaker[T]) Execute(call func() (T, Overloading, error)) (T, error) { + state, err := cb.onRequest() + if err != nil { + cb.fastFailCounter.Inc() + var defaultValue T + return defaultValue, err + } + + defer func() { + e := recover() + if e != nil { + cb.emitMetric(Yes, err) + cb.onResult(state, Yes) + panic(e) + } + }() + + result, overloaded, err := call() + cb.emitMetric(overloaded, err) + cb.onResult(state, overloaded) + return result, err +} + +func (cb *CircuitBreaker[T]) onRequest() (*State[T], error) { + cb.mutex.Lock() + defer cb.mutex.Unlock() + + state, err := cb.state.onRequest(cb) + cb.state = state + return state, err +} + +func (cb *CircuitBreaker[T]) onResult(state *State[T], overloaded Overloading) { + cb.mutex.Lock() + defer cb.mutex.Unlock() + + // even if the circuit breaker already moved to a new state while the request was in progress, + // it is still ok to update the old state, but it is not relevant anymore + state.onResult(overloaded) +} + +func (cb *CircuitBreaker[T]) emitMetric(overloaded Overloading, err error) { + switch overloaded { + case No: + cb.successCounter.Inc() + case Yes: + cb.overloadCounter.Inc() + default: + panic("unknown state") + } + if err != nil { + cb.errorCounter.Inc() + } +} + +// State represents the state of CircuitBreaker. +type State[T any] struct { + stateType StateType + cb *CircuitBreaker[T] + end time.Time + + pendingCount uint32 + successCount uint32 + failureCount uint32 +} + +// newState creates a new State with the given configuration and reset all success/failure counters. +func (cb *CircuitBreaker[T]) newState(now time.Time, stateType StateType) *State[T] { + var end time.Time + var pendingCount uint32 + switch stateType { + case StateClosed: + end = now.Add(cb.config.ErrorRateWindow) + case StateOpen: + end = now.Add(cb.config.CoolDownInterval) + case StateHalfOpen: + // we transition to HalfOpen state on the first request after the cooldown period, + // so we start with 1 pending request + pendingCount = 1 + default: + panic("unknown state") + } + return &State[T]{ + cb: cb, + stateType: stateType, + pendingCount: pendingCount, + end: end, + } +} + +// onRequest transitions the state to the next state based on the current state and the previous requests results +// The implementation represents a state machine for CircuitBreaker +// All state transitions happens at the request evaluation time only +// Circuit breaker start with a closed state, allows all requests to pass through and always lasts for a fixed duration of `Settings.ErrorRateWindow`. +// If `Settings.ErrorRateThresholdPct` is breached at the end of the window, then it moves to Open state, otherwise it moves to a new Closed state with a new window. +// Open state fails all request, it has a fixed duration of `Settings.CoolDownInterval` and always moves to HalfOpen state at the end of the interval. +// HalfOpen state does not have a fixed duration and lasts till `Settings.HalfOpenSuccessCount` are evaluated. +// If any of `Settings.HalfOpenSuccessCount` fails then it moves back to Open state, otherwise it moves to Closed state. +func (s *State[T]) onRequest(cb *CircuitBreaker[T]) (*State[T], error) { + var now = time.Now() + switch s.stateType { + case StateClosed: + if now.After(s.end) { + // ErrorRateWindow is over, let's evaluate the error rate + if s.cb.config.ErrorRateThresholdPct > 0 { // otherwise circuit breaker is disabled + total := s.failureCount + s.successCount + if total > 0 { + observedErrorRatePct := s.failureCount * 100 / total + if total >= uint32(s.cb.config.ErrorRateWindow.Seconds())*s.cb.config.MinQPSForOpen && observedErrorRatePct >= s.cb.config.ErrorRateThresholdPct { + // the error threshold is breached, let's move to open state and start failing all requests + log.Error("circuit breaker tripped and starting to fail all requests", + zap.String("name", cb.name), + zap.Uint32("observed-err-rate-pct", observedErrorRatePct), + zap.Any("config", cb.config)) + return cb.newState(now, StateOpen), errs.ErrCircuitBreakerOpen + } + } + } + // the error threshold is not breached or there were not enough requests to evaluate it, + // continue in the closed state and allow all requests + return cb.newState(now, StateClosed), nil + } + // continue in closed state till ErrorRateWindow is over + return s, nil + case StateOpen: + if s.cb.config.ErrorRateThresholdPct == 0 { + return cb.newState(now, StateClosed), nil + } + + if now.After(s.end) { + // CoolDownInterval is over, it is time to transition to half-open state + log.Info("circuit breaker cooldown period is over. Transitioning to half-open state to test the service", + zap.String("name", cb.name), + zap.Any("config", cb.config)) + return cb.newState(now, StateHalfOpen), nil + } else { + // continue in the open state till CoolDownInterval is over + return s, errs.ErrCircuitBreakerOpen + } + case StateHalfOpen: + if s.cb.config.ErrorRateThresholdPct == 0 { + return cb.newState(now, StateClosed), nil + } + + // do we need some expire time here in case of one of pending requests is stuck forever? + if s.failureCount > 0 { + // there were some failures during half-open state, let's go back to open state to wait a bit longer + log.Error("circuit breaker goes from half-open to open again as errors persist and continue to fail all requests", + zap.String("name", cb.name), + zap.Any("config", cb.config)) + return cb.newState(now, StateOpen), errs.ErrCircuitBreakerOpen + } else if s.successCount == s.cb.config.HalfOpenSuccessCount { + // all probe requests are succeeded, we can move to closed state and allow all requests + log.Info("circuit breaker is closed and start allowing all requests", + zap.String("name", cb.name), + zap.Any("config", cb.config)) + return cb.newState(now, StateClosed), nil + } else if s.pendingCount < s.cb.config.HalfOpenSuccessCount { + // allow more probe requests and continue in half-open state + s.pendingCount++ + return s, nil + } else { + // continue in half-open state till all probe requests are done and fail all other requests for now + return s, errs.ErrCircuitBreakerOpen + } + default: + panic("unknown state") + } +} + +func (s *State[T]) onResult(overloaded Overloading) { + switch overloaded { + case No: + s.successCount++ + case Yes: + s.failureCount++ + default: + panic("unknown state") + } +} diff --git a/client/pkg/circuitbreaker/circuit_breaker_test.go b/client/pkg/circuitbreaker/circuit_breaker_test.go new file mode 100644 index 00000000000..07a3c06f86e --- /dev/null +++ b/client/pkg/circuitbreaker/circuit_breaker_test.go @@ -0,0 +1,270 @@ +// Copyright 2024 TiKV Project 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, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package circuitbreaker + +import ( + "errors" + "testing" + "time" + + "github.com/stretchr/testify/require" + + "github.com/tikv/pd/client/errs" +) + +// advance emulate the state machine clock moves forward by the given duration +func (cb *CircuitBreaker[T]) advance(duration time.Duration) { + cb.state.end = cb.state.end.Add(-duration - 1) +} + +var settings = Settings{ + ErrorRateThresholdPct: 50, + MinQPSForOpen: 10, + ErrorRateWindow: 30 * time.Second, + CoolDownInterval: 10 * time.Second, + HalfOpenSuccessCount: 2, +} + +var minCountToOpen = int(settings.MinQPSForOpen * uint32(settings.ErrorRateWindow.Seconds())) + +func TestCircuitBreakerExecuteWrapperReturnValues(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + originalError := errors.New("circuit breaker is open") + + result, err := cb.Execute(func() (int, Overloading, error) { + return 42, No, originalError + }) + re.Equal(err, originalError) + re.Equal(42, result) + + // same by interpret the result as overloading error + result, err = cb.Execute(func() (int, Overloading, error) { + return 42, Yes, originalError + }) + re.Equal(err, originalError) + re.Equal(42, result) +} + +func TestCircuitBreakerOpenState(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + driveQPS(cb, minCountToOpen, Yes, re) + re.Equal(StateClosed, cb.state.stateType) + assertSucceeds(cb, re) // no error till ErrorRateWindow is finished + cb.advance(settings.ErrorRateWindow) + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) +} + +func TestCircuitBreakerCloseStateNotEnoughQPS(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + driveQPS(cb, minCountToOpen/2, Yes, re) + cb.advance(settings.ErrorRateWindow) + assertSucceeds(cb, re) + re.Equal(StateClosed, cb.state.stateType) +} + +func TestCircuitBreakerCloseStateNotEnoughErrorRate(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + driveQPS(cb, minCountToOpen/4, Yes, re) + driveQPS(cb, minCountToOpen, No, re) + cb.advance(settings.ErrorRateWindow) + assertSucceeds(cb, re) + re.Equal(StateClosed, cb.state.stateType) +} + +func TestCircuitBreakerHalfOpenToClosed(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + driveQPS(cb, minCountToOpen, Yes, re) + cb.advance(settings.ErrorRateWindow) + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) + cb.advance(settings.CoolDownInterval) + assertSucceeds(cb, re) + re.Equal(StateHalfOpen, cb.state.stateType) + assertSucceeds(cb, re) + re.Equal(StateHalfOpen, cb.state.stateType) + // state always transferred on the incoming request + assertSucceeds(cb, re) + re.Equal(StateClosed, cb.state.stateType) +} + +func TestCircuitBreakerHalfOpenToOpen(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + driveQPS(cb, minCountToOpen, Yes, re) + cb.advance(settings.ErrorRateWindow) + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) + cb.advance(settings.CoolDownInterval) + assertSucceeds(cb, re) + re.Equal(StateHalfOpen, cb.state.stateType) + _, err := cb.Execute(func() (int, Overloading, error) { + return 42, Yes, nil // this trip circuit breaker again + }) + re.NoError(err) + re.Equal(StateHalfOpen, cb.state.stateType) + // state always transferred on the incoming request + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) +} + +// in half open state, circuit breaker will allow only HalfOpenSuccessCount pending and should fast fail all other request till HalfOpenSuccessCount requests is completed +// this test moves circuit breaker to the half open state and verifies that requests above HalfOpenSuccessCount are failing +func TestCircuitBreakerHalfOpenFailOverPendingCount(t *testing.T) { + re := require.New(t) + cb := newCircuitBreakerMovedToHalfOpenState(re) + + // the next request will move circuit breaker into the half open state + var started []chan bool + var waited []chan bool + var ended []chan bool + for range settings.HalfOpenSuccessCount { + start := make(chan bool) + wait := make(chan bool) + end := make(chan bool) + started = append(started, start) + waited = append(waited, wait) + ended = append(ended, end) + go func() { + defer func() { + end <- true + }() + _, err := cb.Execute(func() (int, Overloading, error) { + start <- true + <-wait + return 42, No, nil + }) + re.NoError(err) + }() + } + // make sure all requests are started + for i := range started { + <-started[i] + } + // validate that requests beyond HalfOpenSuccessCount are failing + assertFastFail(cb, re) + re.Equal(StateHalfOpen, cb.state.stateType) + // unblock pending requests and wait till they are completed + for i := range ended { + waited[i] <- true + <-ended[i] + } + // validate that circuit breaker moves to closed state + assertSucceeds(cb, re) + re.Equal(StateClosed, cb.state.stateType) + // make sure that after moving to open state all counters are reset + re.Equal(uint32(1), cb.state.successCount) +} + +func TestCircuitBreakerCountOnlyRequestsInSameWindow(t *testing.T) { + re := require.New(t) + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + + start := make(chan bool) + wait := make(chan bool) + end := make(chan bool) + go func() { + defer func() { + end <- true + }() + _, err := cb.Execute(func() (int, Overloading, error) { + start <- true + <-wait + return 42, No, nil + }) + re.NoError(err) + }() + <-start // make sure the request is started + // assert running request is not counted + re.Equal(uint32(0), cb.state.successCount) + + // advance request to the next window + cb.advance(settings.ErrorRateWindow) + assertSucceeds(cb, re) + re.Equal(uint32(1), cb.state.successCount) + + // complete the request from the previous window + wait <- true // resume + <-end // wait for the request to complete + // assert request from last window is not counted + re.Equal(uint32(1), cb.state.successCount) +} + +func TestCircuitBreakerChangeSettings(t *testing.T) { + re := require.New(t) + + cb := NewCircuitBreaker[int]("test_cb", AlwaysClosedSettings) + driveQPS(cb, int(AlwaysClosedSettings.MinQPSForOpen*uint32(AlwaysClosedSettings.ErrorRateWindow.Seconds())), Yes, re) + cb.advance(AlwaysClosedSettings.ErrorRateWindow) + assertSucceeds(cb, re) + re.Equal(StateClosed, cb.state.stateType) + + cb.ChangeSettings(func(config *Settings) { + config.ErrorRateThresholdPct = settings.ErrorRateThresholdPct + }) + re.Equal(settings.ErrorRateThresholdPct, cb.config.ErrorRateThresholdPct) + + driveQPS(cb, minCountToOpen, Yes, re) + cb.advance(settings.ErrorRateWindow) + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) +} + +func newCircuitBreakerMovedToHalfOpenState(re *require.Assertions) *CircuitBreaker[int] { + cb := NewCircuitBreaker[int]("test_cb", settings) + re.Equal(StateClosed, cb.state.stateType) + driveQPS(cb, minCountToOpen, Yes, re) + cb.advance(settings.ErrorRateWindow) + assertFastFail(cb, re) + re.Equal(StateOpen, cb.state.stateType) + cb.advance(settings.CoolDownInterval) + return cb +} + +func driveQPS(cb *CircuitBreaker[int], count int, overload Overloading, re *require.Assertions) { + for range count { + _, err := cb.Execute(func() (int, Overloading, error) { + return 42, overload, nil + }) + re.NoError(err) + } +} + +func assertFastFail(cb *CircuitBreaker[int], re *require.Assertions) { + var executed = false + _, err := cb.Execute(func() (int, Overloading, error) { + executed = true + return 42, No, nil + }) + re.Equal(err, errs.ErrCircuitBreakerOpen) + re.False(executed) +} + +func assertSucceeds(cb *CircuitBreaker[int], re *require.Assertions) { + result, err := cb.Execute(func() (int, Overloading, error) { + return 42, No, nil + }) + re.NoError(err) + re.Equal(42, result) +} diff --git a/client/pkg/retry/backoff.go b/client/pkg/retry/backoff.go index b0524e6c139..e3b331582d6 100644 --- a/client/pkg/retry/backoff.go +++ b/client/pkg/retry/backoff.go @@ -21,10 +21,11 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" - "go.uber.org/zap" ) // Option is used to customize the backoffer. diff --git a/client/pkg/retry/backoff_test.go b/client/pkg/retry/backoff_test.go index 12891d822aa..b01a753b374 100644 --- a/client/pkg/retry/backoff_test.go +++ b/client/pkg/retry/backoff_test.go @@ -22,9 +22,10 @@ import ( "testing" "time" - "github.com/pingcap/log" "github.com/stretchr/testify/require" "go.uber.org/zap" + + "github.com/pingcap/log" ) func TestBackoffer(t *testing.T) { diff --git a/client/pkg/utils/grpcutil/grpcutil.go b/client/pkg/utils/grpcutil/grpcutil.go index 29967263dd3..b73d117fe84 100644 --- a/client/pkg/utils/grpcutil/grpcutil.go +++ b/client/pkg/utils/grpcutil/grpcutil.go @@ -21,17 +21,19 @@ import ( "sync" "time" - "github.com/pingcap/errors" - "github.com/pingcap/failpoint" - "github.com/pingcap/log" - "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/pkg/retry" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/backoff" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" + + "github.com/pingcap/errors" + "github.com/pingcap/failpoint" + "github.com/pingcap/log" + + "github.com/tikv/pd/client/errs" + "github.com/tikv/pd/client/pkg/retry" ) const ( diff --git a/client/pkg/utils/testutil/check_env_linux.go b/client/pkg/utils/testutil/check_env_linux.go index df45f359eb3..ebe6a8e0663 100644 --- a/client/pkg/utils/testutil/check_env_linux.go +++ b/client/pkg/utils/testutil/check_env_linux.go @@ -18,8 +18,9 @@ package testutil import ( "github.com/cakturk/go-netstat/netstat" - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) func environmentCheck(addr string) bool { diff --git a/client/pkg/utils/testutil/tempurl.go b/client/pkg/utils/testutil/tempurl.go index 71d51176106..d948160ba42 100644 --- a/client/pkg/utils/testutil/tempurl.go +++ b/client/pkg/utils/testutil/tempurl.go @@ -20,8 +20,9 @@ import ( "sync" "time" - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) var ( diff --git a/client/pkg/utils/tlsutil/tlsconfig.go b/client/pkg/utils/tlsutil/tlsconfig.go index 88d797d3b3a..65e0ce9542f 100644 --- a/client/pkg/utils/tlsutil/tlsconfig.go +++ b/client/pkg/utils/tlsutil/tlsconfig.go @@ -40,6 +40,7 @@ import ( "fmt" "github.com/pingcap/errors" + "github.com/tikv/pd/client/errs" ) diff --git a/client/pkg/utils/tlsutil/url.go b/client/pkg/utils/tlsutil/url.go index ccc312d195b..abe4132a6a9 100644 --- a/client/pkg/utils/tlsutil/url.go +++ b/client/pkg/utils/tlsutil/url.go @@ -19,8 +19,9 @@ import ( "net/url" "strings" - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) const ( diff --git a/client/resource_group/controller/config.go b/client/resource_group/controller/config.go index 96c783455bb..3008d7b6e77 100644 --- a/client/resource_group/controller/config.go +++ b/client/resource_group/controller/config.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/client/resource_group/controller/controller.go b/client/resource_group/controller/controller.go index 83bd21b1eed..2265053fdd2 100644 --- a/client/resource_group/controller/controller.go +++ b/client/resource_group/controller/controller.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -24,18 +24,20 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "golang.org/x/exp/slices" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/meta_storagepb" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus" + pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/clients/metastorage" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "go.uber.org/zap" - "golang.org/x/exp/slices" ) const ( diff --git a/client/resource_group/controller/controller_test.go b/client/resource_group/controller/controller_test.go index 882f99a6868..f0bdc62d6d3 100644 --- a/client/resource_group/controller/controller_test.go +++ b/client/resource_group/controller/controller_test.go @@ -11,7 +11,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -24,11 +24,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/meta_storagepb" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" + pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" diff --git a/client/resource_group/controller/limiter.go b/client/resource_group/controller/limiter.go index 5d9823312ca..c8843da00bd 100644 --- a/client/resource_group/controller/limiter.go +++ b/client/resource_group/controller/limiter.go @@ -11,7 +11,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -25,10 +25,12 @@ import ( "sync" "time" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" - "github.com/tikv/pd/client/errs" "go.uber.org/zap" + + "github.com/pingcap/log" + + "github.com/tikv/pd/client/errs" ) // Limit defines the maximum frequency of some events. diff --git a/client/resource_group/controller/limiter_test.go b/client/resource_group/controller/limiter_test.go index 9afebcb3d53..24cdee0bbc3 100644 --- a/client/resource_group/controller/limiter_test.go +++ b/client/resource_group/controller/limiter_test.go @@ -11,7 +11,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/client/resource_group/controller/model.go b/client/resource_group/controller/model.go index 9e86de69abb..88c18dc25cf 100644 --- a/client/resource_group/controller/model.go +++ b/client/resource_group/controller/model.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/client/resource_group/controller/model_test.go b/client/resource_group/controller/model_test.go index 594091da364..99cac79c25a 100644 --- a/client/resource_group/controller/model_test.go +++ b/client/resource_group/controller/model_test.go @@ -17,8 +17,9 @@ package controller import ( "testing" - rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/stretchr/testify/require" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" ) func TestGetRUValueFromConsumption(t *testing.T) { diff --git a/client/resource_group/controller/testutil.go b/client/resource_group/controller/testutil.go index 01a9c3af1fc..de71cff4d0b 100644 --- a/client/resource_group/controller/testutil.go +++ b/client/resource_group/controller/testutil.go @@ -11,7 +11,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/client/resource_group/controller/util.go b/client/resource_group/controller/util.go index e3450e0ae0d..3b491e02c8f 100644 --- a/client/resource_group/controller/util.go +++ b/client/resource_group/controller/util.go @@ -11,7 +11,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/client/resource_manager_client.go b/client/resource_manager_client.go index 3cf2970109f..0c481631b93 100644 --- a/client/resource_manager_client.go +++ b/client/resource_manager_client.go @@ -19,14 +19,16 @@ import ( "time" "github.com/gogo/protobuf/proto" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/meta_storagepb" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" - "go.uber.org/zap" ) type actionType int diff --git a/client/servicediscovery/pd_service_discovery.go b/client/servicediscovery/pd_service_discovery.go index bd4e442030a..619d4196408 100644 --- a/client/servicediscovery/pd_service_discovery.go +++ b/client/servicediscovery/pd_service_discovery.go @@ -25,21 +25,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/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/pkg/retry" "github.com/tikv/pd/client/pkg/utils/grpcutil" "github.com/tikv/pd/client/pkg/utils/tlsutil" - "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 ( diff --git a/client/servicediscovery/pd_service_discovery_test.go b/client/servicediscovery/pd_service_discovery_test.go index e8e7ef14e44..dc0a0bd4511 100644 --- a/client/servicediscovery/pd_service_discovery_test.go +++ b/client/servicediscovery/pd_service_discovery_test.go @@ -25,21 +25,23 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" - "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/tikv/pd/client/errs" - "github.com/tikv/pd/client/opt" - "github.com/tikv/pd/client/pkg/utils/grpcutil" - "github.com/tikv/pd/client/pkg/utils/testutil" - "github.com/tikv/pd/client/pkg/utils/tlsutil" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" pb "google.golang.org/grpc/examples/helloworld/helloworld" "google.golang.org/grpc/health" healthpb "google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/metadata" + + "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/pdpb" + + "github.com/tikv/pd/client/errs" + "github.com/tikv/pd/client/opt" + "github.com/tikv/pd/client/pkg/utils/grpcutil" + "github.com/tikv/pd/client/pkg/utils/testutil" + "github.com/tikv/pd/client/pkg/utils/tlsutil" ) type testGRPCServer struct { diff --git a/client/servicediscovery/tso_service_discovery.go b/client/servicediscovery/tso_service_discovery.go index 3fd27837f95..1d2130db804 100644 --- a/client/servicediscovery/tso_service_discovery.go +++ b/client/servicediscovery/tso_service_discovery.go @@ -25,17 +25,19 @@ import ( "time" "github.com/gogo/protobuf/proto" + "go.uber.org/zap" + "google.golang.org/grpc" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" + "github.com/tikv/pd/client/clients/metastorage" "github.com/tikv/pd/client/constants" "github.com/tikv/pd/client/errs" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/pkg/utils/grpcutil" - "go.uber.org/zap" - "google.golang.org/grpc" ) const ( diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 0181d4c47aa..165bcd2a12f 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -22,8 +22,11 @@ import ( "syscall" grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - "github.com/pingcap/log" "github.com/spf13/cobra" + "go.uber.org/zap" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/autoscaling" "github.com/tikv/pd/pkg/dashboard" "github.com/tikv/pd/pkg/errs" @@ -41,7 +44,6 @@ import ( "github.com/tikv/pd/server/apiv2" "github.com/tikv/pd/server/config" "github.com/tikv/pd/server/join" - "go.uber.org/zap" // register microservice API _ "github.com/tikv/pd/pkg/mcs/resourcemanager/server/install" diff --git a/errors.toml b/errors.toml index 9bfd4a79190..785de6662f4 100644 --- a/errors.toml +++ b/errors.toml @@ -61,6 +61,11 @@ error = ''' unsupported metrics type %v ''' +["PD:cgroup:ErrNoCPUControllerDetected"] +error = ''' +no cpu controller detected +''' + ["PD:checker:ErrCheckerMergeAgain"] error = ''' region will be merged again, %s @@ -71,6 +76,36 @@ error = ''' checker not found ''' +["PD:checker:ErrNoNewLeader"] +error = ''' +no new leader +''' + +["PD:checker:ErrNoStoreToAdd"] +error = ''' +no store to add peer +''' + +["PD:checker:ErrNoStoreToReplace"] +error = ''' +no store to replace peer +''' + +["PD:checker:ErrPeerCannotBeLeader"] +error = ''' +peer cannot be leader +''' + +["PD:checker:ErrPeerCannotBeWitness"] +error = ''' +peer cannot be witness +''' + +["PD:checker:ErrRegionNoLeader"] +error = ''' +region no leader +''' + ["PD:client:ErrClientCreateTSOStream"] error = ''' create TSO stream failed, %s @@ -491,6 +526,116 @@ error = ''' failed to unmarshal json ''' +["PD:keyspace:ErrExceedMaxEtcdTxnOps"] +error = ''' +exceed max etcd txn operations +''' + +["PD:keyspace:ErrIllegalOperation"] +error = ''' +unknown operation +''' + +["PD:keyspace:ErrKeyspaceExists"] +error = ''' +keyspace already exists +''' + +["PD:keyspace:ErrKeyspaceGroupExists"] +error = ''' +keyspace group already exists +''' + +["PD:keyspace:ErrKeyspaceGroupInMerging"] +error = ''' +keyspace group %v is in merging state +''' + +["PD:keyspace:ErrKeyspaceGroupInSplit"] +error = ''' +keyspace group %v is in split state +''' + +["PD:keyspace:ErrKeyspaceGroupNotEnoughReplicas"] +error = ''' +not enough replicas in the keyspace group +''' + +["PD:keyspace:ErrKeyspaceGroupNotExists"] +error = ''' +keyspace group %v does not exist +''' + +["PD:keyspace:ErrKeyspaceGroupNotInMerging"] +error = ''' +keyspace group %v is not in merging state +''' + +["PD:keyspace:ErrKeyspaceGroupNotInSplit"] +error = ''' +keyspace group %v is not in split state +''' + +["PD:keyspace:ErrKeyspaceGroupPrimaryNotFound"] +error = ''' +primary of keyspace group does not exist +''' + +["PD:keyspace:ErrKeyspaceGroupWithEmptyKeyspace"] +error = ''' +keyspace group with empty keyspace +''' + +["PD:keyspace:ErrKeyspaceNotFound"] +error = ''' +keyspace does not exist +''' + +["PD:keyspace:ErrKeyspaceNotInAnyKeyspaceGroup"] +error = ''' +keyspace is not in any keyspace group +''' + +["PD:keyspace:ErrKeyspaceNotInKeyspaceGroup"] +error = ''' +keyspace is not in this keyspace group +''' + +["PD:keyspace:ErrModifyDefaultKeyspace"] +error = ''' +cannot modify default keyspace's state +''' + +["PD:keyspace:ErrModifyDefaultKeyspaceGroup"] +error = ''' +default keyspace group cannot be modified +''' + +["PD:keyspace:ErrNoAvailableNode"] +error = ''' +no available node +''' + +["PD:keyspace:ErrNodeNotInKeyspaceGroup"] +error = ''' +the tso node is not in this keyspace group +''' + +["PD:keyspace:ErrRegionSplitFailed"] +error = ''' +region split failed +''' + +["PD:keyspace:ErrRegionSplitTimeout"] +error = ''' +region split timeout +''' + +["PD:keyspace:ErrUnsupportedOperationInKeyspace"] +error = ''' +it's a unsupported operation +''' + ["PD:leveldb:ErrLevelDBClose"] error = ''' close leveldb error @@ -646,6 +791,11 @@ error = ''' failed to unmarshal proto ''' +["PD:ratelimit:ErrMaxWaitingTasksExceeded"] +error = ''' +max waiting tasks exceeded +''' + ["PD:region:ErrRegionAbnormalPeer"] error = ''' region %v has abnormal peer @@ -691,6 +841,11 @@ error = ''' invalid group settings, please check the group name, priority and the number of resources ''' +["PD:scatter:ErrEmptyRegion"] +error = ''' +empty region +''' + ["PD:schedule:ErrCreateOperator"] error = ''' unable to create operator, %s @@ -841,11 +996,6 @@ error = ''' get allocator manager failed, %s ''' -["PD:tso:ErrGetLocalAllocator"] -error = ''' -get local allocator failed, %s -''' - ["PD:tso:ErrGetMinTS"] error = ''' get min ts failed, %s diff --git a/go.mod b/go.mod index 8fed2fc25fc..9c8a7bc90a5 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/aws/aws-sdk-go-v2/config v1.25.12 github.com/aws/aws-sdk-go-v2/credentials v1.16.10 - github.com/aws/aws-sdk-go-v2/service/kms v1.20.8 + github.com/aws/aws-sdk-go-v2/service/kms v1.26.5 github.com/aws/aws-sdk-go-v2/service/sts v1.26.3 github.com/axw/gocov v1.0.0 github.com/brianvoe/gofakeit/v6 v6.26.3 @@ -38,8 +38,8 @@ require ( github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 github.com/pingcap/tidb-dashboard v0.0.0-20241104061623-bce95733dad7 - github.com/prometheus/client_golang v1.19.0 - github.com/prometheus/common v0.51.1 + github.com/prometheus/client_golang v1.20.5 + github.com/prometheus/common v0.55.0 github.com/sasha-s/go-deadlock v0.3.5 github.com/shirou/gopsutil/v3 v3.23.3 github.com/smallnest/chanx v1.2.1-0.20240521153536-01121e21ff99 @@ -89,7 +89,7 @@ require ( github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect @@ -138,6 +138,7 @@ require ( github.com/joomcode/errorx v1.0.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect @@ -147,6 +148,7 @@ require ( github.com/minio/sio v0.3.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oleiade/reflections v1.0.1 // indirect github.com/onsi/gomega v1.20.1 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect @@ -155,8 +157,8 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect - github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/procfs v0.13.0 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/procfs v0.15.1 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/samber/lo v1.37.0 // indirect @@ -194,20 +196,19 @@ require ( go.uber.org/fx v1.12.0 // indirect go.uber.org/multierr v1.11.0 golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.23.0 // indirect + golang.org/x/crypto v0.24.0 // indirect golang.org/x/image v0.18.0 // indirect golang.org/x/mod v0.17.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/oauth2 v0.18.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/oauth2 v0.21.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/term v0.20.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/term v0.21.0 // indirect golang.org/x/text v0.16.0 // indirect - google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect - google.golang.org/protobuf v1.34.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 172a53a0909..a2f070397d1 100644 --- a/go.sum +++ b/go.sum @@ -2,9 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.112.2 h1:ZaGT6LiG7dBzi6zNOvVZwacaXlmf3lRqnC4DQzqyRQw= cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= -cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= +cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= github.com/AlekSi/gocov-xml v1.0.0 h1:4QctJBgXEkbzeKz6PJy6bt3JSPNSN4I2mITYW+eKUoQ= github.com/AlekSi/gocov-xml v1.0.0/go.mod h1:J0qYeZ6tDg4oZubW9mAAgxlqw39PDfoEkzB3HXSbEuA= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= @@ -28,7 +27,6 @@ github.com/alvaroloes/enumer v1.1.2/go.mod h1:FxrjvuXoDAx9isTJrv4c+T410zFi0DtXIT github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/appleboy/gofight/v2 v2.1.2 h1:VOy3jow4vIK8BRQJoC/I9muxyYlJ2yb9ht2hZoS3rf4= github.com/appleboy/gofight/v2 v2.1.2/go.mod h1:frW+U1QZEdDgixycTj4CygQ48yLTUhplt43+Wczp3rw= -github.com/aws/aws-sdk-go-v2 v1.17.7/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= github.com/aws/aws-sdk-go-v2 v1.23.5 h1:xK6C4udTyDMd82RFvNkDQxtAd00xlzFUtX4fF2nMZyg= github.com/aws/aws-sdk-go-v2 v1.23.5/go.mod h1:t3szzKfP0NeRU27uBFczDivYJjsmSnqI8kIvKyWb9ds= github.com/aws/aws-sdk-go-v2/config v1.25.12 h1:mF4cMuNh/2G+d19nWnm1vJ/ak0qK6SbqF0KtSX9pxu0= @@ -37,10 +35,8 @@ github.com/aws/aws-sdk-go-v2/credentials v1.16.10 h1:VmRkuoKaGl2ZDNGkkRQgw80Hxj1 github.com/aws/aws-sdk-go-v2/credentials v1.16.10/go.mod h1:WEn22lpd50buTs/TDqywytW5xQ2zPOMbYipIlqI6xXg= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.9 h1:FZVFahMyZle6WcogZCOxo6D/lkDA2lqKIn4/ueUmVXw= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.9/go.mod h1:kjq7REMIkxdtcEC9/4BVXjOsNY5isz6jQbEgk6osRTU= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.31/go.mod h1:QT0BqUvX1Bh2ABdTGnjqEjvjzrCfIniM9Sc8zn9Yndo= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.8 h1:8GVZIR0y6JRIUNSYI1xAMF4HDfV8H/bOsZ/8AD/uY5Q= github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.8/go.mod h1:rwBfu0SoUkBUZndVgPZKAD9Y2JigaZtRP68unRiYToQ= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.25/go.mod h1:zBHOPwhBc3FlQjQJE/D3IfPWiWaQmT06Vq9aNukDo0k= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.8 h1:ZE2ds/qeBkhk3yqYvS3CDCFNvd9ir5hMjlVStLZWrvM= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.8/go.mod h1:/lAPPymDYL023+TS6DJmjuL42nxix2AvEvfjqOBRODk= github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 h1:uR9lXYjdPX0xY+NhvaJ4dD8rpSRz5VY81ccIIoNG+lw= @@ -49,15 +45,14 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.3 h1:e3PCNeE github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.3/go.mod h1:gIeeNyaL8tIEqZrzAnTeyhHcE0yysCtcaP+N9kxLZ+E= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.8 h1:EamsKe+ZjkOQjDdHd86/JCEucjFKQ9T0atWKO4s2Lgs= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.8/go.mod h1:Q0vV3/csTpbkfKLI5Sb56cJQTCTtJ0ixdb7P+Wedqiw= -github.com/aws/aws-sdk-go-v2/service/kms v1.20.8 h1:R5f4VOFi3ScTe7TtePyxLqEhNqTJIAxL57MzrXFNs6I= -github.com/aws/aws-sdk-go-v2/service/kms v1.20.8/go.mod h1:OtP3pBOgmJM+acQyQcQXtQHets3yJoVuanCx2T5M7v4= +github.com/aws/aws-sdk-go-v2/service/kms v1.26.5 h1:MRNoQVbEtjzhYFeKVMifHae4K5q4FuK9B7tTDskIF/g= +github.com/aws/aws-sdk-go-v2/service/kms v1.26.5/go.mod h1:gfe6e+rOxaiz/gr5Myk83ruBD6F9WvM7TZbLjcTNsDM= github.com/aws/aws-sdk-go-v2/service/sso v1.18.3 h1:wKspi1zc2ZVcgZEu3k2Mt4zGKQSoZTftsoUTLsYPcVo= github.com/aws/aws-sdk-go-v2/service/sso v1.18.3/go.mod h1:zxk6y1X2KXThESWMS5CrKRvISD8mbIMab6nZrCGxDG0= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.3 h1:CxAHBS0BWSUqI7qzXHc2ZpTeHaM9JNnWJ9BN6Kmo2CY= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.3/go.mod h1:7Lt5mjQ8x5rVdKqg+sKKDeuwoszDJIIPmkd8BVsEdS0= github.com/aws/aws-sdk-go-v2/service/sts v1.26.3 h1:KfREzajmHCSYjCaMRtdLr9boUMA7KPpoPApitPlbNeo= github.com/aws/aws-sdk-go-v2/service/sts v1.26.3/go.mod h1:7Ld9eTqocTvJqqJ5K/orbSDwmGcpRdlDiLjz2DO+SL8= -github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/smithy-go v1.18.1 h1:pOdBTUfXNazOlxLrgeYalVnuTpKreACHtc62xLwIB3c= github.com/aws/smithy-go v1.18.1/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= github.com/axw/gocov v1.0.0 h1:YsqYR66hUmilVr23tu8USgnJIJvnwh3n7j5zRn7x4LU= @@ -82,8 +77,8 @@ github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5/go.mod h1:jtAfV github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -221,7 +216,6 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -233,7 +227,6 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -292,8 +285,6 @@ github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/ github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= @@ -312,6 +303,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= @@ -326,6 +319,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= @@ -357,6 +352,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= @@ -416,15 +413,15 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig= github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= -github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= -github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= -github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.51.1 h1:eIjN50Bwglz6a/c3hAgSMcofL3nD+nFQkV6Dd4DsQCw= -github.com/prometheus/common v0.51.1/go.mod h1:lrWtQx+iDfn2mbH5GUzlH9TSHyfZpHkSiG1W7y3sF2Q= -github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= -github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -537,7 +534,6 @@ github.com/xiang90/probing v0.0.0-20221125231312-a49e3df8f510/go.mod h1:UETIi67q github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= @@ -611,9 +607,8 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4 h1:QLureRX3moex6NVu/Lr4MGakp9FdA7sBHGBmvRW7NaM= golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= @@ -630,7 +625,6 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -653,13 +647,12 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= -golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -667,7 +660,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -698,24 +690,20 @@ golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= @@ -743,7 +731,6 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210112230658-8b4aab62c064/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -752,8 +739,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= @@ -776,10 +761,9 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/metrics/grafana/pd.json b/metrics/grafana/pd.json index 8be39af25ee..0f4e91afd50 100644 --- a/metrics/grafana/pd.json +++ b/metrics/grafana/pd.json @@ -13992,6 +13992,1950 @@ ], "title": "DR Autosync", "type": "row" + }, + { + "collapsed": true, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 33 + }, + "id": 1611, + "panels": [ + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "bytes" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 34 + }, + "hiddenSeries": false, + "id": 1612, + "legend": { + "alignAsTable": true, + "avg": false, + "current": true, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": true, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "process_resident_memory_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "rss-{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "go_memory_classes_heap_objects_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "heap_inuse-{{instance}}--{{job}}", + "refId": "B" + }, + { + "exemplar": true, + "expr": "go_memory_classes_heap_stacks_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "stack_inuse-{{instance}}--{{job}}", + "refId": "C" + }, + { + "exemplar": true, + "expr": "go_memory_classes_heap_unused_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "heap_unused-{{instance}}--{{job}}", + "refId": "D" + }, + { + "exemplar": true, + "expr": "go_memory_classes_metadata_mcache_free_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}+go_memory_classes_metadata_mcache_inuse_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}+go_memory_classes_metadata_mspan_free_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}+go_memory_classes_metadata_mspan_inuse_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}+go_memory_classes_metadata_other_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "go_runtime_metadata-{{instance}}--{{job}}", + "refId": "E" + }, + { + "exemplar": true, + "expr": "go_memory_classes_os_stacks_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}+go_memory_classes_other_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}+go_memory_classes_profiling_buckets_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "other_memory-{{instance}}--{{job}}", + "refId": "F" + }, + { + "exemplar": true, + "expr": "go_memory_classes_heap_free_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "free_mem_reserved_by_go-{{instance}}--{{job}}", + "refId": "G" + }, + { + "exemplar": true, + "expr": "go_memory_classes_heap_released_bytes{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "returned_to_os-{{instance}}--{{job}}", + "refId": "H" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Memory Usage", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "bytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "none", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 34 + }, + "hiddenSeries": false, + "id": 1613, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "go_memstats_heap_objects{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "objects--{{instance}}--{{job}}", + "refId": "A" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Estimated Live Objects", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "decbytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 40 + }, + "hiddenSeries": false, + "id": 1614, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "irate(process_cpu_seconds_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "cpu-usage--{{instance}}--{{job}}", + "refId": "A", + "step": 40 + }, + { + "expr": "(idelta((go_memstats_gc_cpu_fraction{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"} * (go_memstats_last_gc_time_seconds{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"} - process_start_time_seconds{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}) * tidb_server_maxprocs{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"})[30s:]) > 0) / 15", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "gc-cpu--{{instance}}--{{job}}", + "refId": "C" + }, + { + "expr": "pd_service_maxprocs{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "format": "time_series", + "interval": "", + "intervalFactor": 1, + "legendFormat": "quota--{{instance}}--{{job}}", + "refId": "B" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "CPU Usage", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "percentunit", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 40 + }, + "hiddenSeries": false, + "id": 1615, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "go_gc_duration_seconds{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", quantile=\"0\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "min-{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "go_gc_duration_seconds{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", quantile!~\"0|1\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "{{quantile}}-{{instance}}--{{job}}", + "refId": "B" + }, + { + "exemplar": true, + "expr": "go_gc_duration_seconds{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\", quantile=\"1\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "max-{{instance}}--{{job}}", + "refId": "C" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "GC STW Duration (last 256 GC cycles)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 46 + }, + "hiddenSeries": false, + "id": 1616, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/threads.*/", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": " go_goroutines{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "goroutines-{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "go_threads{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "instant": false, + "interval": "", + "legendFormat": "threads-{{instance}}--{{job}}", + "refId": "B" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Goroutine Count", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 46 + }, + "hiddenSeries": false, + "id": 1617, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/alloc-ops.*/", + "yaxis": 2 + }, + { + "alias": "/sweep-ops.*/", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "irate(go_memstats_alloc_bytes_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "alloc--{{instance}}--{{job}}", + "refId": "A" + }, + { + "expr": "irate((go_memstats_alloc_bytes_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"} - go_memstats_heap_alloc_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"})[30s:])", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "sweep--{{instance}}--{{job}}", + "refId": "B" + }, + { + "expr": "irate(go_memstats_mallocs_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "alloc-ops--{{instance}}--{{job}}", + "refId": "C" + }, + { + "expr": "irate(go_memstats_frees_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "sweep-ops--{{instance}}--{{job}}", + "refId": "D" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Allocator Throughput", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "Bps", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "format": "ops", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "graph": false, + "legend": false, + "tooltip": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true + }, + "mappings": [], + "min": 0, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "bytes" + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "free-objects-total" + }, + "properties": [ + { + "id": "custom.axisPlacement", + "value": "right" + }, + { + "id": "unit", + "value": "none" + } + ] + } + ] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 52 + }, + "hiddenSeries": false, + "id": 1618, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "sweep", + "transform": "negative-Y" + }, + { + "alias": "alloc-ops", + "yaxis": 2 + }, + { + "alias": "swepp-ops", + "transform": "negative-Y", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "histogram_quantile(0.999, sum(rate(go_gc_heap_frees_by_size_bytes_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])) by (le,instance,job))", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": ".999 free-by-size--{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_by_size_bytes_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])/increase(go_gc_heap_frees_by_size_bytes_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "hide": false, + "interval": "", + "legendFormat": "avg free-by-size--{{instance}}--{{job}}", + "refId": "B" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_bytes_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "free-bytes-total--{{instance}}--{{job}}", + "refId": "C" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_objects_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "free-objects-total--{{instance}}--{{job}}", + "refId": "D" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Estimated portion of CPU time", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 52 + }, + "hiddenSeries": false, + "id": 1619, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "histogram_quantile(0.999,sum(rate(go_sched_pauses_total_gc_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le,instance,job))", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 GC STW--{{instance}}--{{job}}", + "refId": "A", + "step": 40 + }, + { + "exemplar": true, + "expr": "rate(go_sched_pauses_total_gc_seconds_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s]) / rate(go_sched_pauses_total_gc_seconds_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "avg GC STW--{{instance}}--{{job}}", + "refId": "B", + "step": 40 + }, + { + "exemplar": true, + "expr": "histogram_quantile(0.999,sum(rate(go_sched_pauses_total_other_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (instance,le))", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 non-GC STW--{{instance}}--{{job}}", + "refId": "C" + }, + { + "exemplar": true, + "expr": "rate(go_sched_pauses_total_other_seconds_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])/rate(go_sched_pauses_total_other_seconds_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "avg non-GC STW--{{instance}}--{{job}}", + "refId": "D", + "step": 40 + }, + { + "exemplar": true, + "expr": "histogram_quantile(0.999,sum(rate(go_sched_pauses_stopping_gc_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le,instance,job))", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 GC stopping--{{instance}}--{{job}}", + "refId": "E", + "step": 40 + }, + { + "exemplar": true, + "expr": "rate(go_sched_pauses_stopping_gc_seconds_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s]) / rate(go_sched_pauses_stopping_gc_seconds_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "avg GC stopping--{{instance}}--{{job}}", + "refId": "F", + "step": 40 + }, + { + "exemplar": true, + "expr": "histogram_quantile(0.999,sum(rate(go_sched_pauses_stopping_other_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (instance,le))", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 non-GC stopping--{{instance}}--{{job}}", + "refId": "G" + }, + { + "exemplar": true, + "expr": "rate(go_sched_pauses_stopping_other_seconds_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[30s])/rate(go_sched_pauses_stopping_other_seconds_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": " avg non-GC stopping--{{instance}}--{{job}}", + "refId": "H", + "step": 40 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "GC STW Latency(>= go1.22.0)", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": false + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 58 + }, + "hiddenSeries": false, + "id": 1620, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "expr": "histogram_quantile(0.999, sum(rate(go_sched_latencies_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le, instance,job))", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "P999--{{instance}}--{{job}}", + "refId": "A", + "step": 10 + }, + { + "expr": "histogram_quantile(0.9999, sum(rate(go_sched_latencies_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le, instance,job))", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "P9999--{{instance}}--{{job}}", + "refId": "B", + "step": 10 + }, + { + "expr": "histogram_quantile(0.99999, sum(rate(go_sched_latencies_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le, instance,job))", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "P99999--{{instance}}--{{job}}", + "refId": "C", + "step": 10 + }, + { + "expr": "histogram_quantile(0.999999, sum(rate(go_sched_latencies_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le, instance,job))", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "P999999--{{instance}}--{{job}}", + "refId": "D", + "step": 10 + }, + { + "expr": "histogram_quantile(1, sum(rate(go_sched_latencies_seconds_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])) by (le, instance,job))", + "format": "time_series", + "intervalFactor": 1, + "legendFormat": "max--{{instance}}--{{job}}", + "refId": "E", + "step": 10 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Goroutine scheduler latency", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 10, + "gradientMode": "none", + "hideFrom": { + "graph": false, + "legend": false, + "tooltip": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [ + { + "matcher": { + "id": "byFrameRefID", + "options": "D" + }, + "properties": [ + { + "id": "custom.axisPlacement", + "value": "right" + }, + { + "id": "unit", + "value": "short" + } + ] + } + ] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 58 + }, + "hiddenSeries": false, + "id": 1621, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "increase(go_gc_cycles_automatic_gc_cycles_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "auto gc-{{instance}}--{{job}}", + "refId": "A", + "step": 40 + }, + { + "exemplar": true, + "expr": "increase(go_gc_cycles_forced_gc_cycles_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "forced gc-{{instance}}--{{job}}", + "refId": "B", + "step": 40 + }, + { + "exemplar": true, + "expr": "increase(go_gc_cycles_total_gc_cycles_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "total gc-{{instance}}--{{job}}", + "refId": "C", + "step": 40 + }, + { + "exemplar": true, + "expr": "changes(go_gc_limiter_last_enabled_gc_cycle{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": true, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "gc limiter enabled-{{instance}}--{{job}}", + "refId": "D", + "step": 40 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Golang GC", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": {}, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 66 + }, + "hiddenSeries": false, + "id": 1622, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "irate(go_sync_mutex_wait_total_seconds_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[30s])", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "mutex_wait_seconds-{{instance}}--{{job}}", + "refId": "A", + "step": 40 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Sync mutex wait", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "s", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": {}, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 66 + }, + "hiddenSeries": false, + "id": 1623, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/GOMEMLIMIT.*/", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "go_gc_gogc_percent{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "GOGC-{{instance}}--{{job}}", + "refId": "A", + "step": 40 + }, + { + "exemplar": true, + "expr": "go_gc_gomemlimit_bytes{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}", + "format": "time_series", + "hide": false, + "instant": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "GOMEMLIMIT-{{instance}}--{{job}}", + "refId": "B", + "step": 40 + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "GOGC & GOMEMLIMIT", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "decbytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": {}, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 0, + "y": 72 + }, + "hiddenSeries": false, + "id": 1624, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/alloc-objects-total.*/", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "histogram_quantile(0.999, sum(rate(go_gc_heap_allocs_by_size_bytes_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])) by (le,instance,job))", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 alloc-by-size--{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_allocs_by_size_bytes_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])/increase(go_gc_heap_allocs_by_size_bytes_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "hide": false, + "interval": "", + "legendFormat": "avg alloc-by-size--{{instance}}--{{job}}", + "refId": "B" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_allocs_bytes_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "alloc-bytes-total--{{instance}}--{{job}}", + "refId": "C" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_allocs_objects_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "alloc-objects-total--{{instance}}--{{job}}", + "refId": "D" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Heap alloc", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "decbytes", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": "${DS_TEST-CLUSTER}", + "fieldConfig": {}, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 6, + "w": 12, + "x": 12, + "y": 66 + }, + "hiddenSeries": false, + "id": 1625, + "legend": { + "alignAsTable": true, + "avg": false, + "current": false, + "max": false, + "min": false, + "rightSide": true, + "show": true, + "total": false, + "values": false, + "hideEmpty": true, + "hideZero": true + }, + "lines": true, + "linewidth": 1, + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.5.10", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [ + { + "alias": "/free-objects-total.*/", + "yaxis": 2 + } + ], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "exemplar": true, + "expr": "histogram_quantile(0.999, sum(rate(go_gc_heap_frees_by_size_bytes_bucket{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\",job=~\".*(pd|tso|scheduling).*\"}[1m])) by (le,instance,job))", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "P999 free-by-size--{{instance}}--{{job}}", + "refId": "A" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_by_size_bytes_sum{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])/increase(go_gc_heap_frees_by_size_bytes_count{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "hide": false, + "interval": "", + "legendFormat": "avg free-by-size--{{instance}}--{{job}}", + "refId": "B" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_bytes_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "free-bytes-total--{{instance}}--{{job}}", + "refId": "C" + }, + { + "exemplar": true, + "expr": "increase(go_gc_heap_frees_objects_total{k8s_cluster=\"$k8s_cluster\",tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\",job=~\".*(pd|tso|scheduling).*\"}[1m])", + "format": "time_series", + "hide": false, + "interval": "", + "intervalFactor": 1, + "legendFormat": "free-objects-total--{{instance}}--{{job}}", + "refId": "D" + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Heap free", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "transformations": [], + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "format": "decbytes", + "label": null, + "logBase": 1, + "max": null, + "min": "0", + "show": true + }, + { + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + } + ], + "title": "GO Runtime", + "type": "row" } ], "refresh": "30s", diff --git a/pkg/audit/audit.go b/pkg/audit/audit.go index f84d035f8c9..eba9722f44f 100644 --- a/pkg/audit/audit.go +++ b/pkg/audit/audit.go @@ -17,10 +17,12 @@ package audit import ( "net/http" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" - "github.com/tikv/pd/pkg/utils/requestutil" "go.uber.org/zap" + + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/utils/requestutil" ) const ( diff --git a/pkg/audit/audit_test.go b/pkg/audit/audit_test.go index 9066d81ebe3..c210d91f8b2 100644 --- a/pkg/audit/audit_test.go +++ b/pkg/audit/audit_test.go @@ -27,6 +27,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/requestutil" "github.com/tikv/pd/pkg/utils/testutil" ) diff --git a/pkg/autoscaling/calculation.go b/pkg/autoscaling/calculation.go index 43aa2972ed8..41db5f6cf78 100644 --- a/pkg/autoscaling/calculation.go +++ b/pkg/autoscaling/calculation.go @@ -20,17 +20,19 @@ import ( "strings" "time" + promClient "github.com/prometheus/client_golang/api" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" - promClient "github.com/prometheus/client_golang/api" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule/filter" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/server/cluster" "github.com/tikv/pd/server/config" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( diff --git a/pkg/autoscaling/calculation_test.go b/pkg/autoscaling/calculation_test.go index 9eb4ad648df..c2a70f8920e 100644 --- a/pkg/autoscaling/calculation_test.go +++ b/pkg/autoscaling/calculation_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/autoscaling/handler.go b/pkg/autoscaling/handler.go index ea248fdcc55..52b342f4a85 100644 --- a/pkg/autoscaling/handler.go +++ b/pkg/autoscaling/handler.go @@ -19,9 +19,10 @@ import ( "io" "net/http" + "github.com/unrolled/render" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/server" - "github.com/unrolled/render" ) // HTTPHandler is a handler to handle the auto scaling HTTP request. diff --git a/pkg/autoscaling/prometheus.go b/pkg/autoscaling/prometheus.go index 91b813b6ef2..43c47c8c898 100644 --- a/pkg/autoscaling/prometheus.go +++ b/pkg/autoscaling/prometheus.go @@ -22,13 +22,15 @@ import ( "strings" "time" - "github.com/pingcap/errors" - "github.com/pingcap/log" promClient "github.com/prometheus/client_golang/api" promAPI "github.com/prometheus/client_golang/api/prometheus/v1" promModel "github.com/prometheus/common/model" - "github.com/tikv/pd/pkg/errs" "go.uber.org/zap" + + "github.com/pingcap/errors" + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" ) const ( diff --git a/pkg/autoscaling/service.go b/pkg/autoscaling/service.go index a8d84b2e598..304f1aa1188 100644 --- a/pkg/autoscaling/service.go +++ b/pkg/autoscaling/service.go @@ -18,11 +18,12 @@ import ( "context" "net/http" + "github.com/unrolled/render" + "github.com/urfave/negroni" + "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/apiutil/serverapi" "github.com/tikv/pd/server" - "github.com/unrolled/render" - "github.com/urfave/negroni" ) const autoScalingPrefix = "/autoscaling" diff --git a/pkg/autoscaling/types.go b/pkg/autoscaling/types.go index 53c614312b2..bee0d157191 100644 --- a/pkg/autoscaling/types.go +++ b/pkg/autoscaling/types.go @@ -20,8 +20,9 @@ import ( "regexp" "strings" - "github.com/tikv/pd/pkg/utils/etcdutil" clientv3 "go.etcd.io/etcd/client/v3" + + "github.com/tikv/pd/pkg/utils/etcdutil" ) // Strategy within a HTTP request provides rules and resources to help make decision for auto scaling. diff --git a/pkg/basicserver/metrics.go b/pkg/basicserver/metrics.go index 4e4ab214ed5..dad79c8763f 100644 --- a/pkg/basicserver/metrics.go +++ b/pkg/basicserver/metrics.go @@ -14,7 +14,10 @@ package server -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" +) var ( // ServerMaxProcsGauge records the maxprocs. @@ -46,6 +49,9 @@ var ( ) func init() { + prometheus.DefaultRegisterer.Unregister(collectors.NewGoCollector()) + prometheus.MustRegister(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsGC, collectors.MetricsMemory, collectors.MetricsScheduler))) + prometheus.MustRegister(ServerMaxProcsGauge) prometheus.MustRegister(ServerMemoryLimit) prometheus.MustRegister(ServerInfoGauge) diff --git a/pkg/cache/cache_test.go b/pkg/cache/cache_test.go index 75f26cfed33..d7d7365a344 100644 --- a/pkg/cache/cache_test.go +++ b/pkg/cache/cache_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" ) diff --git a/pkg/cache/ttl.go b/pkg/cache/ttl.go index 2aa39f6c6fd..ba7e3b67330 100644 --- a/pkg/cache/ttl.go +++ b/pkg/cache/ttl.go @@ -18,10 +18,12 @@ import ( "context" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) type ttlCacheItem struct { diff --git a/pkg/cgroup/cgmon.go b/pkg/cgroup/cgmon.go index 407e50f50c7..4be033facb1 100644 --- a/pkg/cgroup/cgmon.go +++ b/pkg/cgroup/cgmon.go @@ -21,10 +21,12 @@ import ( "sync" "time" - "github.com/pingcap/log" "github.com/shirou/gopsutil/v3/mem" - bs "github.com/tikv/pd/pkg/basicserver" "go.uber.org/zap" + + "github.com/pingcap/log" + + bs "github.com/tikv/pd/pkg/basicserver" ) const ( diff --git a/pkg/cgroup/cgroup.go b/pkg/cgroup/cgroup.go index 133bd3158c8..0093020a0ac 100644 --- a/pkg/cgroup/cgroup.go +++ b/pkg/cgroup/cgroup.go @@ -26,9 +26,10 @@ import ( "strconv" "strings" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" - "go.uber.org/zap" ) // CPUQuotaStatus presents the status of how CPU quota is used diff --git a/pkg/cgroup/cgroup_cpu.go b/pkg/cgroup/cgroup_cpu.go index 67eace5363c..e696e36fad5 100644 --- a/pkg/cgroup/cgroup_cpu.go +++ b/pkg/cgroup/cgroup_cpu.go @@ -19,9 +19,9 @@ import ( "path/filepath" "github.com/pingcap/errors" -) -var errNoCPUControllerDetected = errors.New("no cpu controller detected") + "github.com/tikv/pd/pkg/errs" +) // Helper function for getCgroupCPU. Root is always "/", except in tests. func getCgroupCPUHelper(root string) (CPUUsage, error) { @@ -32,7 +32,7 @@ func getCgroupCPUHelper(root string) (CPUUsage, error) { // No CPU controller detected if path == "" { - return CPUUsage{}, errNoCPUControllerDetected + return CPUUsage{}, errs.ErrNoCPUControllerDetected } mount, ver, err := getCgroupDetails(filepath.Join(root, procPathMountInfo), path, "cpu,cpuacct") diff --git a/pkg/cgroup/cgroup_cpu_test.go b/pkg/cgroup/cgroup_cpu_test.go index 265291163c3..441c2192e79 100644 --- a/pkg/cgroup/cgroup_cpu_test.go +++ b/pkg/cgroup/cgroup_cpu_test.go @@ -26,6 +26,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + "github.com/tikv/pd/pkg/errs" ) func checkKernelVersionNewerThan(re *require.Assertions, t *testing.T, major, minor int) bool { @@ -82,7 +84,7 @@ func TestGetCgroupCPU(t *testing.T) { }() } cpu, err := GetCgroupCPU() - if err == errNoCPUControllerDetected { + if err == errs.ErrNoCPUControllerDetected { // for more information, please refer https://github.com/pingcap/tidb/pull/41347 if checkKernelVersionNewerThan(re, t, 4, 7) { re.NoError(err, "linux version > v4.7 and err still happens") diff --git a/pkg/core/factory_test.go b/pkg/core/factory_test.go index 9f0ba883885..a81da9af081 100644 --- a/pkg/core/factory_test.go +++ b/pkg/core/factory_test.go @@ -18,7 +18,9 @@ import ( "testing" "github.com/gogo/protobuf/proto" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/utils/typeutil" ) diff --git a/pkg/core/region.go b/pkg/core/region.go index b5ead86b3f1..5f5a4a5f2e0 100644 --- a/pkg/core/region.go +++ b/pkg/core/region.go @@ -29,17 +29,19 @@ import ( "github.com/docker/go-units" "github.com/gogo/protobuf/proto" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/replication_modepb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/core/region_test.go b/pkg/core/region_test.go index 8c30efb2769..51ba5fe96dc 100644 --- a/pkg/core/region_test.go +++ b/pkg/core/region_test.go @@ -23,10 +23,12 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/id" "github.com/tikv/pd/pkg/mock/mockid" diff --git a/pkg/core/region_tree.go b/pkg/core/region_tree.go index 12e2c5c8878..6efafd133cf 100644 --- a/pkg/core/region_tree.go +++ b/pkg/core/region_tree.go @@ -18,12 +18,14 @@ import ( "bytes" "math/rand" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/btree" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) type regionItem struct { diff --git a/pkg/core/region_tree_test.go b/pkg/core/region_tree_test.go index 0dedd91be9e..4d18394aa70 100644 --- a/pkg/core/region_tree_test.go +++ b/pkg/core/region_tree_test.go @@ -19,9 +19,10 @@ import ( "math/rand" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" ) func TestRegionInfo(t *testing.T) { diff --git a/pkg/core/store.go b/pkg/core/store.go index 5edf59f6dce..9ec9a44bfc8 100644 --- a/pkg/core/store.go +++ b/pkg/core/store.go @@ -20,15 +20,17 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/core/store_option.go b/pkg/core/store_option.go index 3d05a0fb6e1..80fb09853e2 100644 --- a/pkg/core/store_option.go +++ b/pkg/core/store_option.go @@ -19,6 +19,7 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/pkg/core/store_stats.go b/pkg/core/store_stats.go index d68f8b8e43c..6c6a6420d56 100644 --- a/pkg/core/store_stats.go +++ b/pkg/core/store_stats.go @@ -16,6 +16,7 @@ package core import ( "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/movingaverage" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/pkg/core/store_stats_test.go b/pkg/core/store_stats_test.go index 9f2969cd81f..47f30dbd27b 100644 --- a/pkg/core/store_stats_test.go +++ b/pkg/core/store_stats_test.go @@ -18,9 +18,10 @@ import ( "testing" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" ) func TestStoreStats(t *testing.T) { diff --git a/pkg/core/store_test.go b/pkg/core/store_test.go index 5cb324e5635..7c5aaa98289 100644 --- a/pkg/core/store_test.go +++ b/pkg/core/store_test.go @@ -21,9 +21,11 @@ import ( "time" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/typeutil" ) diff --git a/pkg/core/storelimit/limit_test.go b/pkg/core/storelimit/limit_test.go index cfe805935a5..eb0bde2732f 100644 --- a/pkg/core/storelimit/limit_test.go +++ b/pkg/core/storelimit/limit_test.go @@ -23,6 +23,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core/constant" ) diff --git a/pkg/dashboard/adapter/manager.go b/pkg/dashboard/adapter/manager.go index 293d8ad6549..648f5562419 100644 --- a/pkg/dashboard/adapter/manager.go +++ b/pkg/dashboard/adapter/manager.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" "github.com/pingcap/tidb-dashboard/pkg/apiserver" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/server" diff --git a/pkg/dashboard/adapter/redirector.go b/pkg/dashboard/adapter/redirector.go index c1d845065b7..5d0fd1801cd 100644 --- a/pkg/dashboard/adapter/redirector.go +++ b/pkg/dashboard/adapter/redirector.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb-dashboard/pkg/apiserver" "github.com/pingcap/tidb-dashboard/pkg/utils" + "github.com/tikv/pd/pkg/utils/syncutil" ) diff --git a/pkg/dashboard/distroutil/distro.go b/pkg/dashboard/distroutil/distro.go index a19db806d70..0bc7b1d031b 100644 --- a/pkg/dashboard/distroutil/distro.go +++ b/pkg/dashboard/distroutil/distro.go @@ -18,9 +18,10 @@ import ( "os" "path/filepath" + "go.uber.org/zap" + "github.com/pingcap/log" "github.com/pingcap/tidb-dashboard/util/distro" - "go.uber.org/zap" ) const ( diff --git a/pkg/dashboard/keyvisual/input/core.go b/pkg/dashboard/keyvisual/input/core.go index 3ca5f96cd81..0219d6e0b77 100644 --- a/pkg/dashboard/keyvisual/input/core.go +++ b/pkg/dashboard/keyvisual/input/core.go @@ -15,11 +15,13 @@ package input import ( + "go.uber.org/zap" + "github.com/pingcap/log" regionpkg "github.com/pingcap/tidb-dashboard/pkg/keyvisual/region" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/server" - "go.uber.org/zap" ) const limit = 1024 diff --git a/pkg/dashboard/uiserver/embedded_assets_rewriter.go b/pkg/dashboard/uiserver/embedded_assets_rewriter.go index d19db01936f..f0f9f0c1e51 100644 --- a/pkg/dashboard/uiserver/embedded_assets_rewriter.go +++ b/pkg/dashboard/uiserver/embedded_assets_rewriter.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/tidb-dashboard/pkg/config" "github.com/pingcap/tidb-dashboard/pkg/uiserver" + "github.com/tikv/pd/pkg/dashboard/distroutil" ) diff --git a/pkg/election/leadership.go b/pkg/election/leadership.go index ec64a003c53..bb0ce7bf361 100644 --- a/pkg/election/leadership.go +++ b/pkg/election/leadership.go @@ -19,18 +19,20 @@ import ( "sync/atomic" "time" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( diff --git a/pkg/election/leadership_test.go b/pkg/election/leadership_test.go index eab842ca6e5..fc158e6f73a 100644 --- a/pkg/election/leadership_test.go +++ b/pkg/election/leadership_test.go @@ -21,12 +21,14 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/etcdutil" - "github.com/tikv/pd/pkg/utils/testutil" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/embed" + + "github.com/pingcap/failpoint" + + "github.com/tikv/pd/pkg/utils/etcdutil" + "github.com/tikv/pd/pkg/utils/testutil" ) const defaultLeaseTimeout = 1 diff --git a/pkg/election/lease.go b/pkg/election/lease.go index 21bd43018b5..1dff5ea7a99 100644 --- a/pkg/election/lease.go +++ b/pkg/election/lease.go @@ -19,13 +19,15 @@ import ( "sync/atomic" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( diff --git a/pkg/election/lease_test.go b/pkg/election/lease_test.go index 3a02de97239..b099d0c0d5e 100644 --- a/pkg/election/lease_test.go +++ b/pkg/election/lease_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/etcdutil" ) diff --git a/pkg/encryption/config.go b/pkg/encryption/config.go index d4d257a8a43..38222c56b5d 100644 --- a/pkg/encryption/config.go +++ b/pkg/encryption/config.go @@ -18,6 +18,7 @@ import ( "time" "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/typeutil" ) diff --git a/pkg/encryption/config_test.go b/pkg/encryption/config_test.go index 4134d46c2f3..2ab5ae68dfa 100644 --- a/pkg/encryption/config_test.go +++ b/pkg/encryption/config_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/typeutil" ) diff --git a/pkg/encryption/crypter.go b/pkg/encryption/crypter.go index 7e69854c5a8..5c91228c150 100644 --- a/pkg/encryption/crypter.go +++ b/pkg/encryption/crypter.go @@ -22,6 +22,7 @@ import ( "io" "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/tikv/pd/pkg/errs" ) diff --git a/pkg/encryption/crypter_test.go b/pkg/encryption/crypter_test.go index 9ac72bd7813..ff660cc1a9d 100644 --- a/pkg/encryption/crypter_test.go +++ b/pkg/encryption/crypter_test.go @@ -19,8 +19,9 @@ import ( "encoding/hex" "testing" - "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/encryptionpb" ) func TestEncryptionMethodSupported(t *testing.T) { diff --git a/pkg/encryption/key_manager.go b/pkg/encryption/key_manager.go index 621b1b9742f..54e5fa01b35 100644 --- a/pkg/encryption/key_manager.go +++ b/pkg/encryption/key_manager.go @@ -20,15 +20,17 @@ import ( "time" "github.com/gogo/protobuf/proto" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( diff --git a/pkg/encryption/key_manager_test.go b/pkg/encryption/key_manager_test.go index f387497c2e9..52e91296314 100644 --- a/pkg/encryption/key_manager_test.go +++ b/pkg/encryption/key_manager_test.go @@ -24,13 +24,15 @@ import ( "time" "github.com/gogo/protobuf/proto" - "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/stretchr/testify/require" + clientv3 "go.etcd.io/etcd/client/v3" + + "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" ) // #nosec G101 diff --git a/pkg/encryption/kms.go b/pkg/encryption/kms.go index 99dcf9619a3..3836cf53db6 100644 --- a/pkg/encryption/kms.go +++ b/pkg/encryption/kms.go @@ -22,7 +22,9 @@ import ( "github.com/aws/aws-sdk-go-v2/credentials/stscreds" "github.com/aws/aws-sdk-go-v2/service/kms" "github.com/aws/aws-sdk-go-v2/service/sts" + "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/tikv/pd/pkg/errs" ) diff --git a/pkg/encryption/master_key.go b/pkg/encryption/master_key.go index 31d9a0cb591..aff480386ac 100644 --- a/pkg/encryption/master_key.go +++ b/pkg/encryption/master_key.go @@ -20,6 +20,7 @@ import ( "strings" "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/tikv/pd/pkg/errs" ) diff --git a/pkg/encryption/master_key_test.go b/pkg/encryption/master_key_test.go index d6d7845284a..0a8e99bf75a 100644 --- a/pkg/encryption/master_key_test.go +++ b/pkg/encryption/master_key_test.go @@ -20,8 +20,9 @@ import ( "path/filepath" "testing" - "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/encryptionpb" ) func TestPlaintextMasterKey(t *testing.T) { diff --git a/pkg/encryption/region_crypter.go b/pkg/encryption/region_crypter.go index 458c5b67d7b..96826d8bef6 100644 --- a/pkg/encryption/region_crypter.go +++ b/pkg/encryption/region_crypter.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/pkg/encryption/region_crypter_test.go b/pkg/encryption/region_crypter_test.go index b1ca558063c..1b6f910b0d5 100644 --- a/pkg/encryption/region_crypter_test.go +++ b/pkg/encryption/region_crypter_test.go @@ -19,10 +19,11 @@ import ( "crypto/cipher" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/stretchr/testify/require" ) type testKeyManager struct { diff --git a/pkg/errs/errno.go b/pkg/errs/errno.go index e5c23cffde2..30e24647a3f 100644 --- a/pkg/errs/errno.go +++ b/pkg/errs/errno.go @@ -41,7 +41,6 @@ var ( // tso errors var ( ErrGetAllocator = errors.Normalize("get allocator failed, %s", errors.RFCCodeText("PD:tso:ErrGetAllocator")) - ErrGetLocalAllocator = errors.Normalize("get local allocator failed, %s", errors.RFCCodeText("PD:tso:ErrGetLocalAllocator")) ErrResetUserTimestamp = errors.Normalize("reset user timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrResetUserTimestamp")) ErrGenerateTimestamp = errors.Normalize("generate timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrGenerateTimestamp")) ErrUpdateTimestamp = errors.Normalize("update timestamp failed, %s", errors.RFCCodeText("PD:tso:ErrUpdateTimestamp")) @@ -140,8 +139,69 @@ var ( // checker errors var ( - ErrCheckerNotFound = errors.Normalize("checker not found", errors.RFCCodeText("PD:checker:ErrCheckerNotFound")) - ErrCheckerMergeAgain = errors.Normalize("region will be merged again, %s", errors.RFCCodeText("PD:checker:ErrCheckerMergeAgain")) + ErrCheckerNotFound = errors.Normalize("checker not found", errors.RFCCodeText("PD:checker:ErrCheckerNotFound")) + ErrCheckerMergeAgain = errors.Normalize("region will be merged again, %s", errors.RFCCodeText("PD:checker:ErrCheckerMergeAgain")) + ErrNoStoreToAdd = errors.Normalize("no store to add peer", errors.RFCCodeText("PD:checker:ErrNoStoreToAdd")) + ErrNoStoreToReplace = errors.Normalize("no store to replace peer", errors.RFCCodeText("PD:checker:ErrNoStoreToReplace")) + ErrPeerCannotBeLeader = errors.Normalize("peer cannot be leader", errors.RFCCodeText("PD:checker:ErrPeerCannotBeLeader")) + ErrPeerCannotBeWitness = errors.Normalize("peer cannot be witness", errors.RFCCodeText("PD:checker:ErrPeerCannotBeWitness")) + ErrNoNewLeader = errors.Normalize("no new leader", errors.RFCCodeText("PD:checker:ErrNoNewLeader")) + ErrRegionNoLeader = errors.Normalize("region no leader", errors.RFCCodeText("PD:checker:ErrRegionNoLeader")) +) + +// scatter errors +var ( + ErrEmptyRegion = errors.Normalize("empty region", errors.RFCCodeText("PD:scatter:ErrEmptyRegion")) +) + +// keyspace errors +var ( + // ErrKeyspaceNotFound is used to indicate target keyspace does not exist. + ErrKeyspaceNotFound = errors.Normalize("keyspace does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotFound")) + // ErrRegionSplitTimeout indices to split region timeout + ErrRegionSplitTimeout = errors.Normalize("region split timeout", errors.RFCCodeText("PD:keyspace:ErrRegionSplitTimeout")) + // ErrRegionSplitFailed indices to split region failed + ErrRegionSplitFailed = errors.Normalize("region split failed", errors.RFCCodeText("PD:keyspace:ErrRegionSplitFailed")) + // ErrKeyspaceExists indicates target keyspace already exists. + // It's used when creating a new keyspace. + ErrKeyspaceExists = errors.Normalize("keyspace already exists", errors.RFCCodeText("PD:keyspace:ErrKeyspaceExists")) + // ErrKeyspaceGroupExists indicates target keyspace group already exists. + ErrKeyspaceGroupExists = errors.Normalize("keyspace group already exists", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupExists")) + // ErrKeyspaceNotInKeyspaceGroup is used to indicate target keyspace is not in this keyspace group. + ErrKeyspaceNotInKeyspaceGroup = errors.Normalize("keyspace is not in this keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotInKeyspaceGroup")) + // ErrKeyspaceNotInAnyKeyspaceGroup is used to indicate target keyspace is not in any keyspace group. + ErrKeyspaceNotInAnyKeyspaceGroup = errors.Normalize("keyspace is not in any keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceNotInAnyKeyspaceGroup")) + // ErrNodeNotInKeyspaceGroup is used to indicate the tso node is not in this keyspace group. + ErrNodeNotInKeyspaceGroup = errors.Normalize("the tso node is not in this keyspace group", errors.RFCCodeText("PD:keyspace:ErrNodeNotInKeyspaceGroup")) + // ErrKeyspaceGroupNotEnoughReplicas is used to indicate not enough replicas in the keyspace group. + ErrKeyspaceGroupNotEnoughReplicas = errors.Normalize("not enough replicas in the keyspace group", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotEnoughReplicas")) + // ErrKeyspaceGroupWithEmptyKeyspace is used to indicate keyspace group with empty keyspace. + ErrKeyspaceGroupWithEmptyKeyspace = errors.Normalize("keyspace group with empty keyspace", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupWithEmptyKeyspace")) + // ErrModifyDefaultKeyspaceGroup is used to indicate that default keyspace group cannot be modified. + ErrModifyDefaultKeyspaceGroup = errors.Normalize("default keyspace group cannot be modified", errors.RFCCodeText("PD:keyspace:ErrModifyDefaultKeyspaceGroup")) + // ErrNoAvailableNode is used to indicate no available node in the keyspace group. + ErrNoAvailableNode = errors.Normalize("no available node", errors.RFCCodeText("PD:keyspace:ErrNoAvailableNode")) + // ErrExceedMaxEtcdTxnOps is used to indicate the number of etcd txn operations exceeds the limit. + ErrExceedMaxEtcdTxnOps = errors.Normalize("exceed max etcd txn operations", errors.RFCCodeText("PD:keyspace:ErrExceedMaxEtcdTxnOps")) + // ErrModifyDefaultKeyspace is used to indicate that default keyspace cannot be modified. + ErrModifyDefaultKeyspace = errors.Normalize("cannot modify default keyspace's state", errors.RFCCodeText("PD:keyspace:ErrModifyDefaultKeyspace")) + // ErrIllegalOperation is used to indicate this is an illegal operation. + ErrIllegalOperation = errors.Normalize("unknown operation", errors.RFCCodeText("PD:keyspace:ErrIllegalOperation")) + // ErrUnsupportedOperationInKeyspace is used to indicate this is an unsupported operation. + ErrUnsupportedOperationInKeyspace = errors.Normalize("it's a unsupported operation", errors.RFCCodeText("PD:keyspace:ErrUnsupportedOperationInKeyspace")) + // ErrKeyspaceGroupPrimaryNotFound is used to indicate primary of target keyspace group does not exist. + ErrKeyspaceGroupPrimaryNotFound = errors.Normalize("primary of keyspace group does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupPrimaryNotFound")) + // ErrKeyspaceGroupNotExists is used to indicate target keyspace group does not exist. + ErrKeyspaceGroupNotExists = errors.Normalize("keyspace group %v does not exist", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotExists")) + // ErrKeyspaceGroupInSplit is used to indicate target keyspace group is in split state. + ErrKeyspaceGroupInSplit = errors.Normalize("keyspace group %v is in split state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupInSplit")) + // ErrKeyspaceGroupNotInSplit is used to indicate target keyspace group is not in split state. + ErrKeyspaceGroupNotInSplit = errors.Normalize("keyspace group %v is not in split state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotInSplit")) + // ErrKeyspaceGroupInMerging is used to indicate target keyspace group is in merging state. + ErrKeyspaceGroupInMerging = errors.Normalize("keyspace group %v is in merging state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupInMerging")) + // ErrKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state. + ErrKeyspaceGroupNotInMerging = errors.Normalize("keyspace group %v is not in merging state", errors.RFCCodeText("PD:keyspace:ErrKeyspaceGroupNotInMerging")) + // errKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state. ) // diagnostic errors @@ -229,6 +289,16 @@ var ( ErrBytesToUint64 = errors.Normalize("invalid data, must 8 bytes, but %d", errors.RFCCodeText("PD:typeutil:ErrBytesToUint64")) ) +// cgroup errors +var ( + ErrNoCPUControllerDetected = errors.Normalize("no cpu controller detected", errors.RFCCodeText("PD:cgroup:ErrNoCPUControllerDetected")) +) + +// ratelimit errors +var ( + ErrMaxWaitingTasksExceeded = errors.Normalize("max waiting tasks exceeded", errors.RFCCodeText("PD:ratelimit:ErrMaxWaitingTasksExceeded")) +) + // The third-party project error. // url errors var ( diff --git a/pkg/errs/errs.go b/pkg/errs/errs.go index 5746b282f10..84cc90312d1 100644 --- a/pkg/errs/errs.go +++ b/pkg/errs/errs.go @@ -15,9 +15,10 @@ package errs import ( - "github.com/pingcap/errors" "go.uber.org/zap" "go.uber.org/zap/zapcore" + + "github.com/pingcap/errors" ) // ZapError is used to make the log output easier. diff --git a/pkg/errs/errs_test.go b/pkg/errs/errs_test.go index 01b7de461b8..80722f4a8c4 100644 --- a/pkg/errs/errs_test.go +++ b/pkg/errs/errs_test.go @@ -20,10 +20,11 @@ import ( "strings" "testing" - "github.com/pingcap/errors" - "github.com/pingcap/log" "github.com/stretchr/testify/require" "go.uber.org/zap" + + "github.com/pingcap/errors" + "github.com/pingcap/log" ) // testingWriter is a WriteSyncer that writes to the the messages. diff --git a/pkg/gc/safepoint.go b/pkg/gc/safepoint.go index c1b4687e109..5bc64ae9a90 100644 --- a/pkg/gc/safepoint.go +++ b/pkg/gc/safepoint.go @@ -19,6 +19,7 @@ import ( "time" "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/server/config" diff --git a/pkg/gc/safepoint_test.go b/pkg/gc/safepoint_test.go index 62ce9c086fc..b67f7b4fe44 100644 --- a/pkg/gc/safepoint_test.go +++ b/pkg/gc/safepoint_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/server/config" diff --git a/pkg/gc/safepoint_v2.go b/pkg/gc/safepoint_v2.go index 665249bcab0..acdd4e6eef8 100644 --- a/pkg/gc/safepoint_v2.go +++ b/pkg/gc/safepoint_v2.go @@ -18,16 +18,19 @@ import ( "context" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/keyspace" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) var ( @@ -99,7 +102,7 @@ func (manager *SafePointV2Manager) checkKeyspace(keyspaceID uint32, updateReques } // If a keyspace does not exist, then loading its gc safe point is prohibited. if meta == nil { - return keyspace.ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } // If keyspace's state does not permit updating safe point, we return error. if updateRequest && !slice.Contains(allowUpdateSafePoint, meta.GetState()) { diff --git a/pkg/gctuner/memory_limit_tuner.go b/pkg/gctuner/memory_limit_tuner.go index 8a852b191d8..10e28842938 100644 --- a/pkg/gctuner/memory_limit_tuner.go +++ b/pkg/gctuner/memory_limit_tuner.go @@ -20,12 +20,14 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/log" + util "github.com/tikv/pd/pkg/gogc" "github.com/tikv/pd/pkg/memory" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // GlobalMemoryLimitTuner only allow one memory limit tuner in one process diff --git a/pkg/gctuner/memory_limit_tuner_test.go b/pkg/gctuner/memory_limit_tuner_test.go index 5e5f84ccbac..6c0aaca685d 100644 --- a/pkg/gctuner/memory_limit_tuner_test.go +++ b/pkg/gctuner/memory_limit_tuner_test.go @@ -20,8 +20,10 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/memory" ) diff --git a/pkg/gctuner/tuner.go b/pkg/gctuner/tuner.go index 74932fe174b..bc63b36c5a2 100644 --- a/pkg/gctuner/tuner.go +++ b/pkg/gctuner/tuner.go @@ -20,9 +20,11 @@ import ( "strconv" "sync/atomic" + "go.uber.org/zap" + "github.com/pingcap/log" + util "github.com/tikv/pd/pkg/gogc" - "go.uber.org/zap" ) var ( diff --git a/pkg/id/id.go b/pkg/id/id.go index eb2788fc656..cb38c23268d 100644 --- a/pkg/id/id.go +++ b/pkg/id/id.go @@ -15,16 +15,18 @@ package id import ( - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) type label string diff --git a/pkg/id/id_test.go b/pkg/id/id_test.go index e08c0e93367..9cd8493c430 100644 --- a/pkg/id/id_test.go +++ b/pkg/id/id_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/etcdutil" ) diff --git a/pkg/keyspace/keyspace.go b/pkg/keyspace/keyspace.go index 08bb51da936..c9e390df47a 100644 --- a/pkg/keyspace/keyspace.go +++ b/pkg/keyspace/keyspace.go @@ -20,10 +20,14 @@ import ( "strconv" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/id" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/schedule/core" @@ -35,7 +39,6 @@ import ( "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( @@ -151,7 +154,7 @@ func (manager *Manager) Bootstrap() error { err = manager.saveNewKeyspace(defaultKeyspaceMeta) // It's possible that default keyspace already exists in the storage (e.g. PD restart/recover), // so we ignore the keyspaceExists error. - if err != nil && err != ErrKeyspaceExists { + if err != nil && err != errs.ErrKeyspaceExists { return err } if err := manager.kgm.UpdateKeyspaceForGroup(endpoint.Basic, config[TSOKeyspaceGroupIDKey], defaultKeyspaceMeta.GetId(), opAdd); err != nil { @@ -172,7 +175,7 @@ func (manager *Manager) Bootstrap() error { } keyspace, err := manager.CreateKeyspace(req) // Ignore the keyspaceExists error for the same reason as saving default keyspace. - if err != nil && err != ErrKeyspaceExists { + if err != nil && err != errs.ErrKeyspaceExists { return err } if err := manager.kgm.UpdateKeyspaceForGroup(endpoint.Basic, config[TSOKeyspaceGroupIDKey], keyspace.GetId(), opAdd); err != nil { @@ -286,7 +289,7 @@ func (manager *Manager) saveNewKeyspace(keyspace *keyspacepb.KeyspaceMeta) error return err } if nameExists { - return ErrKeyspaceExists + return errs.ErrKeyspaceExists } err = manager.store.SaveKeyspaceID(txn, keyspace.Id, keyspace.Name) if err != nil { @@ -299,7 +302,7 @@ func (manager *Manager) saveNewKeyspace(keyspace *keyspacepb.KeyspaceMeta) error return err } if loadedMeta != nil { - return ErrKeyspaceExists + return errs.ErrKeyspaceExists } return manager.store.SaveKeyspaceMeta(txn, keyspace) }) @@ -341,7 +344,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er ranges := keyspaceRule.Data.([]*labeler.KeyRangeRule) if len(ranges) < 2 { log.Warn("[keyspace] failed to split keyspace region with insufficient range", logutil.ZapRedactString("label-rule", keyspaceRule.String())) - return ErrRegionSplitFailed + return errs.ErrRegionSplitFailed } rawLeftBound, rawRightBound := ranges[0].StartKey, ranges[0].EndKey txnLeftBound, txnRightBound := ranges[1].StartKey, ranges[1].EndKey @@ -379,7 +382,7 @@ func (manager *Manager) splitKeyspaceRegion(id uint32, waitRegionSplit bool) (er zap.Uint32("keyspace-id", id), zap.Error(err), ) - err = ErrRegionSplitTimeout + err = errs.ErrRegionSplitTimeout return } log.Info("[keyspace] wait region split successfully", zap.Uint32("keyspace-id", id)) @@ -405,14 +408,14 @@ func (manager *Manager) LoadKeyspace(name string) (*keyspacepb.KeyspaceMeta, err return err } if !loaded { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } meta, err = manager.store.LoadKeyspaceMeta(txn, id) if err != nil { return err } if meta == nil { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } return nil }) @@ -432,7 +435,7 @@ func (manager *Manager) LoadKeyspaceByID(spaceID uint32) (*keyspacepb.KeyspaceMe return err } if meta == nil { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } return nil }) @@ -472,7 +475,7 @@ func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation) return err } if !loaded { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } manager.metaLock.Lock(id) defer manager.metaLock.Unlock(id) @@ -482,7 +485,7 @@ func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation) return err } if meta == nil { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } // Only keyspace with state listed in allowChangeConfig are allowed to change their config. if !slice.Contains(allowChangeConfig, meta.GetState()) { @@ -503,7 +506,7 @@ func (manager *Manager) UpdateKeyspaceConfig(name string, mutations []*Mutation) case OpDel: delete(meta.Config, mutation.Key) default: - return errIllegalOperation + return errs.ErrIllegalOperation } } newConfig := meta.GetConfig() @@ -551,9 +554,9 @@ func (manager *Manager) UpdateKeyspaceState(name string, newState keyspacepb.Key // Changing the state of default keyspace is not allowed. if name == constant.DefaultKeyspaceName { log.Warn("[keyspace] failed to update keyspace config", - zap.Error(ErrModifyDefaultKeyspace), + errs.ZapError(errs.ErrModifyDefaultKeyspace), ) - return nil, ErrModifyDefaultKeyspace + return nil, errs.ErrModifyDefaultKeyspace } var meta *keyspacepb.KeyspaceMeta err := manager.store.RunInTxn(manager.ctx, func(txn kv.Txn) error { @@ -563,7 +566,7 @@ func (manager *Manager) UpdateKeyspaceState(name string, newState keyspacepb.Key return err } if !loaded { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } manager.metaLock.Lock(id) defer manager.metaLock.Unlock(id) @@ -573,7 +576,7 @@ func (manager *Manager) UpdateKeyspaceState(name string, newState keyspacepb.Key return err } if meta == nil { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } // Update keyspace meta. if err = updateKeyspaceState(meta, newState, now); err != nil { @@ -603,9 +606,9 @@ func (manager *Manager) UpdateKeyspaceStateByID(id uint32, newState keyspacepb.K // Changing the state of default keyspace is not allowed. if id == constant.DefaultKeyspaceID { log.Warn("[keyspace] failed to update keyspace config", - zap.Error(ErrModifyDefaultKeyspace), + errs.ZapError(errs.ErrModifyDefaultKeyspace), ) - return nil, ErrModifyDefaultKeyspace + return nil, errs.ErrModifyDefaultKeyspace } var meta *keyspacepb.KeyspaceMeta var err error @@ -618,7 +621,7 @@ func (manager *Manager) UpdateKeyspaceStateByID(id uint32, newState keyspacepb.K return err } if meta == nil { - return ErrKeyspaceNotFound + return errs.ErrKeyspaceNotFound } // Update keyspace meta. if err = updateKeyspaceState(meta, newState, now); err != nil { @@ -738,10 +741,10 @@ func (manager *Manager) PatrolKeyspaceAssignment(startKeyspaceID, endKeyspaceID return errors.Errorf("default keyspace group %d not found", constant.DefaultKeyspaceGroupID) } if defaultKeyspaceGroup.IsSplitting() { - return ErrKeyspaceGroupInSplit(constant.DefaultKeyspaceGroupID) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(constant.DefaultKeyspaceGroupID) } if defaultKeyspaceGroup.IsMerging() { - return ErrKeyspaceGroupInMerging(constant.DefaultKeyspaceGroupID) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(constant.DefaultKeyspaceGroupID) } keyspaces, err := manager.store.LoadRangeKeyspace(txn, manager.nextPatrolStartID, etcdutil.MaxEtcdTxnOps) if err != nil { diff --git a/pkg/keyspace/keyspace_test.go b/pkg/keyspace/keyspace_test.go index 3c259649cd3..57aeb70341d 100644 --- a/pkg/keyspace/keyspace_test.go +++ b/pkg/keyspace/keyspace_test.go @@ -23,10 +23,12 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" - "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/mock/mockid" "github.com/tikv/pd/pkg/storage/endpoint" diff --git a/pkg/keyspace/tso_keyspace_group.go b/pkg/keyspace/tso_keyspace_group.go index fa26b4cd0cb..a6068ffc2bb 100644 --- a/pkg/keyspace/tso_keyspace_group.go +++ b/pkg/keyspace/tso_keyspace_group.go @@ -23,11 +23,17 @@ import ( "sync" "time" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/balancer" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/slice" @@ -38,9 +44,6 @@ import ( "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( @@ -127,7 +130,7 @@ func (m *GroupManager) Bootstrap(ctx context.Context) error { // Ignore the error if default keyspace group already exists in the storage (e.g. PD restart/recover). err := m.saveKeyspaceGroups([]*endpoint.KeyspaceGroup{defaultKeyspaceGroup}, false) - if err != nil && err != ErrKeyspaceGroupExists { + if err != nil && err != errs.ErrKeyspaceGroupExists { return err } @@ -320,7 +323,7 @@ func (m *GroupManager) DeleteKeyspaceGroupByID(id uint32) (*endpoint.KeyspaceGro return nil } if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(id) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(id) } return m.store.DeleteKeyspaceGroup(txn, id) }); err != nil { @@ -346,13 +349,13 @@ func (m *GroupManager) saveKeyspaceGroups(keyspaceGroups []*endpoint.KeyspaceGro return err } if oldKG != nil && !overwrite { - return ErrKeyspaceGroupExists + return errs.ErrKeyspaceGroupExists } if oldKG.IsSplitting() && overwrite { - return ErrKeyspaceGroupInSplit(keyspaceGroup.ID) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(keyspaceGroup.ID) } if oldKG.IsMerging() && overwrite { - return ErrKeyspaceGroupInMerging(keyspaceGroup.ID) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(keyspaceGroup.ID) } newKG := &endpoint.KeyspaceGroup{ ID: keyspaceGroup.ID, @@ -408,7 +411,7 @@ func (m *GroupManager) GetGroupByKeyspaceID(id uint32) (uint32, error) { } } } - return 0, ErrKeyspaceNotInAnyKeyspaceGroup + return 0, errs.ErrKeyspaceNotInAnyKeyspaceGroup } var failpointOnce sync.Once @@ -438,13 +441,13 @@ func (m *GroupManager) UpdateKeyspaceForGroup(userKind endpoint.UserKind, groupI func (m *GroupManager) updateKeyspaceForGroupLocked(userKind endpoint.UserKind, groupID uint64, keyspaceID uint32, mutation int) error { kg := m.groups[userKind].Get(uint32(groupID)) if kg == nil { - return ErrKeyspaceGroupNotExists(uint32(groupID)) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(uint32(groupID)) } if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(uint32(groupID)) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(uint32(groupID)) } if kg.IsMerging() { - return ErrKeyspaceGroupInMerging(uint32(groupID)) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(uint32(groupID)) } changed := false @@ -498,13 +501,13 @@ func (m *GroupManager) UpdateKeyspaceGroup(oldGroupID, newGroupID string, oldUse return errors.Errorf("keyspace group %s not found in %s group", newGroupID, newUserKind) } if oldKG.IsSplitting() { - return ErrKeyspaceGroupInSplit(uint32(oldID)) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(uint32(oldID)) } else if newKG.IsSplitting() { - return ErrKeyspaceGroupInSplit(uint32(newID)) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(uint32(newID)) } else if oldKG.IsMerging() { - return ErrKeyspaceGroupInMerging(uint32(oldID)) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(uint32(oldID)) } else if newKG.IsMerging() { - return ErrKeyspaceGroupInMerging(uint32(newID)) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(uint32(newID)) } var updateOld, updateNew bool @@ -550,15 +553,15 @@ func (m *GroupManager) SplitKeyspaceGroupByID( return err } if splitSourceKg == nil { - return ErrKeyspaceGroupNotExists(splitSourceID) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(splitSourceID) } // A keyspace group can not take part in multiple split processes. if splitSourceKg.IsSplitting() { - return ErrKeyspaceGroupInSplit(splitSourceID) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(splitSourceID) } // A keyspace group can not be split when it is in merging. if splitSourceKg.IsMerging() { - return ErrKeyspaceGroupInMerging(splitSourceID) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(splitSourceID) } // Build the new keyspace groups for split source and target. var startKeyspaceID, endKeyspaceID uint32 @@ -572,7 +575,7 @@ func (m *GroupManager) SplitKeyspaceGroupByID( } // Check if the source keyspace group has enough replicas. if len(splitSourceKg.Members) < constant.DefaultKeyspaceGroupReplicaCount { - return ErrKeyspaceGroupNotEnoughReplicas + return errs.ErrKeyspaceGroupNotEnoughReplicas } // Check if the new keyspace group already exists. splitTargetKg, err = m.store.LoadKeyspaceGroup(txn, splitTargetID) @@ -580,7 +583,7 @@ func (m *GroupManager) SplitKeyspaceGroupByID( return err } if splitTargetKg != nil { - return ErrKeyspaceGroupExists + return errs.ErrKeyspaceGroupExists } // Update the old keyspace group. splitSourceKg.Keyspaces = splitSourceKeyspaces @@ -621,7 +624,7 @@ func buildSplitKeyspaces( // Split according to the new keyspace list. if newNum != 0 { if newNum > oldNum { - return nil, nil, ErrKeyspaceNotInKeyspaceGroup + return nil, nil, errs.ErrKeyspaceNotInKeyspaceGroup } var ( oldKeyspaceMap = make(map[uint32]struct{}, oldNum) @@ -632,10 +635,10 @@ func buildSplitKeyspaces( } for _, keyspace := range new { if keyspace == constant.DefaultKeyspaceID { - return nil, nil, ErrModifyDefaultKeyspace + return nil, nil, errs.ErrModifyDefaultKeyspace } if _, ok := oldKeyspaceMap[keyspace]; !ok { - return nil, nil, ErrKeyspaceNotInKeyspaceGroup + return nil, nil, errs.ErrKeyspaceNotInKeyspaceGroup } newKeyspaceMap[keyspace] = struct{}{} } @@ -660,7 +663,7 @@ func buildSplitKeyspaces( } // Split according to the start and end keyspace ID. if startKeyspaceID == 0 && endKeyspaceID == 0 { - return nil, nil, ErrKeyspaceNotInKeyspaceGroup + return nil, nil, errs.ErrKeyspaceNotInKeyspaceGroup } var ( newSplit = make([]uint32, 0, oldNum) @@ -679,7 +682,7 @@ func buildSplitKeyspaces( } // Check if the new keyspace list is empty. if len(newSplit) == 0 { - return nil, nil, ErrKeyspaceGroupWithEmptyKeyspace + return nil, nil, errs.ErrKeyspaceGroupWithEmptyKeyspace } // Get the split keyspace list for the old keyspace group. oldSplit := make([]uint32, 0, oldNum-len(newSplit)) @@ -703,11 +706,11 @@ func (m *GroupManager) FinishSplitKeyspaceByID(splitTargetID uint32) error { return err } if splitTargetKg == nil { - return ErrKeyspaceGroupNotExists(splitTargetID) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(splitTargetID) } // Check if it's in the split state. if !splitTargetKg.IsSplitTarget() { - return ErrKeyspaceGroupNotInSplit(splitTargetID) + return errs.ErrKeyspaceGroupNotInSplit.FastGenByArgs(splitTargetID) } // Load the split source keyspace group then. splitSourceKg, err = m.store.LoadKeyspaceGroup(txn, splitTargetKg.SplitSource()) @@ -715,10 +718,10 @@ func (m *GroupManager) FinishSplitKeyspaceByID(splitTargetID uint32) error { return err } if splitSourceKg == nil { - return ErrKeyspaceGroupNotExists(splitTargetKg.SplitSource()) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(splitTargetKg.SplitSource()) } if !splitSourceKg.IsSplitSource() { - return ErrKeyspaceGroupNotInSplit(splitTargetKg.SplitSource()) + return errs.ErrKeyspaceGroupNotInSplit.FastGenByArgs(splitTargetKg.SplitSource()) } splitTargetKg.SplitState = nil splitSourceKg.SplitState = nil @@ -763,13 +766,13 @@ func (m *GroupManager) AllocNodesForKeyspaceGroup(id uint32, existMembers map[st return err } if kg == nil { - return ErrKeyspaceGroupNotExists(id) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(id) } if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(id) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(id) } if kg.IsMerging() { - return ErrKeyspaceGroupInMerging(id) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(id) } for addr := range existMembers { @@ -786,14 +789,14 @@ func (m *GroupManager) AllocNodesForKeyspaceGroup(id uint32, existMembers map[st case <-ticker.C: } if m.GetNodesCount() == 0 { // double check - return ErrNoAvailableNode + return errs.ErrNoAvailableNode } if len(existMembers) == m.GetNodesCount() { break } addr := m.nodesBalancer.Next() if addr == "" { - return ErrNoAvailableNode + return errs.ErrNoAvailableNode } if _, ok := existMembers[addr]; ok { continue @@ -829,13 +832,13 @@ func (m *GroupManager) SetNodesForKeyspaceGroup(id uint32, nodes []string) error return err } if kg == nil { - return ErrKeyspaceGroupNotExists(id) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(id) } if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(id) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(id) } if kg.IsMerging() { - return ErrKeyspaceGroupInMerging(id) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(id) } members := make([]endpoint.KeyspaceGroupMember, 0, len(nodes)) for _, node := range nodes { @@ -866,13 +869,13 @@ func (m *GroupManager) SetPriorityForKeyspaceGroup(id uint32, node string, prior return err } if kg == nil { - return ErrKeyspaceGroupNotExists(id) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(id) } if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(id) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(id) } if kg.IsMerging() { - return ErrKeyspaceGroupInMerging(id) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(id) } inKeyspaceGroup := false members := make([]endpoint.KeyspaceGroupMember, 0, len(kg.Members)) @@ -884,7 +887,7 @@ func (m *GroupManager) SetPriorityForKeyspaceGroup(id uint32, node string, prior members = append(members, member) } if !inKeyspaceGroup { - return ErrNodeNotInKeyspaceGroup + return errs.ErrNodeNotInKeyspaceGroup } kg.Members = members return m.store.SaveKeyspaceGroup(txn, kg) @@ -918,10 +921,10 @@ func (m *GroupManager) MergeKeyspaceGroups(mergeTargetID uint32, mergeList []uin // - Load and update the target keyspace group. // So we pre-check the number of operations to avoid exceeding the maximum number of etcd transaction. if (mergeListNum+1)*2 > etcdutil.MaxEtcdTxnOps { - return ErrExceedMaxEtcdTxnOps + return errs.ErrExceedMaxEtcdTxnOps } if slice.Contains(mergeList, constant.DefaultKeyspaceGroupID) { - return ErrModifyDefaultKeyspaceGroup + return errs.ErrModifyDefaultKeyspaceGroup } var ( groups = make(map[uint32]*endpoint.KeyspaceGroup, mergeListNum+1) @@ -937,15 +940,15 @@ func (m *GroupManager) MergeKeyspaceGroups(mergeTargetID uint32, mergeList []uin return err } if kg == nil { - return ErrKeyspaceGroupNotExists(kgID) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(kgID) } // A keyspace group can not be merged if it's in splitting. if kg.IsSplitting() { - return ErrKeyspaceGroupInSplit(kgID) + return errs.ErrKeyspaceGroupInSplit.FastGenByArgs(kgID) } // A keyspace group can not be split when it is in merging. if kg.IsMerging() { - return ErrKeyspaceGroupInMerging(kgID) + return errs.ErrKeyspaceGroupInMerging.FastGenByArgs(kgID) } groups[kgID] = kg } @@ -1011,11 +1014,11 @@ func (m *GroupManager) FinishMergeKeyspaceByID(mergeTargetID uint32) error { return err } if mergeTargetKg == nil { - return ErrKeyspaceGroupNotExists(mergeTargetID) + return errs.ErrKeyspaceGroupNotExists.FastGenByArgs(mergeTargetID) } // Check if it's in the merging state. if !mergeTargetKg.IsMergeTarget() { - return ErrKeyspaceGroupNotInMerging(mergeTargetID) + return errs.ErrKeyspaceGroupNotInMerging.FastGenByArgs(mergeTargetID) } // Make sure all merging keyspace groups are deleted. for _, kgID := range mergeTargetKg.MergeState.MergeList { @@ -1024,7 +1027,7 @@ func (m *GroupManager) FinishMergeKeyspaceByID(mergeTargetID uint32) error { return err } if kg != nil { - return ErrKeyspaceGroupNotInMerging(kgID) + return errs.ErrKeyspaceGroupNotInMerging.FastGenByArgs(kgID) } } mergeList = mergeTargetKg.MergeState.MergeList @@ -1148,7 +1151,7 @@ func (m *GroupManager) GetKeyspaceGroupPrimaryByID(id uint32) (string, error) { return "", err } if kg == nil { - return "", ErrKeyspaceGroupNotExists(id) + return "", errs.ErrKeyspaceGroupNotExists.FastGenByArgs(id) } primaryPath := keypath.LeaderPath(&keypath.MsParam{ @@ -1161,7 +1164,7 @@ func (m *GroupManager) GetKeyspaceGroupPrimaryByID(id uint32) (string, error) { return "", err } if !ok { - return "", ErrKeyspaceGroupPrimaryNotFound + return "", errs.ErrKeyspaceGroupPrimaryNotFound } // The format of leader name is address-groupID. contents := strings.Split(leader.GetName(), "-") diff --git a/pkg/keyspace/tso_keyspace_group_test.go b/pkg/keyspace/tso_keyspace_group_test.go index 5878d7d907f..68461855c6f 100644 --- a/pkg/keyspace/tso_keyspace_group_test.go +++ b/pkg/keyspace/tso_keyspace_group_test.go @@ -22,6 +22,8 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" @@ -255,13 +257,13 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() { re.NoError(err) // split the default keyspace err = suite.kgm.SplitKeyspaceGroupByID(0, 4, []uint32{constant.DefaultKeyspaceID}) - re.ErrorIs(err, ErrModifyDefaultKeyspace) + re.ErrorIs(err, errs.ErrModifyDefaultKeyspace) // split the keyspace group 1 to 4 err = suite.kgm.SplitKeyspaceGroupByID(1, 4, []uint32{444}) - re.ErrorIs(err, ErrKeyspaceGroupNotEnoughReplicas) + re.ErrorIs(err, errs.ErrKeyspaceGroupNotEnoughReplicas) // split the keyspace group 2 to 4 without giving any keyspace err = suite.kgm.SplitKeyspaceGroupByID(2, 4, []uint32{}) - re.ErrorIs(err, ErrKeyspaceNotInKeyspaceGroup) + re.ErrorIs(err, errs.ErrKeyspaceNotInKeyspaceGroup) // split the keyspace group 2 to 4 err = suite.kgm.SplitKeyspaceGroupByID(2, 4, []uint32{333}) re.NoError(err) @@ -282,25 +284,25 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() { // finish the split of the keyspace group 2 err = suite.kgm.FinishSplitKeyspaceByID(2) - re.ErrorContains(err, ErrKeyspaceGroupNotInSplit(2).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupNotInSplit.FastGenByArgs(2).Error()) // finish the split of a non-existing keyspace group err = suite.kgm.FinishSplitKeyspaceByID(5) - re.ErrorContains(err, ErrKeyspaceGroupNotExists(5).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupNotExists.FastGenByArgs(5).Error()) // split the in-split keyspace group err = suite.kgm.SplitKeyspaceGroupByID(2, 4, []uint32{333}) - re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupInSplit.FastGenByArgs(2).Error()) // remove the in-split keyspace group kg2, err = suite.kgm.DeleteKeyspaceGroupByID(2) re.Nil(kg2) - re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupInSplit.FastGenByArgs(2).Error()) kg4, err = suite.kgm.DeleteKeyspaceGroupByID(4) re.Nil(kg4) - re.ErrorContains(err, ErrKeyspaceGroupInSplit(4).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupInSplit.FastGenByArgs(4).Error()) // update the in-split keyspace group err = suite.kg.kgm.UpdateKeyspaceForGroup(endpoint.Standard, "2", 444, opAdd) - re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupInSplit.FastGenByArgs(2).Error()) err = suite.kg.kgm.UpdateKeyspaceForGroup(endpoint.Standard, "4", 444, opAdd) - re.ErrorContains(err, ErrKeyspaceGroupInSplit(4).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupInSplit.FastGenByArgs(4).Error()) // finish the split of keyspace group 4 err = suite.kgm.FinishSplitKeyspaceByID(4) @@ -320,13 +322,13 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() { // split a non-existing keyspace group err = suite.kgm.SplitKeyspaceGroupByID(3, 5, nil) - re.ErrorContains(err, ErrKeyspaceGroupNotExists(3).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupNotExists.FastGenByArgs(3).Error()) // split into an existing keyspace group err = suite.kgm.SplitKeyspaceGroupByID(2, 4, []uint32{111}) - re.ErrorIs(err, ErrKeyspaceGroupExists) + re.ErrorIs(err, errs.ErrKeyspaceGroupExists) // split with the wrong keyspaces. err = suite.kgm.SplitKeyspaceGroupByID(2, 5, []uint32{111, 222, 444}) - re.ErrorIs(err, ErrKeyspaceNotInKeyspaceGroup) + re.ErrorIs(err, errs.ErrKeyspaceNotInKeyspaceGroup) } func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplitRange() { @@ -448,13 +450,13 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupMerge() { // merge a non-existing keyspace group err = suite.kgm.MergeKeyspaceGroups(4, []uint32{5}) - re.ErrorContains(err, ErrKeyspaceGroupNotExists(5).Error()) + re.ErrorContains(err, errs.ErrKeyspaceGroupNotExists.FastGenByArgs(5).Error()) // merge with the number of keyspace groups exceeds the limit err = suite.kgm.MergeKeyspaceGroups(1, make([]uint32, etcdutil.MaxEtcdTxnOps/2)) - re.ErrorIs(err, ErrExceedMaxEtcdTxnOps) + re.ErrorIs(err, errs.ErrExceedMaxEtcdTxnOps) // merge the default keyspace group err = suite.kgm.MergeKeyspaceGroups(1, []uint32{constant.DefaultKeyspaceGroupID}) - re.ErrorIs(err, ErrModifyDefaultKeyspaceGroup) + re.ErrorIs(err, errs.ErrModifyDefaultKeyspaceGroup) } func TestBuildSplitKeyspaces(t *testing.T) { @@ -483,7 +485,7 @@ func TestBuildSplitKeyspaces(t *testing.T) { { old: []uint32{1, 2, 3, 4, 5}, new: []uint32{6}, - err: ErrKeyspaceNotInKeyspaceGroup, + err: errs.ErrKeyspaceNotInKeyspaceGroup, }, { old: []uint32{1, 2}, @@ -544,11 +546,11 @@ func TestBuildSplitKeyspaces(t *testing.T) { old: []uint32{1, 2, 3, 4, 5}, startKeyspaceID: 7, endKeyspaceID: 10, - err: ErrKeyspaceGroupWithEmptyKeyspace, + err: errs.ErrKeyspaceGroupWithEmptyKeyspace, }, { old: []uint32{1, 2, 3, 4, 5}, - err: ErrKeyspaceNotInKeyspaceGroup, + err: errs.ErrKeyspaceNotInKeyspaceGroup, }, } for idx, testCase := range testCases { diff --git a/pkg/keyspace/util.go b/pkg/keyspace/util.go index 91d07676205..e68a8fa60e8 100644 --- a/pkg/keyspace/util.go +++ b/pkg/keyspace/util.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/schedule/labeler" @@ -37,60 +38,6 @@ const ( ) var ( - // ErrKeyspaceNotFound is used to indicate target keyspace does not exist. - ErrKeyspaceNotFound = errors.New("keyspace does not exist") - // ErrRegionSplitTimeout indices to split region timeout - ErrRegionSplitTimeout = errors.New("region split timeout") - // ErrRegionSplitFailed indices to split region failed - ErrRegionSplitFailed = errors.New("region split failed") - // ErrKeyspaceExists indicates target keyspace already exists. - // It's used when creating a new keyspace. - ErrKeyspaceExists = errors.New("keyspace already exists") - // ErrKeyspaceGroupExists indicates target keyspace group already exists. - ErrKeyspaceGroupExists = errors.New("keyspace group already exists") - // ErrKeyspaceGroupNotExists is used to indicate target keyspace group does not exist. - ErrKeyspaceGroupNotExists = func(groupID uint32) error { - return errors.Errorf("keyspace group %v does not exist", groupID) - } - // ErrKeyspaceGroupInSplit is used to indicate target keyspace group is in split state. - ErrKeyspaceGroupInSplit = func(groupID uint32) error { - return errors.Errorf("keyspace group %v is in split state", groupID) - } - // ErrKeyspaceGroupNotInSplit is used to indicate target keyspace group is not in split state. - ErrKeyspaceGroupNotInSplit = func(groupID uint32) error { - return errors.Errorf("keyspace group %v is not in split state", groupID) - } - // ErrKeyspaceGroupInMerging is used to indicate target keyspace group is in merging state. - ErrKeyspaceGroupInMerging = func(groupID uint32) error { - return errors.Errorf("keyspace group %v is in merging state", groupID) - } - // ErrKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state. - ErrKeyspaceGroupNotInMerging = func(groupID uint32) error { - return errors.Errorf("keyspace group %v is not in merging state", groupID) - } - // ErrKeyspaceNotInKeyspaceGroup is used to indicate target keyspace is not in this keyspace group. - ErrKeyspaceNotInKeyspaceGroup = errors.New("keyspace is not in this keyspace group") - // ErrKeyspaceNotInAnyKeyspaceGroup is used to indicate target keyspace is not in any keyspace group. - ErrKeyspaceNotInAnyKeyspaceGroup = errors.New("keyspace is not in any keyspace group") - // ErrNodeNotInKeyspaceGroup is used to indicate the tso node is not in this keyspace group. - ErrNodeNotInKeyspaceGroup = errors.New("the tso node is not in this keyspace group") - // ErrKeyspaceGroupNotEnoughReplicas is used to indicate not enough replicas in the keyspace group. - ErrKeyspaceGroupNotEnoughReplicas = errors.New("not enough replicas in the keyspace group") - // ErrKeyspaceGroupWithEmptyKeyspace is used to indicate keyspace group with empty keyspace. - ErrKeyspaceGroupWithEmptyKeyspace = errors.New("keyspace group with empty keyspace") - // ErrModifyDefaultKeyspaceGroup is used to indicate that default keyspace group cannot be modified. - ErrModifyDefaultKeyspaceGroup = errors.New("default keyspace group cannot be modified") - // ErrNoAvailableNode is used to indicate no available node in the keyspace group. - ErrNoAvailableNode = errors.New("no available node") - // ErrExceedMaxEtcdTxnOps is used to indicate the number of etcd txn operations exceeds the limit. - ErrExceedMaxEtcdTxnOps = errors.New("exceed max etcd txn operations") - // ErrModifyDefaultKeyspace is used to indicate that default keyspace cannot be modified. - ErrModifyDefaultKeyspace = errors.New("cannot modify default keyspace's state") - errIllegalOperation = errors.New("unknown operation") - - // ErrUnsupportedOperationInKeyspace is used to indicate this is an unsupported operation. - ErrUnsupportedOperationInKeyspace = errors.New("it's a unsupported operation") - // stateTransitionTable lists all allowed next state for the given current state. // Note that transit from any state to itself is allowed for idempotence. stateTransitionTable = map[keyspacepb.KeyspaceState][]keyspacepb.KeyspaceState{ @@ -101,9 +48,6 @@ var ( } // Only keyspaces in the state specified by allowChangeConfig are allowed to change their config. allowChangeConfig = []keyspacepb.KeyspaceState{keyspacepb.KeyspaceState_ENABLED, keyspacepb.KeyspaceState_DISABLED} - - // ErrKeyspaceGroupPrimaryNotFound is used to indicate primary of target keyspace group does not exist. - ErrKeyspaceGroupPrimaryNotFound = errors.New("primary of keyspace group does not exist") ) // validateID check if keyspace falls within the acceptable range. diff --git a/pkg/keyspace/util_test.go b/pkg/keyspace/util_test.go index ab544b21a5d..f938904c709 100644 --- a/pkg/keyspace/util_test.go +++ b/pkg/keyspace/util_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/schedule/labeler" diff --git a/pkg/mcs/discovery/discover.go b/pkg/mcs/discovery/discover.go index d4234df893d..f46c72495c6 100644 --- a/pkg/mcs/discovery/discover.go +++ b/pkg/mcs/discovery/discover.go @@ -15,15 +15,17 @@ package discovery import ( + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Discover is used to get all the service instances of the specified service name. diff --git a/pkg/mcs/discovery/discover_test.go b/pkg/mcs/discovery/discover_test.go index fd66ddcad18..81af0d524b7 100644 --- a/pkg/mcs/discovery/discover_test.go +++ b/pkg/mcs/discovery/discover_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/etcdutil" ) diff --git a/pkg/mcs/discovery/register.go b/pkg/mcs/discovery/register.go index 5ab0ceabfce..e62239a4694 100644 --- a/pkg/mcs/discovery/register.go +++ b/pkg/mcs/discovery/register.go @@ -19,12 +19,14 @@ import ( "fmt" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // DefaultLeaseInSeconds is the default lease time in seconds. diff --git a/pkg/mcs/discovery/register_test.go b/pkg/mcs/discovery/register_test.go index bdaf7e379a4..b03543f624e 100644 --- a/pkg/mcs/discovery/register_test.go +++ b/pkg/mcs/discovery/register_test.go @@ -22,10 +22,11 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/etcdutil" - "github.com/tikv/pd/pkg/utils/testutil" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/embed" + + "github.com/tikv/pd/pkg/utils/etcdutil" + "github.com/tikv/pd/pkg/utils/testutil" ) func TestRegister(t *testing.T) { diff --git a/pkg/mcs/discovery/registry_entry.go b/pkg/mcs/discovery/registry_entry.go index db4ac44a2cc..887a8eb7aea 100644 --- a/pkg/mcs/discovery/registry_entry.go +++ b/pkg/mcs/discovery/registry_entry.go @@ -17,8 +17,9 @@ package discovery import ( "encoding/json" - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) // ServiceRegistryEntry is the registry entry of a service diff --git a/pkg/mcs/metastorage/server/grpc_service.go b/pkg/mcs/metastorage/server/grpc_service.go index 32b3788906d..00f4efb56fd 100644 --- a/pkg/mcs/metastorage/server/grpc_service.go +++ b/pkg/mcs/metastorage/server/grpc_service.go @@ -19,17 +19,19 @@ import ( "fmt" "net/http" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/kvproto/pkg/meta_storagepb" "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/mcs/registry" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) var ( diff --git a/pkg/mcs/metastorage/server/manager.go b/pkg/mcs/metastorage/server/manager.go index 49fc58c6b7d..0c03e4c7d03 100644 --- a/pkg/mcs/metastorage/server/manager.go +++ b/pkg/mcs/metastorage/server/manager.go @@ -15,12 +15,14 @@ package server import ( + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Manager is the manager of resource group. diff --git a/pkg/mcs/registry/registry.go b/pkg/mcs/registry/registry.go index c6470b34dc4..6a01f091e52 100644 --- a/pkg/mcs/registry/registry.go +++ b/pkg/mcs/registry/registry.go @@ -20,10 +20,12 @@ import ( "fmt" "net/http" - "github.com/pingcap/log" - bs "github.com/tikv/pd/pkg/basicserver" "go.uber.org/zap" "google.golang.org/grpc" + + "github.com/pingcap/log" + + bs "github.com/tikv/pd/pkg/basicserver" ) var ( diff --git a/pkg/mcs/resourcemanager/server/apis/v1/api.go b/pkg/mcs/resourcemanager/server/apis/v1/api.go index 891072e898f..e142dbbc69a 100644 --- a/pkg/mcs/resourcemanager/server/apis/v1/api.go +++ b/pkg/mcs/resourcemanager/server/apis/v1/api.go @@ -25,7 +25,9 @@ import ( "github.com/gin-contrib/gzip" "github.com/gin-contrib/pprof" "github.com/gin-gonic/gin" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" + rmserver "github.com/tikv/pd/pkg/mcs/resourcemanager/server" "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/utils/apiutil" diff --git a/pkg/mcs/resourcemanager/server/config.go b/pkg/mcs/resourcemanager/server/config.go index 360f3b169b9..415a87d5e79 100644 --- a/pkg/mcs/resourcemanager/server/config.go +++ b/pkg/mcs/resourcemanager/server/config.go @@ -22,16 +22,18 @@ import ( "time" "github.com/BurntSushi/toml" + "github.com/spf13/pflag" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" - "github.com/spf13/pflag" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/configutil" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/metricutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/mcs/resourcemanager/server/config_test.go b/pkg/mcs/resourcemanager/server/config_test.go index ae9dfc2cad3..afe22356def 100644 --- a/pkg/mcs/resourcemanager/server/config_test.go +++ b/pkg/mcs/resourcemanager/server/config_test.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. diff --git a/pkg/mcs/resourcemanager/server/grpc_service.go b/pkg/mcs/resourcemanager/server/grpc_service.go index 21681bc0759..6c0d7ce0120 100644 --- a/pkg/mcs/resourcemanager/server/grpc_service.go +++ b/pkg/mcs/resourcemanager/server/grpc_service.go @@ -20,17 +20,19 @@ import ( "net/http" "time" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/mcs/registry" "github.com/tikv/pd/pkg/utils/apiutil" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) var ( diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 7f7e710b3fb..2ccfd44c418 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -23,11 +23,14 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/endpoint" @@ -35,7 +38,6 @@ import ( "github.com/tikv/pd/pkg/utils/jsonutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/mcs/resourcemanager/server/metrics_test.go b/pkg/mcs/resourcemanager/server/metrics_test.go index d69d364b64b..4c3ec7ce5ef 100644 --- a/pkg/mcs/resourcemanager/server/metrics_test.go +++ b/pkg/mcs/resourcemanager/server/metrics_test.go @@ -18,8 +18,9 @@ import ( "fmt" "testing" - rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/stretchr/testify/require" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" ) func TestMaxPerSecCostTracker(t *testing.T) { diff --git a/pkg/mcs/resourcemanager/server/resource_group.go b/pkg/mcs/resourcemanager/server/resource_group.go index 6a5d06da6f7..65d2959e870 100644 --- a/pkg/mcs/resourcemanager/server/resource_group.go +++ b/pkg/mcs/resourcemanager/server/resource_group.go @@ -20,12 +20,14 @@ import ( "time" "github.com/gogo/protobuf/proto" + "go.uber.org/zap" + "github.com/pingcap/errors" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) // ResourceGroup is the definition of a resource group, for REST API. diff --git a/pkg/mcs/resourcemanager/server/resource_group_test.go b/pkg/mcs/resourcemanager/server/resource_group_test.go index 96b15d14293..8f058a212bb 100644 --- a/pkg/mcs/resourcemanager/server/resource_group_test.go +++ b/pkg/mcs/resourcemanager/server/resource_group_test.go @@ -5,8 +5,9 @@ import ( "testing" "github.com/brianvoe/gofakeit/v6" - rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/stretchr/testify/require" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" ) func TestPatchResourceGroup(t *testing.T) { diff --git a/pkg/mcs/resourcemanager/server/token_buckets.go b/pkg/mcs/resourcemanager/server/token_buckets.go index e0777b419eb..50dc78c9d68 100644 --- a/pkg/mcs/resourcemanager/server/token_buckets.go +++ b/pkg/mcs/resourcemanager/server/token_buckets.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -19,9 +19,10 @@ import ( "time" "github.com/gogo/protobuf/proto" + "go.uber.org/zap" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/pingcap/log" - "go.uber.org/zap" ) const ( diff --git a/pkg/mcs/resourcemanager/server/token_buckets_test.go b/pkg/mcs/resourcemanager/server/token_buckets_test.go index 8ac3ec4a3ba..b56ccb6ab96 100644 --- a/pkg/mcs/resourcemanager/server/token_buckets_test.go +++ b/pkg/mcs/resourcemanager/server/token_buckets_test.go @@ -7,7 +7,7 @@ // 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,g +// distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. @@ -20,8 +20,9 @@ import ( "testing" "time" - rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/stretchr/testify/require" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" ) func TestGroupTokenBucketUpdateAndPatch(t *testing.T) { diff --git a/pkg/mcs/scheduling/server/apis/v1/api.go b/pkg/mcs/scheduling/server/apis/v1/api.go index c374456a6eb..3d2d0005a24 100644 --- a/pkg/mcs/scheduling/server/apis/v1/api.go +++ b/pkg/mcs/scheduling/server/apis/v1/api.go @@ -27,8 +27,11 @@ import ( "github.com/gin-contrib/gzip" "github.com/gin-contrib/pprof" "github.com/gin-gonic/gin" + "github.com/unrolled/render" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" scheserver "github.com/tikv/pd/pkg/mcs/scheduling/server" mcsutils "github.com/tikv/pd/pkg/mcs/utils" @@ -44,7 +47,6 @@ import ( "github.com/tikv/pd/pkg/utils/apiutil/multiservicesapi" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/typeutil" - "github.com/unrolled/render" ) // APIPathPrefix is the prefix of the API path. diff --git a/pkg/mcs/scheduling/server/cluster.go b/pkg/mcs/scheduling/server/cluster.go index e4949446da9..20e5acca379 100644 --- a/pkg/mcs/scheduling/server/cluster.go +++ b/pkg/mcs/scheduling/server/cluster.go @@ -7,12 +7,15 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/schedulingpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cluster" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" @@ -35,7 +38,6 @@ import ( "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // Cluster is used to manage all information for scheduling purpose. diff --git a/pkg/mcs/scheduling/server/config/config.go b/pkg/mcs/scheduling/server/config/config.go index 45a606720a0..784d1f45a82 100644 --- a/pkg/mcs/scheduling/server/config/config.go +++ b/pkg/mcs/scheduling/server/config/config.go @@ -27,10 +27,13 @@ import ( "github.com/BurntSushi/toml" "github.com/coreos/go-semver/semver" + "github.com/spf13/pflag" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" - "github.com/spf13/pflag" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" @@ -43,7 +46,6 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/metricutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/mcs/scheduling/server/config/watcher.go b/pkg/mcs/scheduling/server/config/watcher.go index f0af61c9dd2..f499a0d7d50 100644 --- a/pkg/mcs/scheduling/server/config/watcher.go +++ b/pkg/mcs/scheduling/server/config/watcher.go @@ -23,15 +23,17 @@ import ( "time" "github.com/coreos/go-semver/semver" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/schedulers" "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Watcher is used to watch the PD API server for any configuration changes. diff --git a/pkg/mcs/scheduling/server/grpc_service.go b/pkg/mcs/scheduling/server/grpc_service.go index f4fe606b403..440b2d47d4f 100644 --- a/pkg/mcs/scheduling/server/grpc_service.go +++ b/pkg/mcs/scheduling/server/grpc_service.go @@ -21,10 +21,16 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/schedulingpb" "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" @@ -33,10 +39,6 @@ import ( "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // gRPC errors diff --git a/pkg/mcs/scheduling/server/meta/watcher.go b/pkg/mcs/scheduling/server/meta/watcher.go index 9d54a636b9e..27fe6687f3d 100644 --- a/pkg/mcs/scheduling/server/meta/watcher.go +++ b/pkg/mcs/scheduling/server/meta/watcher.go @@ -20,15 +20,17 @@ import ( "sync" "github.com/gogo/protobuf/proto" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/statistics" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Watcher is used to watch the PD API server for any meta changes. diff --git a/pkg/mcs/scheduling/server/rule/watcher.go b/pkg/mcs/scheduling/server/rule/watcher.go index 790dd9c2f81..cc6480a0cb4 100644 --- a/pkg/mcs/scheduling/server/rule/watcher.go +++ b/pkg/mcs/scheduling/server/rule/watcher.go @@ -19,7 +19,12 @@ import ( "strings" "sync" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/checker" "github.com/tikv/pd/pkg/schedule/labeler" @@ -27,9 +32,6 @@ import ( "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Watcher is used to watch the PD API server for any Placement Rule changes. diff --git a/pkg/mcs/scheduling/server/rule/watcher_test.go b/pkg/mcs/scheduling/server/rule/watcher_test.go index 40469eef2a8..5b3d49a53f1 100644 --- a/pkg/mcs/scheduling/server/rule/watcher_test.go +++ b/pkg/mcs/scheduling/server/rule/watcher_test.go @@ -24,14 +24,15 @@ import ( "time" "github.com/stretchr/testify/require" + clientv3 "go.etcd.io/etcd/client/v3" + "go.etcd.io/etcd/server/v3/embed" + "github.com/tikv/pd/pkg/keyspace" "github.com/tikv/pd/pkg/schedule/labeler" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/embed" ) const ( diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 31c8d307adb..8c9972d5eec 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -28,6 +28,10 @@ import ( "time" grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/spf13/cobra" + "go.uber.org/zap" + "google.golang.org/grpc" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/diagnosticspb" @@ -35,7 +39,7 @@ import ( "github.com/pingcap/kvproto/pkg/schedulingpb" "github.com/pingcap/log" "github.com/pingcap/sysutil" - "github.com/spf13/cobra" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" @@ -62,8 +66,6 @@ import ( "github.com/tikv/pd/pkg/utils/memberutil" "github.com/tikv/pd/pkg/utils/metricutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/zap" - "google.golang.org/grpc" ) var _ bs.Server = (*Server)(nil) diff --git a/pkg/mcs/scheduling/server/testutil.go b/pkg/mcs/scheduling/server/testutil.go index 312365c81ab..794a1bf520c 100644 --- a/pkg/mcs/scheduling/server/testutil.go +++ b/pkg/mcs/scheduling/server/testutil.go @@ -18,9 +18,11 @@ import ( "context" "os" - "github.com/pingcap/log" "github.com/spf13/pflag" "github.com/stretchr/testify/require" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/mcs/scheduling/server/config" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/testutil" diff --git a/pkg/mcs/server/server.go b/pkg/mcs/server/server.go index fef05a85012..9692b52beb3 100644 --- a/pkg/mcs/server/server.go +++ b/pkg/mcs/server/server.go @@ -23,11 +23,13 @@ import ( "sync" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "google.golang.org/grpc" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/grpcutil" - clientv3 "go.etcd.io/etcd/client/v3" - "google.golang.org/grpc" ) // BaseServer is a basic server that provides some common functionality. diff --git a/pkg/mcs/tso/server/apis/v1/api.go b/pkg/mcs/tso/server/apis/v1/api.go index ec8782eb522..d659c13edca 100644 --- a/pkg/mcs/tso/server/apis/v1/api.go +++ b/pkg/mcs/tso/server/apis/v1/api.go @@ -23,8 +23,12 @@ import ( "github.com/gin-contrib/gzip" "github.com/gin-contrib/pprof" "github.com/gin-gonic/gin" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" tsoserver "github.com/tikv/pd/pkg/mcs/tso/server" "github.com/tikv/pd/pkg/mcs/utils" @@ -34,8 +38,6 @@ import ( "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/apiutil/multiservicesapi" "github.com/tikv/pd/pkg/utils/logutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/mcs/tso/server/config.go b/pkg/mcs/tso/server/config.go index 0973042b912..f2ee3c36a7b 100644 --- a/pkg/mcs/tso/server/config.go +++ b/pkg/mcs/tso/server/config.go @@ -22,16 +22,18 @@ import ( "time" "github.com/BurntSushi/toml" + "github.com/spf13/pflag" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/spf13/pflag" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/tso" "github.com/tikv/pd/pkg/utils/configutil" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/metricutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( @@ -64,10 +66,7 @@ type Config struct { // the primary/leader again. Etcd only supports seconds TTL, so here is second too. LeaderLease int64 `toml:"lease" json:"lease"` - // EnableLocalTSO is used to enable the Local TSO Allocator feature, - // which allows the PD server to generate Local TSO for certain DC-level transactions. - // To make this feature meaningful, user has to set the "zone" label for the PD server - // to indicate which DC this PD belongs to. + // Deprecated EnableLocalTSO bool `toml:"enable-local-tso" json:"enable-local-tso"` // TSOSaveInterval is the interval to save timestamp. diff --git a/pkg/mcs/tso/server/config_test.go b/pkg/mcs/tso/server/config_test.go index 2bd27a67492..08686bd5208 100644 --- a/pkg/mcs/tso/server/config_test.go +++ b/pkg/mcs/tso/server/config_test.go @@ -21,6 +21,7 @@ import ( "github.com/BurntSushi/toml" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mcs/utils/constant" ) @@ -36,7 +37,6 @@ func TestConfigBasic(t *testing.T) { re.Equal(defaultBackendEndpoints, cfg.BackendEndpoints) re.Equal(defaultListenAddr, cfg.ListenAddr) re.Equal(constant.DefaultLeaderLease, cfg.LeaderLease) - re.False(cfg.EnableLocalTSO) re.True(cfg.EnableGRPCGateway) re.Equal(defaultTSOSaveInterval, cfg.TSOSaveInterval.Duration) re.Equal(defaultTSOUpdatePhysicalInterval, cfg.TSOUpdatePhysicalInterval.Duration) @@ -48,7 +48,6 @@ func TestConfigBasic(t *testing.T) { cfg.ListenAddr = "test-listen-addr" cfg.AdvertiseListenAddr = "test-advertise-listen-addr" cfg.LeaderLease = 123 - cfg.EnableLocalTSO = true cfg.TSOSaveInterval.Duration = time.Duration(10) * time.Second cfg.TSOUpdatePhysicalInterval.Duration = time.Duration(100) * time.Millisecond cfg.MaxResetTSGap.Duration = time.Duration(1) * time.Hour @@ -58,7 +57,6 @@ func TestConfigBasic(t *testing.T) { re.Equal("test-listen-addr", cfg.GetListenAddr()) re.Equal("test-advertise-listen-addr", cfg.GetAdvertiseListenAddr()) re.Equal(int64(123), cfg.GetLeaderLease()) - re.True(cfg.EnableLocalTSO) re.Equal(time.Duration(10)*time.Second, cfg.TSOSaveInterval.Duration) re.Equal(time.Duration(100)*time.Millisecond, cfg.TSOUpdatePhysicalInterval.Duration) re.Equal(time.Duration(1)*time.Hour, cfg.MaxResetTSGap.Duration) @@ -74,7 +72,6 @@ name = "tso-test-name" data-dir = "/var/lib/tso" enable-grpc-gateway = false lease = 123 -enable-local-tso = true tso-save-interval = "10s" tso-update-physical-interval = "100ms" max-gap-reset-ts = "1h" @@ -92,7 +89,6 @@ max-gap-reset-ts = "1h" re.Equal("test-advertise-listen-addr", cfg.GetAdvertiseListenAddr()) re.Equal("/var/lib/tso", cfg.DataDir) re.Equal(int64(123), cfg.GetLeaderLease()) - re.True(cfg.EnableLocalTSO) re.Equal(time.Duration(10)*time.Second, cfg.TSOSaveInterval.Duration) re.Equal(time.Duration(100)*time.Millisecond, cfg.TSOUpdatePhysicalInterval.Duration) re.Equal(time.Duration(1)*time.Hour, cfg.MaxResetTSGap.Duration) diff --git a/pkg/mcs/tso/server/grpc_service.go b/pkg/mcs/tso/server/grpc_service.go index 3419fd16221..59abed67213 100644 --- a/pkg/mcs/tso/server/grpc_service.go +++ b/pkg/mcs/tso/server/grpc_service.go @@ -21,16 +21,18 @@ import ( "strconv" "time" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/mcs/registry" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/keypath" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // gRPC errors diff --git a/pkg/mcs/tso/server/server.go b/pkg/mcs/tso/server/server.go index 04e81c2d48e..34f51573baf 100644 --- a/pkg/mcs/tso/server/server.go +++ b/pkg/mcs/tso/server/server.go @@ -27,12 +27,18 @@ import ( "time" grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus" + "github.com/spf13/cobra" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/diagnosticspb" "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" "github.com/pingcap/sysutil" - "github.com/spf13/cobra" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" @@ -49,10 +55,6 @@ import ( "github.com/tikv/pd/pkg/utils/metricutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) var _ bs.Server = (*Server)(nil) @@ -272,15 +274,6 @@ func (s *Server) GetTSOAllocatorManager(keyspaceGroupID uint32) (*tso.AllocatorM return s.keyspaceGroupManager.GetAllocatorManager(keyspaceGroupID) } -// IsLocalRequest checks if the forwarded host is the current host -func (*Server) IsLocalRequest(forwardedHost string) bool { - // TODO: Check if the forwarded host is the current host. - // The logic is depending on etcd service mode -- if the TSO service - // uses the embedded etcd, check against ClientUrls; otherwise check - // against the cluster membership. - return forwardedHost == "" -} - // ValidateInternalRequest checks if server is closed, which is used to validate // the gRPC communication between TSO servers internally. // TODO: Check if the sender is from the global TSO allocator diff --git a/pkg/mcs/tso/server/testutil.go b/pkg/mcs/tso/server/testutil.go index 5dcfd4759b9..5ffcac48edb 100644 --- a/pkg/mcs/tso/server/testutil.go +++ b/pkg/mcs/tso/server/testutil.go @@ -17,11 +17,12 @@ package server import ( "strings" - "github.com/pingcap/kvproto/pkg/tsopb" "github.com/spf13/pflag" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + "github.com/pingcap/kvproto/pkg/tsopb" ) // MustNewGrpcClient must create a new TSO grpc client. diff --git a/pkg/mcs/utils/expected_primary.go b/pkg/mcs/utils/expected_primary.go index c39345b004e..b8a317ed251 100644 --- a/pkg/mcs/utils/expected_primary.go +++ b/pkg/mcs/utils/expected_primary.go @@ -20,8 +20,12 @@ import ( "math/rand" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" @@ -29,8 +33,6 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // GetExpectedPrimaryFlag gets the expected primary flag. diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index 253c846d167..9e187b3a361 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -25,11 +25,19 @@ import ( "time" "github.com/gin-gonic/gin" - "github.com/pingcap/kvproto/pkg/diagnosticspb" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/soheilhy/cmux" + etcdtypes "go.etcd.io/etcd/client/pkg/v3/types" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" + + "github.com/pingcap/kvproto/pkg/diagnosticspb" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" "github.com/tikv/pd/pkg/mcs/utils/constant" @@ -40,15 +48,14 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/versioninfo" - etcdtypes "go.etcd.io/etcd/client/pkg/v3/types" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" ) // PromHandler is a handler to get prometheus metrics. func PromHandler() gin.HandlerFunc { + prometheus.DefaultRegisterer.Unregister(collectors.NewGoCollector()) + if err := prometheus.Register(collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.MetricsGC, collectors.MetricsMemory, collectors.MetricsScheduler))); err != nil { + log.Warn("go runtime collectors have already registered", errs.ZapError(err)) + } return func(c *gin.Context) { // register promhttp.HandlerOpts DisableCompression promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ diff --git a/pkg/member/member.go b/pkg/member/member.go index 04e55c1a647..8b388cdee6a 100644 --- a/pkg/member/member.go +++ b/pkg/member/member.go @@ -24,18 +24,20 @@ import ( "sync/atomic" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.etcd.io/etcd/server/v3/embed" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.etcd.io/etcd/server/v3/embed" - "go.uber.org/zap" ) const ( diff --git a/pkg/member/participant.go b/pkg/member/participant.go index f3399f5d900..5d9129bcad5 100644 --- a/pkg/member/participant.go +++ b/pkg/member/participant.go @@ -19,16 +19,18 @@ import ( "sync/atomic" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/schedulingpb" "github.com/pingcap/kvproto/pkg/tsopb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) type leadershipCheckFunc func(*election.Leadership) bool diff --git a/pkg/memory/meminfo.go b/pkg/memory/meminfo.go index 64505e2e5f3..7ed1afb579b 100644 --- a/pkg/memory/meminfo.go +++ b/pkg/memory/meminfo.go @@ -17,14 +17,16 @@ package memory import ( "time" + "github.com/shirou/gopsutil/v3/mem" + "go.uber.org/zap" + "golang.org/x/exp/constraints" + "github.com/pingcap/failpoint" "github.com/pingcap/log" "github.com/pingcap/sysutil" - "github.com/shirou/gopsutil/v3/mem" + "github.com/tikv/pd/pkg/cgroup" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" - "golang.org/x/exp/constraints" ) // MemTotal returns the total amount of RAM on this system diff --git a/pkg/mock/mockcluster/mockcluster.go b/pkg/mock/mockcluster/mockcluster.go index 5fe17e5e723..45d8e35a0bc 100644 --- a/pkg/mock/mockcluster/mockcluster.go +++ b/pkg/mock/mockcluster/mockcluster.go @@ -21,10 +21,12 @@ import ( "time" "github.com/docker/go-units" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" diff --git a/pkg/mock/mockhbstream/mockhbstream.go b/pkg/mock/mockhbstream/mockhbstream.go index ac8f246f86a..848f134c8a0 100644 --- a/pkg/mock/mockhbstream/mockhbstream.go +++ b/pkg/mock/mockhbstream/mockhbstream.go @@ -19,6 +19,7 @@ import ( "time" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/hbstream" ) diff --git a/pkg/mock/mockhbstream/mockhbstream_test.go b/pkg/mock/mockhbstream/mockhbstream_test.go index 87a39b028b9..e4ffe8a9b20 100644 --- a/pkg/mock/mockhbstream/mockhbstream_test.go +++ b/pkg/mock/mockhbstream/mockhbstream_test.go @@ -18,10 +18,12 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/eraftpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" "github.com/tikv/pd/pkg/schedule/hbstream" diff --git a/pkg/mock/mockserver/mockserver.go b/pkg/mock/mockserver/mockserver.go index d79d79ffa03..3ba2abfca3f 100644 --- a/pkg/mock/mockserver/mockserver.go +++ b/pkg/mock/mockserver/mockserver.go @@ -18,6 +18,7 @@ import ( "context" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/utils/grpcutil" diff --git a/pkg/ratelimit/controller_test.go b/pkg/ratelimit/controller_test.go index 5efa6ec1190..f42169c9902 100644 --- a/pkg/ratelimit/controller_test.go +++ b/pkg/ratelimit/controller_test.go @@ -21,8 +21,9 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/syncutil" "golang.org/x/time/rate" + + "github.com/tikv/pd/pkg/utils/syncutil" ) type changeAndResult struct { diff --git a/pkg/ratelimit/limiter.go b/pkg/ratelimit/limiter.go index e312066dc56..0fc3a4e6bd1 100644 --- a/pkg/ratelimit/limiter.go +++ b/pkg/ratelimit/limiter.go @@ -17,9 +17,10 @@ package ratelimit import ( "math" + "golang.org/x/time/rate" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/syncutil" - "golang.org/x/time/rate" ) // DoneFunc is done function. diff --git a/pkg/ratelimit/limiter_test.go b/pkg/ratelimit/limiter_test.go index 256f9ea9ab4..2bb967677bb 100644 --- a/pkg/ratelimit/limiter_test.go +++ b/pkg/ratelimit/limiter_test.go @@ -20,8 +20,9 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/syncutil" "golang.org/x/time/rate" + + "github.com/tikv/pd/pkg/utils/syncutil" ) type releaseUtil struct { diff --git a/pkg/ratelimit/ratelimiter.go b/pkg/ratelimit/ratelimiter.go index b88127915c9..1c2a6a0f7b0 100644 --- a/pkg/ratelimit/ratelimiter.go +++ b/pkg/ratelimit/ratelimiter.go @@ -18,8 +18,9 @@ import ( "context" "time" - "github.com/tikv/pd/pkg/utils/syncutil" "golang.org/x/time/rate" + + "github.com/tikv/pd/pkg/utils/syncutil" ) // RateLimiter is a rate limiter based on `golang.org/x/time/rate`. diff --git a/pkg/ratelimit/runner.go b/pkg/ratelimit/runner.go index 1d65ff6a568..2a121d17c00 100644 --- a/pkg/ratelimit/runner.go +++ b/pkg/ratelimit/runner.go @@ -16,13 +16,15 @@ package ratelimit import ( "context" - "errors" "sync" "time" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" "go.uber.org/zap" + + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" ) // RegionHeartbeatStageName is the name of the stage of the region heartbeat. @@ -57,9 +59,6 @@ type Task struct { retained bool } -// ErrMaxWaitingTasksExceeded is returned when the number of waiting tasks exceeds the maximum. -var ErrMaxWaitingTasksExceeded = errors.New("max waiting tasks exceeded") - type taskID struct { id uint64 name string @@ -216,12 +215,12 @@ func (cr *ConcurrentRunner) RunTask(id uint64, name string, f func(context.Conte maxWait := time.Since(cr.pendingTasks[0].submittedAt) if maxWait > cr.maxPendingDuration { runnerFailedTasks.WithLabelValues(cr.name, task.name).Inc() - return ErrMaxWaitingTasksExceeded + return errs.ErrMaxWaitingTasksExceeded } } if pendingTaskNum > maxPendingTaskNum { runnerFailedTasks.WithLabelValues(cr.name, task.name).Inc() - return ErrMaxWaitingTasksExceeded + return errs.ErrMaxWaitingTasksExceeded } } cr.pendingTasks = append(cr.pendingTasks, task) diff --git a/pkg/replication/replication_mode.go b/pkg/replication/replication_mode.go index cba83cf1ebb..856a68a9b09 100644 --- a/pkg/replication/replication_mode.go +++ b/pkg/replication/replication_mode.go @@ -24,9 +24,12 @@ import ( "sync" "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/pdpb" pb "github.com/pingcap/kvproto/pkg/replication_modepb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" @@ -35,7 +38,6 @@ import ( "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/server/config" - "go.uber.org/zap" ) const ( diff --git a/pkg/replication/replication_mode_test.go b/pkg/replication/replication_mode_test.go index 243d7f7d8f1..0a921bccf3a 100644 --- a/pkg/replication/replication_mode_test.go +++ b/pkg/replication/replication_mode_test.go @@ -22,9 +22,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/pdpb" pb "github.com/pingcap/kvproto/pkg/replication_modepb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/response/region.go b/pkg/response/region.go index 6db7f135ad8..b635780e4f2 100644 --- a/pkg/response/region.go +++ b/pkg/response/region.go @@ -18,9 +18,11 @@ import ( "context" "github.com/mailru/easyjson/jwriter" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/replication_modepb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/response/region_test.go b/pkg/response/region_test.go index de6daa2c2fe..8da4c739f79 100644 --- a/pkg/response/region_test.go +++ b/pkg/response/region_test.go @@ -18,9 +18,10 @@ import ( "encoding/json" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" ) func TestPeer(t *testing.T) { diff --git a/pkg/response/store.go b/pkg/response/store.go index 8bff1e75e42..25dc7fc2176 100644 --- a/pkg/response/store.go +++ b/pkg/response/store.go @@ -18,6 +18,7 @@ import ( "time" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sc "github.com/tikv/pd/pkg/schedule/config" diff --git a/pkg/schedule/checker/checker_controller.go b/pkg/schedule/checker/checker_controller.go index 49d097daea6..aa15ee03d6f 100644 --- a/pkg/schedule/checker/checker_controller.go +++ b/pkg/schedule/checker/checker_controller.go @@ -22,8 +22,11 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" @@ -34,7 +37,6 @@ import ( "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/utils/keyutil" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/checker/joint_state_checker.go b/pkg/schedule/checker/joint_state_checker.go index 2122044e64a..4dc3922906a 100644 --- a/pkg/schedule/checker/joint_state_checker.go +++ b/pkg/schedule/checker/joint_state_checker.go @@ -16,6 +16,7 @@ package checker import ( "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/schedule/checker/joint_state_checker_test.go b/pkg/schedule/checker/joint_state_checker_test.go index 1b9436b65fd..f649c737284 100644 --- a/pkg/schedule/checker/joint_state_checker_test.go +++ b/pkg/schedule/checker/joint_state_checker_test.go @@ -18,8 +18,10 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/checker/learner_checker.go b/pkg/schedule/checker/learner_checker.go index 8590904a760..6d830c39ad8 100644 --- a/pkg/schedule/checker/learner_checker.go +++ b/pkg/schedule/checker/learner_checker.go @@ -16,6 +16,7 @@ package checker import ( "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" diff --git a/pkg/schedule/checker/learner_checker_test.go b/pkg/schedule/checker/learner_checker_test.go index b5d994d4201..3a559b86958 100644 --- a/pkg/schedule/checker/learner_checker_test.go +++ b/pkg/schedule/checker/learner_checker_test.go @@ -18,8 +18,10 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/checker/merge_checker.go b/pkg/schedule/checker/merge_checker.go index bf7fe4f2496..571ee134da0 100644 --- a/pkg/schedule/checker/merge_checker.go +++ b/pkg/schedule/checker/merge_checker.go @@ -20,6 +20,7 @@ import ( "time" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" diff --git a/pkg/schedule/checker/merge_checker_test.go b/pkg/schedule/checker/merge_checker_test.go index 00aaafa2cfd..3737e6cc0c2 100644 --- a/pkg/schedule/checker/merge_checker_test.go +++ b/pkg/schedule/checker/merge_checker_test.go @@ -20,8 +20,11 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/suite" + "go.uber.org/goleak" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/mock/mockcluster" @@ -34,7 +37,6 @@ import ( "github.com/tikv/pd/pkg/utils/operatorutil" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/goleak" ) func TestMain(m *testing.M) { diff --git a/pkg/schedule/checker/priority_inspector_test.go b/pkg/schedule/checker/priority_inspector_test.go index 5a5d8079d93..6de76b5ccb1 100644 --- a/pkg/schedule/checker/priority_inspector_test.go +++ b/pkg/schedule/checker/priority_inspector_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" ) diff --git a/pkg/schedule/checker/replica_checker.go b/pkg/schedule/checker/replica_checker.go index fabee683c92..f1d6efe15ba 100644 --- a/pkg/schedule/checker/replica_checker.go +++ b/pkg/schedule/checker/replica_checker.go @@ -19,8 +19,11 @@ import ( "math/rand" "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" @@ -29,7 +32,6 @@ import ( sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/types" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/checker/replica_checker_test.go b/pkg/schedule/checker/replica_checker_test.go index da04fb6d768..3f0f6b67d8d 100644 --- a/pkg/schedule/checker/replica_checker_test.go +++ b/pkg/schedule/checker/replica_checker_test.go @@ -20,10 +20,12 @@ import ( "time" "github.com/docker/go-units" - "github.com/pingcap/kvproto/pkg/metapb" - "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/schedule/checker/replica_strategy.go b/pkg/schedule/checker/replica_strategy.go index ffb25f90ad5..3bf2c955af7 100644 --- a/pkg/schedule/checker/replica_strategy.go +++ b/pkg/schedule/checker/replica_strategy.go @@ -17,12 +17,14 @@ package checker import ( "math/rand" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/filter" - "go.uber.org/zap" ) // ReplicaStrategy collects some utilities to manipulate region peers. It diff --git a/pkg/schedule/checker/rule_checker.go b/pkg/schedule/checker/rule_checker.go index 2d06f84fdfe..7350d92cf58 100644 --- a/pkg/schedule/checker/rule_checker.go +++ b/pkg/schedule/checker/rule_checker.go @@ -16,14 +16,16 @@ package checker import ( "context" - "errors" "math" "math/rand" "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" @@ -35,20 +37,10 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/zap" ) const maxPendingListLen = 100000 -var ( - errNoStoreToAdd = errors.New("no store to add peer") - errNoStoreToReplace = errors.New("no store to replace peer") - errPeerCannotBeLeader = errors.New("peer cannot be leader") - errPeerCannotBeWitness = errors.New("peer cannot be witness") - errNoNewLeader = errors.New("no new leader") - errRegionNoLeader = errors.New("region no leader") -) - // RuleChecker fix/improve region by placement rules. type RuleChecker struct { PauseController @@ -101,7 +93,7 @@ func (c *RuleChecker) CheckWithFit(region *core.RegionInfo, fit *placement.Regio // skip no leader region if region.GetLeader() == nil { ruleCheckerRegionNoLeaderCounter.Inc() - log.Debug("fail to check region", zap.Uint64("region-id", region.GetID()), zap.Error(errRegionNoLeader)) + log.Debug("fail to check region", zap.Uint64("region-id", region.GetID()), errs.ZapError(errs.ErrRegionNoLeader)) return } @@ -228,7 +220,7 @@ func (c *RuleChecker) addRulePeer(region *core.RegionInfo, fit *placement.Region } } } - return nil, errNoStoreToAdd + return nil, errs.ErrNoStoreToAdd } peer := &metapb.Peer{StoreId: store, Role: rf.Rule.Role.MetaPeerRole(), IsWitness: isWitness} op, err := operator.CreateAddPeerOperator("add-rule-peer", c.cluster, region, peer, operator.OpReplica) @@ -260,7 +252,7 @@ func (c *RuleChecker) replaceUnexpectedRulePeer(region *core.RegionInfo, rf *pla if store == 0 { ruleCheckerNoStoreReplaceCounter.Inc() c.handleFilterState(region, filterByTempState) - return nil, errNoStoreToReplace + return nil, errs.ErrNoStoreToReplace } newPeer := &metapb.Peer{StoreId: store, Role: rf.Rule.Role.MetaPeerRole(), IsWitness: fastFailover} // pick the smallest leader store to avoid the Offline store be snapshot generator bottleneck. @@ -323,7 +315,7 @@ func (c *RuleChecker) fixLooseMatchPeer(region *core.RegionInfo, fit *placement. return operator.CreateTransferLeaderOperator("fix-leader-role", c.cluster, region, peer.GetStoreId(), []uint64{}, 0) } ruleCheckerNotAllowLeaderCounter.Inc() - return nil, errPeerCannotBeLeader + return nil, errs.ErrPeerCannotBeLeader } if region.GetLeader().GetId() == peer.GetId() && rf.Rule.Role == placement.Follower { ruleCheckerFixFollowerRoleCounter.Inc() @@ -333,14 +325,14 @@ func (c *RuleChecker) fixLooseMatchPeer(region *core.RegionInfo, fit *placement. } } ruleCheckerNoNewLeaderCounter.Inc() - return nil, errNoNewLeader + return nil, errs.ErrNoNewLeader } if core.IsVoter(peer) && rf.Rule.Role == placement.Learner { ruleCheckerDemoteVoterRoleCounter.Inc() return operator.CreateDemoteVoterOperator("fix-demote-voter", c.cluster, region, peer) } if region.GetLeader().GetId() == peer.GetId() && rf.Rule.IsWitness { - return nil, errPeerCannotBeWitness + return nil, errs.ErrPeerCannotBeWitness } if !core.IsWitness(peer) && rf.Rule.IsWitness && c.isWitnessEnabled() { c.switchWitnessCache.UpdateTTL(c.cluster.GetCheckerConfig().GetSwitchWitnessInterval()) diff --git a/pkg/schedule/checker/rule_checker_test.go b/pkg/schedule/checker/rule_checker_test.go index 5ac67122de1..0b37ed57e7e 100644 --- a/pkg/schedule/checker/rule_checker_test.go +++ b/pkg/schedule/checker/rule_checker_test.go @@ -17,16 +17,17 @@ package checker import ( "context" "fmt" - "strconv" "strings" "testing" "time" + "github.com/stretchr/testify/suite" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" diff --git a/pkg/schedule/checker/split_checker.go b/pkg/schedule/checker/split_checker.go index 3cc1664b6cc..91487949821 100644 --- a/pkg/schedule/checker/split_checker.go +++ b/pkg/schedule/checker/split_checker.go @@ -17,6 +17,7 @@ package checker import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" diff --git a/pkg/schedule/checker/split_checker_test.go b/pkg/schedule/checker/split_checker_test.go index 40357d2408c..be3cce84f0d 100644 --- a/pkg/schedule/checker/split_checker_test.go +++ b/pkg/schedule/checker/split_checker_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" "github.com/tikv/pd/pkg/schedule/labeler" diff --git a/pkg/schedule/config/config.go b/pkg/schedule/config/config.go index 5e8f2c587ac..f00cd8a943b 100644 --- a/pkg/schedule/config/config.go +++ b/pkg/schedule/config/config.go @@ -19,6 +19,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/configutil" diff --git a/pkg/schedule/config/config_provider.go b/pkg/schedule/config/config_provider.go index 5c1be1089e9..a18051ca38e 100644 --- a/pkg/schedule/config/config_provider.go +++ b/pkg/schedule/config/config_provider.go @@ -19,7 +19,9 @@ import ( "time" "github.com/coreos/go-semver/semver" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/schedule/types" diff --git a/pkg/schedule/config/store_config.go b/pkg/schedule/config/store_config.go index b7676311f3d..5575f0d9d56 100644 --- a/pkg/schedule/config/store_config.go +++ b/pkg/schedule/config/store_config.go @@ -18,10 +18,12 @@ import ( "encoding/json" "reflect" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) var ( @@ -172,7 +174,7 @@ func (c *StoreConfig) CheckRegionSize(size, mergeSize uint64) error { if regionSplitSize == 0 { return nil } - // the smallest of the split regions can not be merge again, so it's size should less merge size. + // the smallest of the split regions can not be merge again, so it's size should be less than merge size. if smallSize := size % regionSplitSize; smallSize <= mergeSize && smallSize != 0 { log.Debug("region size is too small", zap.Uint64("size", size), zap.Uint64("merge-size", mergeSize), zap.Uint64("small-size", smallSize)) return errs.ErrCheckerMergeAgain.FastGenByArgs("the smallest region of the split regions is less than max-merge-region-size, " + diff --git a/pkg/schedule/config/util_test.go b/pkg/schedule/config/util_test.go index 31ab3ccf2a6..bda6b9441ad 100644 --- a/pkg/schedule/config/util_test.go +++ b/pkg/schedule/config/util_test.go @@ -17,8 +17,9 @@ package config import ( "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" ) func TestValidateLabels(t *testing.T) { diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 739ca5c84b6..e792560cb37 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -20,9 +20,12 @@ import ( "sync" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule/checker" @@ -39,7 +42,6 @@ import ( "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/filter/candidates_test.go b/pkg/schedule/filter/candidates_test.go index fd03b42ace0..ce8be5ef72e 100644 --- a/pkg/schedule/filter/candidates_test.go +++ b/pkg/schedule/filter/candidates_test.go @@ -19,8 +19,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/plan" diff --git a/pkg/schedule/filter/counter_test.go b/pkg/schedule/filter/counter_test.go index 7c7acc5e9a5..74ff194c47a 100644 --- a/pkg/schedule/filter/counter_test.go +++ b/pkg/schedule/filter/counter_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/schedule/types" ) diff --git a/pkg/schedule/filter/filters.go b/pkg/schedule/filter/filters.go index 4ea59935109..efb27c3ec6d 100644 --- a/pkg/schedule/filter/filters.go +++ b/pkg/schedule/filter/filters.go @@ -17,8 +17,11 @@ package filter import ( "strconv" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" @@ -27,7 +30,6 @@ import ( "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) // SelectSourceStores selects stores that be selected as source store from the list. diff --git a/pkg/schedule/filter/filters_test.go b/pkg/schedule/filter/filters_test.go index f061a472d65..35ba2c33589 100644 --- a/pkg/schedule/filter/filters_test.go +++ b/pkg/schedule/filter/filters_test.go @@ -19,9 +19,11 @@ import ( "time" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" diff --git a/pkg/schedule/filter/healthy_test.go b/pkg/schedule/filter/healthy_test.go index 15588352554..dd5ab8e958d 100644 --- a/pkg/schedule/filter/healthy_test.go +++ b/pkg/schedule/filter/healthy_test.go @@ -18,9 +18,11 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/filter/region_filters_test.go b/pkg/schedule/filter/region_filters_test.go index a7dd1fa932a..ddd4141f8ba 100644 --- a/pkg/schedule/filter/region_filters_test.go +++ b/pkg/schedule/filter/region_filters_test.go @@ -19,9 +19,11 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/handler/handler.go b/pkg/schedule/handler/handler.go index a8540b4b5f4..042adf96611 100644 --- a/pkg/schedule/handler/handler.go +++ b/pkg/schedule/handler/handler.go @@ -23,11 +23,14 @@ import ( "strings" "time" + "go.uber.org/zap" + "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/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule" @@ -43,7 +46,6 @@ import ( "github.com/tikv/pd/pkg/statistics/buckets" "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/hbstream/heartbeat_streams.go b/pkg/schedule/hbstream/heartbeat_streams.go index ef0440a9f77..6637800e97f 100644 --- a/pkg/schedule/hbstream/heartbeat_streams.go +++ b/pkg/schedule/hbstream/heartbeat_streams.go @@ -20,17 +20,19 @@ import ( "sync" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/schedulingpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // Operation is detailed scheduling step of a region. diff --git a/pkg/schedule/labeler/labeler.go b/pkg/schedule/labeler/labeler.go index 7670ccdedd7..16a14068e68 100644 --- a/pkg/schedule/labeler/labeler.go +++ b/pkg/schedule/labeler/labeler.go @@ -19,7 +19,10 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule/rangelist" @@ -27,7 +30,6 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) // RegionLabeler is utility to label regions. diff --git a/pkg/schedule/labeler/labeler_test.go b/pkg/schedule/labeler/labeler_test.go index ebd57708e47..564542727ff 100644 --- a/pkg/schedule/labeler/labeler_test.go +++ b/pkg/schedule/labeler/labeler_test.go @@ -24,8 +24,10 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/storage/endpoint" diff --git a/pkg/schedule/labeler/rules.go b/pkg/schedule/labeler/rules.go index 39a420032d8..4f5d28a8034 100644 --- a/pkg/schedule/labeler/rules.go +++ b/pkg/schedule/labeler/rules.go @@ -23,10 +23,12 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" - "go.uber.org/zap" ) // RegionLabel is the label of a region. diff --git a/pkg/schedule/operator/builder.go b/pkg/schedule/operator/builder.go index 29b8aedf978..8fd2393da2e 100644 --- a/pkg/schedule/operator/builder.go +++ b/pkg/schedule/operator/builder.go @@ -20,6 +20,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/filter" diff --git a/pkg/schedule/operator/builder_test.go b/pkg/schedule/operator/builder_test.go index 5e9ff7f89bb..77224a82c15 100644 --- a/pkg/schedule/operator/builder_test.go +++ b/pkg/schedule/operator/builder_test.go @@ -18,9 +18,11 @@ import ( "context" "testing" + "github.com/stretchr/testify/suite" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/operator/create_operator.go b/pkg/schedule/operator/create_operator.go index 4fae7f9e3f2..2558ca8d75b 100644 --- a/pkg/schedule/operator/create_operator.go +++ b/pkg/schedule/operator/create_operator.go @@ -18,16 +18,18 @@ import ( "fmt" "math/rand" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // CreateAddPeerOperator creates an operator that adds a new peer. diff --git a/pkg/schedule/operator/create_operator_test.go b/pkg/schedule/operator/create_operator_test.go index 845255e713c..0143b1b8011 100644 --- a/pkg/schedule/operator/create_operator_test.go +++ b/pkg/schedule/operator/create_operator_test.go @@ -19,11 +19,13 @@ import ( "encoding/hex" "testing" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/operator/metrics.go b/pkg/schedule/operator/metrics.go index 47a165500e9..25de41f0fb7 100644 --- a/pkg/schedule/operator/metrics.go +++ b/pkg/schedule/operator/metrics.go @@ -16,6 +16,7 @@ package operator import ( "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/pkg/schedule/types" ) diff --git a/pkg/schedule/operator/operator.go b/pkg/schedule/operator/operator.go index 8abeae54f6b..69b2504755e 100644 --- a/pkg/schedule/operator/operator.go +++ b/pkg/schedule/operator/operator.go @@ -22,8 +22,10 @@ import ( "sync/atomic" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/prometheus/client_golang/prometheus" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" ) diff --git a/pkg/schedule/operator/operator_controller.go b/pkg/schedule/operator/operator_controller.go index 0478ef2b6ae..cd2470376e1 100644 --- a/pkg/schedule/operator/operator_controller.go +++ b/pkg/schedule/operator/operator_controller.go @@ -21,9 +21,12 @@ import ( "sync" "time" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" @@ -33,7 +36,6 @@ import ( "github.com/tikv/pd/pkg/schedule/hbstream" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/versioninfo" - "go.uber.org/zap" ) // The source of dispatched region. diff --git a/pkg/schedule/operator/operator_controller_test.go b/pkg/schedule/operator/operator_controller_test.go index 69600f80536..3c9abe54f24 100644 --- a/pkg/schedule/operator/operator_controller_test.go +++ b/pkg/schedule/operator/operator_controller_test.go @@ -22,11 +22,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/schedule/operator/operator_test.go b/pkg/schedule/operator/operator_test.go index 22a86c789fc..6976b5ca12e 100644 --- a/pkg/schedule/operator/operator_test.go +++ b/pkg/schedule/operator/operator_test.go @@ -22,9 +22,11 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" diff --git a/pkg/schedule/operator/step.go b/pkg/schedule/operator/step.go index 04e41028865..6b0f0f1021f 100644 --- a/pkg/schedule/operator/step.go +++ b/pkg/schedule/operator/step.go @@ -20,17 +20,19 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/eraftpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/hbstream" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/operator/step_test.go b/pkg/schedule/operator/step_test.go index 014703d00f9..f6323a6d23c 100644 --- a/pkg/schedule/operator/step_test.go +++ b/pkg/schedule/operator/step_test.go @@ -18,9 +18,11 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/operator/test_util.go b/pkg/schedule/operator/test_util.go index 8206189daa6..f86701792dd 100644 --- a/pkg/schedule/operator/test_util.go +++ b/pkg/schedule/operator/test_util.go @@ -16,6 +16,7 @@ package operator import ( "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" ) diff --git a/pkg/schedule/operator/waiting_operator_test.go b/pkg/schedule/operator/waiting_operator_test.go index 8a0d1875cd7..a2e333231b0 100644 --- a/pkg/schedule/operator/waiting_operator_test.go +++ b/pkg/schedule/operator/waiting_operator_test.go @@ -17,8 +17,10 @@ package operator import ( "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core/constant" ) diff --git a/pkg/schedule/placement/fit.go b/pkg/schedule/placement/fit.go index 30530462664..bb1d642900b 100644 --- a/pkg/schedule/placement/fit.go +++ b/pkg/schedule/placement/fit.go @@ -20,6 +20,7 @@ import ( "sort" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/placement/fit_region_test.go b/pkg/schedule/placement/fit_region_test.go index 284674b79a2..9c6e7b7faf1 100644 --- a/pkg/schedule/placement/fit_region_test.go +++ b/pkg/schedule/placement/fit_region_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/placement/fit_test.go b/pkg/schedule/placement/fit_test.go index b12bcd7451a..f22661ba694 100644 --- a/pkg/schedule/placement/fit_test.go +++ b/pkg/schedule/placement/fit_test.go @@ -21,9 +21,11 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/placement/label_constraint_test.go b/pkg/schedule/placement/label_constraint_test.go index e65676f0a5e..cd2ff5976df 100644 --- a/pkg/schedule/placement/label_constraint_test.go +++ b/pkg/schedule/placement/label_constraint_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/placement/region_rule_cache.go b/pkg/schedule/placement/region_rule_cache.go index 79e52a49fca..4b17c3baf70 100644 --- a/pkg/schedule/placement/region_rule_cache.go +++ b/pkg/schedule/placement/region_rule_cache.go @@ -16,6 +16,7 @@ package placement import ( "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/utils/syncutil" diff --git a/pkg/schedule/placement/region_rule_cache_test.go b/pkg/schedule/placement/region_rule_cache_test.go index e951ea10cc5..c526a095e7b 100644 --- a/pkg/schedule/placement/region_rule_cache_test.go +++ b/pkg/schedule/placement/region_rule_cache_test.go @@ -19,9 +19,11 @@ import ( "time" "unsafe" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/placement/rule_list.go b/pkg/schedule/placement/rule_list.go index f5ee0dada0e..3fc401163d1 100644 --- a/pkg/schedule/placement/rule_list.go +++ b/pkg/schedule/placement/rule_list.go @@ -20,6 +20,7 @@ import ( "strings" "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule/rangelist" ) diff --git a/pkg/schedule/placement/rule_manager.go b/pkg/schedule/placement/rule_manager.go index f44258d797c..f5101f0250c 100644 --- a/pkg/schedule/placement/rule_manager.go +++ b/pkg/schedule/placement/rule_manager.go @@ -24,8 +24,12 @@ import ( "sort" "strings" + "go.uber.org/zap" + "golang.org/x/exp/slices" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" @@ -35,8 +39,6 @@ import ( "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" - "golang.org/x/exp/slices" ) const ( diff --git a/pkg/schedule/placement/rule_manager_test.go b/pkg/schedule/placement/rule_manager_test.go index 2e1883640d8..5f5f457da13 100644 --- a/pkg/schedule/placement/rule_manager_test.go +++ b/pkg/schedule/placement/rule_manager_test.go @@ -19,8 +19,10 @@ import ( "encoding/hex" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" diff --git a/pkg/schedule/plan/balance_plan_test.go b/pkg/schedule/plan/balance_plan_test.go index 59f2acc689a..8bdc2519a90 100644 --- a/pkg/schedule/plan/balance_plan_test.go +++ b/pkg/schedule/plan/balance_plan_test.go @@ -18,8 +18,10 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/plugin_interface.go b/pkg/schedule/plugin_interface.go index 62ffe2eb900..8870ca7f46d 100644 --- a/pkg/schedule/plugin_interface.go +++ b/pkg/schedule/plugin_interface.go @@ -18,10 +18,12 @@ import ( "path/filepath" "plugin" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) // PluginInterface is used to manage all plugin. diff --git a/pkg/schedule/prepare_checker.go b/pkg/schedule/prepare_checker.go index 187d68e3d9f..5f6b54f33ae 100644 --- a/pkg/schedule/prepare_checker.go +++ b/pkg/schedule/prepare_checker.go @@ -17,10 +17,12 @@ package schedule import ( "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) type prepareChecker struct { diff --git a/pkg/schedule/scatter/region_scatterer.go b/pkg/schedule/scatter/region_scatterer.go index 71b2cd346c7..0e4dd43ecb2 100644 --- a/pkg/schedule/scatter/region_scatterer.go +++ b/pkg/schedule/scatter/region_scatterer.go @@ -22,10 +22,13 @@ import ( "sync" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/cache" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" @@ -36,7 +39,6 @@ import ( "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const regionScatterName = "region-scatter" @@ -53,8 +55,6 @@ var ( scatterUnnecessaryCounter = scatterCounter.WithLabelValues("unnecessary", "") scatterFailCounter = scatterCounter.WithLabelValues("fail", "") scatterSuccessCounter = scatterCounter.WithLabelValues("success", "") - errRegionNotFound = errors.New("region not found") - errEmptyRegion = errors.New("empty region") ) const ( @@ -167,7 +167,7 @@ func (r *RegionScatterer) ScatterRegionsByRange(startKey, endKey []byte, group s regions := r.cluster.ScanRegions(startKey, endKey, -1) if len(regions) < 1 { scatterSkipEmptyRegionCounter.Inc() - return 0, nil, errEmptyRegion + return 0, nil, errs.ErrEmptyRegion } failures := make(map[uint64]error, len(regions)) regionMap := make(map[uint64]*core.RegionInfo, len(regions)) @@ -186,13 +186,13 @@ func (r *RegionScatterer) ScatterRegionsByRange(startKey, endKey []byte, group s func (r *RegionScatterer) ScatterRegionsByID(regionsID []uint64, group string, retryLimit int, skipStoreLimit bool) (int, map[uint64]error, error) { if len(regionsID) < 1 { scatterSkipEmptyRegionCounter.Inc() - return 0, nil, errEmptyRegion + return 0, nil, errs.ErrEmptyRegion } if len(regionsID) == 1 { region := r.cluster.GetRegion(regionsID[0]) if region == nil { scatterSkipNoRegionCounter.Inc() - return 0, nil, errRegionNotFound + return 0, nil, errs.ErrRegionNotFound } } failures := make(map[uint64]error, len(regionsID)) @@ -228,7 +228,7 @@ func (r *RegionScatterer) ScatterRegionsByID(regionsID []uint64, group string, r func (r *RegionScatterer) scatterRegions(regions map[uint64]*core.RegionInfo, failures map[uint64]error, group string, retryLimit int, skipStoreLimit bool) (int, error) { if len(regions) < 1 { scatterSkipEmptyRegionCounter.Inc() - return 0, errEmptyRegion + return 0, errs.ErrEmptyRegion } if retryLimit > maxRetryLimit { retryLimit = maxRetryLimit diff --git a/pkg/schedule/scatter/region_scatterer_test.go b/pkg/schedule/scatter/region_scatterer_test.go index fdaed888309..b86d73d4288 100644 --- a/pkg/schedule/scatter/region_scatterer_test.go +++ b/pkg/schedule/scatter/region_scatterer_test.go @@ -23,9 +23,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/schedule/schedulers/balance_benchmark_test.go b/pkg/schedule/schedulers/balance_benchmark_test.go index aaafa7be8ca..abf4c0b3def 100644 --- a/pkg/schedule/schedulers/balance_benchmark_test.go +++ b/pkg/schedule/schedulers/balance_benchmark_test.go @@ -18,8 +18,10 @@ import ( "fmt" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/assert" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/balance_leader.go b/pkg/schedule/schedulers/balance_leader.go index 03f02002c74..2884e8a486f 100644 --- a/pkg/schedule/schedulers/balance_leader.go +++ b/pkg/schedule/schedulers/balance_leader.go @@ -23,7 +23,11 @@ import ( "strconv" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -34,8 +38,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/reflectutil" "github.com/tikv/pd/pkg/utils/typeutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/balance_leader_test.go b/pkg/schedule/schedulers/balance_leader_test.go index 940f75f78bc..36a4ee52ea6 100644 --- a/pkg/schedule/schedulers/balance_leader_test.go +++ b/pkg/schedule/schedulers/balance_leader_test.go @@ -22,9 +22,11 @@ import ( "testing" "github.com/docker/go-units" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/schedule/schedulers/balance_region.go b/pkg/schedule/schedulers/balance_region.go index 2bee521364d..6ad95201f68 100644 --- a/pkg/schedule/schedulers/balance_region.go +++ b/pkg/schedule/schedulers/balance_region.go @@ -18,8 +18,11 @@ import ( "sort" "strconv" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sche "github.com/tikv/pd/pkg/schedule/core" @@ -27,7 +30,6 @@ import ( "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/schedule/types" - "go.uber.org/zap" ) type balanceRegionSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/balance_region_test.go b/pkg/schedule/schedulers/balance_region_test.go index 48a4959a170..aa8e7fc30d1 100644 --- a/pkg/schedule/schedulers/balance_region_test.go +++ b/pkg/schedule/schedulers/balance_region_test.go @@ -18,8 +18,10 @@ import ( "fmt" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/schedule/schedulers/balance_witness.go b/pkg/schedule/schedulers/balance_witness.go index cfcafb56c57..1b23e5b4a19 100644 --- a/pkg/schedule/schedulers/balance_witness.go +++ b/pkg/schedule/schedulers/balance_witness.go @@ -23,8 +23,12 @@ import ( "strconv" "github.com/gorilla/mux" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" + "github.com/unrolled/render" + "go.uber.org/zap" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -35,8 +39,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/reflectutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/balance_witness_test.go b/pkg/schedule/schedulers/balance_witness_test.go index b1449821236..a7edbd3ea94 100644 --- a/pkg/schedule/schedulers/balance_witness_test.go +++ b/pkg/schedule/schedulers/balance_witness_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/base_scheduler.go b/pkg/schedule/schedulers/base_scheduler.go index ef5c6bf7ae7..2534ed12281 100644 --- a/pkg/schedule/schedulers/base_scheduler.go +++ b/pkg/schedule/schedulers/base_scheduler.go @@ -21,6 +21,7 @@ import ( "time" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/config.go b/pkg/schedule/schedulers/config.go index 78b123981fd..e172b596685 100644 --- a/pkg/schedule/schedulers/config.go +++ b/pkg/schedule/schedulers/config.go @@ -15,13 +15,15 @@ package schedulers import ( + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) type schedulerConfig interface { diff --git a/pkg/schedule/schedulers/config_test.go b/pkg/schedule/schedulers/config_test.go index 9e20521854f..f97a2ad17ea 100644 --- a/pkg/schedule/schedulers/config_test.go +++ b/pkg/schedule/schedulers/config_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/storage" ) diff --git a/pkg/schedule/schedulers/evict_leader.go b/pkg/schedule/schedulers/evict_leader.go index defc65846ae..45285b51137 100644 --- a/pkg/schedule/schedulers/evict_leader.go +++ b/pkg/schedule/schedulers/evict_leader.go @@ -20,8 +20,12 @@ import ( "strconv" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -32,8 +36,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/evict_leader_test.go b/pkg/schedule/schedulers/evict_leader_test.go index ecd80813c0f..587a48358e9 100644 --- a/pkg/schedule/schedulers/evict_leader_test.go +++ b/pkg/schedule/schedulers/evict_leader_test.go @@ -18,9 +18,11 @@ import ( "bytes" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/types" diff --git a/pkg/schedule/schedulers/evict_slow_store.go b/pkg/schedule/schedulers/evict_slow_store.go index b1960ceca8e..8d8c014b110 100644 --- a/pkg/schedule/schedulers/evict_slow_store.go +++ b/pkg/schedule/schedulers/evict_slow_store.go @@ -19,9 +19,13 @@ import ( "time" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sche "github.com/tikv/pd/pkg/schedule/core" @@ -29,8 +33,6 @@ import ( "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/apiutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/evict_slow_store_test.go b/pkg/schedule/schedulers/evict_slow_store_test.go index 79651fb5b5c..636d856fc14 100644 --- a/pkg/schedule/schedulers/evict_slow_store_test.go +++ b/pkg/schedule/schedulers/evict_slow_store_test.go @@ -18,8 +18,10 @@ import ( "context" "testing" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/suite" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/evict_slow_trend.go b/pkg/schedule/schedulers/evict_slow_trend.go index 92805587f72..cf4bf3d3b39 100644 --- a/pkg/schedule/schedulers/evict_slow_trend.go +++ b/pkg/schedule/schedulers/evict_slow_trend.go @@ -20,9 +20,13 @@ import ( "time" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sche "github.com/tikv/pd/pkg/schedule/core" @@ -31,8 +35,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/evict_slow_trend_test.go b/pkg/schedule/schedulers/evict_slow_trend_test.go index 4be6eeb58d9..21420cc6022 100644 --- a/pkg/schedule/schedulers/evict_slow_trend_test.go +++ b/pkg/schedule/schedulers/evict_slow_trend_test.go @@ -19,9 +19,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/suite" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/grant_hot_region.go b/pkg/schedule/schedulers/grant_hot_region.go index e547c7204e2..79be126f1d4 100644 --- a/pkg/schedule/schedulers/grant_hot_region.go +++ b/pkg/schedule/schedulers/grant_hot_region.go @@ -21,8 +21,12 @@ import ( "strings" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -36,8 +40,6 @@ import ( "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) type grantHotRegionSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/grant_leader.go b/pkg/schedule/schedulers/grant_leader.go index b18d1fc3397..d0cb6bae34d 100644 --- a/pkg/schedule/schedulers/grant_leader.go +++ b/pkg/schedule/schedulers/grant_leader.go @@ -19,8 +19,12 @@ import ( "strconv" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -31,8 +35,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) type grantLeaderSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/grant_leader_test.go b/pkg/schedule/schedulers/grant_leader_test.go index 38bac3c961a..003966db73d 100644 --- a/pkg/schedule/schedulers/grant_leader_test.go +++ b/pkg/schedule/schedulers/grant_leader_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/storage" diff --git a/pkg/schedule/schedulers/hot_region.go b/pkg/schedule/schedulers/hot_region.go index 75f3af17d5d..2ba9af782db 100644 --- a/pkg/schedule/schedulers/hot_region.go +++ b/pkg/schedule/schedulers/hot_region.go @@ -23,10 +23,13 @@ import ( "strconv" "time" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "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/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -41,7 +44,6 @@ import ( "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/keyutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/hot_region_config.go b/pkg/schedule/schedulers/hot_region_config.go index df82ccc3afc..c458d29842f 100644 --- a/pkg/schedule/schedulers/hot_region_config.go +++ b/pkg/schedule/schedulers/hot_region_config.go @@ -22,7 +22,11 @@ import ( "time" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/slice" @@ -31,8 +35,6 @@ import ( "github.com/tikv/pd/pkg/utils/reflectutil" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/pkg/versioninfo" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/hot_region_rank_v2_test.go b/pkg/schedule/schedulers/hot_region_rank_v2_test.go index f00e9dde787..d4cbfc092a0 100644 --- a/pkg/schedule/schedulers/hot_region_rank_v2_test.go +++ b/pkg/schedule/schedulers/hot_region_rank_v2_test.go @@ -19,6 +19,7 @@ import ( "github.com/docker/go-units" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/statistics/utils" diff --git a/pkg/schedule/schedulers/hot_region_test.go b/pkg/schedule/schedulers/hot_region_test.go index 9f79ac617c9..b37fc00cea1 100644 --- a/pkg/schedule/schedulers/hot_region_test.go +++ b/pkg/schedule/schedulers/hot_region_test.go @@ -22,9 +22,11 @@ import ( "time" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/schedule/operator" diff --git a/pkg/schedule/schedulers/label.go b/pkg/schedule/schedulers/label.go index a27ea29687e..cd63b6c0511 100644 --- a/pkg/schedule/schedulers/label.go +++ b/pkg/schedule/schedulers/label.go @@ -15,7 +15,10 @@ package schedulers import ( + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -25,7 +28,6 @@ import ( "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/schedule/types" - "go.uber.org/zap" ) type labelSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/metrics.go b/pkg/schedule/schedulers/metrics.go index 4afc4605f52..bd8a2b4f6ea 100644 --- a/pkg/schedule/schedulers/metrics.go +++ b/pkg/schedule/schedulers/metrics.go @@ -16,6 +16,7 @@ package schedulers import ( "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/pkg/schedule/types" ) diff --git a/pkg/schedule/schedulers/random_merge.go b/pkg/schedule/schedulers/random_merge.go index 7cd9954ce4b..ccb1bc12f9a 100644 --- a/pkg/schedule/schedulers/random_merge.go +++ b/pkg/schedule/schedulers/random_merge.go @@ -18,6 +18,7 @@ import ( "math/rand" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/schedule/schedulers/random_merge_test.go b/pkg/schedule/schedulers/random_merge_test.go index 6c8ea353f2d..e7be6d589ba 100644 --- a/pkg/schedule/schedulers/random_merge_test.go +++ b/pkg/schedule/schedulers/random_merge_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/storage" diff --git a/pkg/schedule/schedulers/range_cluster.go b/pkg/schedule/schedulers/range_cluster.go index e83e74145f6..0b6e908b56c 100644 --- a/pkg/schedule/schedulers/range_cluster.go +++ b/pkg/schedule/schedulers/range_cluster.go @@ -16,6 +16,7 @@ package schedulers import ( "github.com/docker/go-units" + "github.com/tikv/pd/pkg/core" sche "github.com/tikv/pd/pkg/schedule/core" ) diff --git a/pkg/schedule/schedulers/scatter_range.go b/pkg/schedule/schedulers/scatter_range.go index 5ba303ad05a..2e071ec6ca7 100644 --- a/pkg/schedule/schedulers/scatter_range.go +++ b/pkg/schedule/schedulers/scatter_range.go @@ -19,7 +19,10 @@ import ( "net/http" "github.com/gorilla/mux" + "github.com/unrolled/render" + "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" @@ -28,7 +31,6 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" ) type scatterRangeSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/scatter_range_test.go b/pkg/schedule/schedulers/scatter_range_test.go index 26ac48a36bb..7125ba9a596 100644 --- a/pkg/schedule/schedulers/scatter_range_test.go +++ b/pkg/schedule/schedulers/scatter_range_test.go @@ -19,8 +19,10 @@ import ( "math/rand" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/storage" diff --git a/pkg/schedule/schedulers/scheduler.go b/pkg/schedule/schedulers/scheduler.go index 3f722f7f804..8976c3a1928 100644 --- a/pkg/schedule/schedulers/scheduler.go +++ b/pkg/schedule/schedulers/scheduler.go @@ -20,8 +20,11 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/schedule/config" sche "github.com/tikv/pd/pkg/schedule/core" @@ -29,7 +32,6 @@ import ( "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/storage/endpoint" - "go.uber.org/zap" ) // Scheduler is an interface to schedule resources. diff --git a/pkg/schedule/schedulers/scheduler_controller.go b/pkg/schedule/schedulers/scheduler_controller.go index cb4ffd6f9c2..28973631570 100644 --- a/pkg/schedule/schedulers/scheduler_controller.go +++ b/pkg/schedule/schedulers/scheduler_controller.go @@ -22,7 +22,10 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" @@ -33,7 +36,6 @@ import ( "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const maxScheduleRetries = 10 diff --git a/pkg/schedule/schedulers/scheduler_test.go b/pkg/schedule/schedulers/scheduler_test.go index 0e06b9333e9..24df62ad3e1 100644 --- a/pkg/schedule/schedulers/scheduler_test.go +++ b/pkg/schedule/schedulers/scheduler_test.go @@ -20,8 +20,10 @@ import ( "testing" "github.com/docker/go-units" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/schedule/schedulers/shuffle_hot_region.go b/pkg/schedule/schedulers/shuffle_hot_region.go index 7517abb3c21..6da4b71ea45 100644 --- a/pkg/schedule/schedulers/shuffle_hot_region.go +++ b/pkg/schedule/schedulers/shuffle_hot_region.go @@ -18,8 +18,12 @@ import ( "net/http" "github.com/gorilla/mux" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" @@ -30,8 +34,6 @@ import ( "github.com/tikv/pd/pkg/statistics" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" - "go.uber.org/zap" ) type shuffleHotRegionSchedulerConfig struct { diff --git a/pkg/schedule/schedulers/shuffle_leader.go b/pkg/schedule/schedulers/shuffle_leader.go index e2a256af7a7..8fd5b87c1bc 100644 --- a/pkg/schedule/schedulers/shuffle_leader.go +++ b/pkg/schedule/schedulers/shuffle_leader.go @@ -16,6 +16,7 @@ package schedulers import ( "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/schedule/schedulers/shuffle_region.go b/pkg/schedule/schedulers/shuffle_region.go index 1fbc1f08e67..2b4e2443210 100644 --- a/pkg/schedule/schedulers/shuffle_region.go +++ b/pkg/schedule/schedulers/shuffle_region.go @@ -18,6 +18,7 @@ import ( "net/http" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" sche "github.com/tikv/pd/pkg/schedule/core" diff --git a/pkg/schedule/schedulers/shuffle_region_config.go b/pkg/schedule/schedulers/shuffle_region_config.go index 2e3394a58df..58ea25b6186 100644 --- a/pkg/schedule/schedulers/shuffle_region_config.go +++ b/pkg/schedule/schedulers/shuffle_region_config.go @@ -18,12 +18,13 @@ import ( "net/http" "github.com/gorilla/mux" + "github.com/unrolled/render" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" ) const ( diff --git a/pkg/schedule/schedulers/split_bucket.go b/pkg/schedule/schedulers/split_bucket.go index edbe2ac3545..d6aee65b181 100644 --- a/pkg/schedule/schedulers/split_bucket.go +++ b/pkg/schedule/schedulers/split_bucket.go @@ -22,8 +22,11 @@ import ( "strconv" "github.com/gorilla/mux" + "github.com/unrolled/render" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/operator" @@ -32,7 +35,6 @@ import ( "github.com/tikv/pd/pkg/statistics/buckets" "github.com/tikv/pd/pkg/utils/reflectutil" "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/unrolled/render" ) const ( diff --git a/pkg/schedule/schedulers/split_bucket_test.go b/pkg/schedule/schedulers/split_bucket_test.go index 840dfa97c19..41892bb4fc4 100644 --- a/pkg/schedule/schedulers/split_bucket_test.go +++ b/pkg/schedule/schedulers/split_bucket_test.go @@ -18,8 +18,10 @@ import ( "fmt" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/statistics/buckets" diff --git a/pkg/schedule/schedulers/transfer_witness_leader.go b/pkg/schedule/schedulers/transfer_witness_leader.go index 90191dd355c..c84f0918884 100644 --- a/pkg/schedule/schedulers/transfer_witness_leader.go +++ b/pkg/schedule/schedulers/transfer_witness_leader.go @@ -19,6 +19,7 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/schedule/schedulers/transfer_witness_leader_test.go b/pkg/schedule/schedulers/transfer_witness_leader_test.go index b100e0a9535..e58f3dd3544 100644 --- a/pkg/schedule/schedulers/transfer_witness_leader_test.go +++ b/pkg/schedule/schedulers/transfer_witness_leader_test.go @@ -17,9 +17,11 @@ package schedulers import ( "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/schedule/types" diff --git a/pkg/schedule/schedulers/utils.go b/pkg/schedule/schedulers/utils.go index 9c1c7fe3854..9a6a6bd96fa 100644 --- a/pkg/schedule/schedulers/utils.go +++ b/pkg/schedule/schedulers/utils.go @@ -19,7 +19,10 @@ import ( "strconv" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/errs" @@ -28,7 +31,6 @@ import ( "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/schedule/plan" "github.com/tikv/pd/pkg/statistics" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/schedulers/utils_test.go b/pkg/schedule/schedulers/utils_test.go index deb7c6e1038..d85fba47ff4 100644 --- a/pkg/schedule/schedulers/utils_test.go +++ b/pkg/schedule/schedulers/utils_test.go @@ -17,8 +17,10 @@ package schedulers import ( "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/schedule/splitter/region_splitter.go b/pkg/schedule/splitter/region_splitter.go index 37b33dad480..c5b950d73be 100644 --- a/pkg/schedule/splitter/region_splitter.go +++ b/pkg/schedule/splitter/region_splitter.go @@ -22,15 +22,17 @@ import ( "math" "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" sche "github.com/tikv/pd/pkg/schedule/core" "github.com/tikv/pd/pkg/schedule/filter" "github.com/tikv/pd/pkg/schedule/operator" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/schedule/splitter/region_splitter_test.go b/pkg/schedule/splitter/region_splitter_test.go index 6f49707217e..8e59fa74382 100644 --- a/pkg/schedule/splitter/region_splitter_test.go +++ b/pkg/schedule/splitter/region_splitter_test.go @@ -20,6 +20,7 @@ import ( "testing" "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/slice/slice_test.go b/pkg/slice/slice_test.go index 019cd49c46a..c0abb46f298 100644 --- a/pkg/slice/slice_test.go +++ b/pkg/slice/slice_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/slice" ) diff --git a/pkg/statistics/buckets/hot_bucket_cache.go b/pkg/statistics/buckets/hot_bucket_cache.go index 3fc640e8c1f..f29ef1563e8 100644 --- a/pkg/statistics/buckets/hot_bucket_cache.go +++ b/pkg/statistics/buckets/hot_bucket_cache.go @@ -19,12 +19,14 @@ import ( "context" "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core/rangetree" "github.com/tikv/pd/pkg/utils/keyutil" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) type status int diff --git a/pkg/statistics/buckets/hot_bucket_cache_test.go b/pkg/statistics/buckets/hot_bucket_cache_test.go index e9669eb2eec..06e00687fd7 100644 --- a/pkg/statistics/buckets/hot_bucket_cache_test.go +++ b/pkg/statistics/buckets/hot_bucket_cache_test.go @@ -18,8 +18,9 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" ) func TestPutItem(t *testing.T) { diff --git a/pkg/statistics/buckets/hot_bucket_task_test.go b/pkg/statistics/buckets/hot_bucket_task_test.go index 100ed7c818d..93551919ba2 100644 --- a/pkg/statistics/buckets/hot_bucket_task_test.go +++ b/pkg/statistics/buckets/hot_bucket_task_test.go @@ -21,8 +21,9 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" ) func getAllBucketStats(ctx context.Context, hotCache *HotBucketCache) map[uint64][]*BucketStat { diff --git a/pkg/statistics/hot_cache.go b/pkg/statistics/hot_cache.go index ae61063646d..99ec587aea7 100644 --- a/pkg/statistics/hot_cache.go +++ b/pkg/statistics/hot_cache.go @@ -17,8 +17,10 @@ package statistics import ( "context" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/smallnest/chanx" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/logutil" diff --git a/pkg/statistics/hot_cache_test.go b/pkg/statistics/hot_cache_test.go index b0232b658d4..668c930adcc 100644 --- a/pkg/statistics/hot_cache_test.go +++ b/pkg/statistics/hot_cache_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/statistics/utils" ) diff --git a/pkg/statistics/hot_peer.go b/pkg/statistics/hot_peer.go index c17ad5c246f..55dcd03b4ee 100644 --- a/pkg/statistics/hot_peer.go +++ b/pkg/statistics/hot_peer.go @@ -18,12 +18,14 @@ import ( "math" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/movingaverage" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) type dimStat struct { diff --git a/pkg/statistics/hot_peer_cache.go b/pkg/statistics/hot_peer_cache.go index b62248062bd..77b5d567ca4 100644 --- a/pkg/statistics/hot_peer_cache.go +++ b/pkg/statistics/hot_peer_cache.go @@ -20,9 +20,11 @@ import ( "math" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/prometheus/client_golang/prometheus" "github.com/smallnest/chanx" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/statistics/utils" diff --git a/pkg/statistics/hot_peer_cache_test.go b/pkg/statistics/hot_peer_cache_test.go index 2d44b5dc783..09d267d60b9 100644 --- a/pkg/statistics/hot_peer_cache_test.go +++ b/pkg/statistics/hot_peer_cache_test.go @@ -23,9 +23,11 @@ import ( "time" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockid" "github.com/tikv/pd/pkg/movingaverage" diff --git a/pkg/statistics/region_collection.go b/pkg/statistics/region_collection.go index 958ba3be5df..8d12dbf42c9 100644 --- a/pkg/statistics/region_collection.go +++ b/pkg/statistics/region_collection.go @@ -17,12 +17,14 @@ package statistics import ( "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/placement" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) // RegionInfoProvider is an interface to provide the region information. diff --git a/pkg/statistics/region_collection_test.go b/pkg/statistics/region_collection_test.go index 64a625a04e2..f97dffa893d 100644 --- a/pkg/statistics/region_collection_test.go +++ b/pkg/statistics/region_collection_test.go @@ -18,9 +18,11 @@ import ( "context" "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockconfig" "github.com/tikv/pd/pkg/schedule/placement" diff --git a/pkg/statistics/store.go b/pkg/statistics/store.go index baeef0ad417..fbbfea72700 100644 --- a/pkg/statistics/store.go +++ b/pkg/statistics/store.go @@ -17,13 +17,15 @@ package statistics import ( "time" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/movingaverage" "github.com/tikv/pd/pkg/statistics/utils" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/statistics/store_collection.go b/pkg/statistics/store_collection.go index f55c23b27b7..a7c77aa7b4b 100644 --- a/pkg/statistics/store_collection.go +++ b/pkg/statistics/store_collection.go @@ -19,6 +19,7 @@ import ( "strconv" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/core/storelimit" diff --git a/pkg/statistics/store_collection_test.go b/pkg/statistics/store_collection_test.go index 6a0ef24aff5..93845d4de1a 100644 --- a/pkg/statistics/store_collection_test.go +++ b/pkg/statistics/store_collection_test.go @@ -20,9 +20,11 @@ import ( "time" "github.com/docker/go-units" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/mock/mockconfig" diff --git a/pkg/statistics/store_load_test.go b/pkg/statistics/store_load_test.go index 9d958151182..cbcbb0bacfe 100644 --- a/pkg/statistics/store_load_test.go +++ b/pkg/statistics/store_load_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core/constant" "github.com/tikv/pd/pkg/statistics/utils" ) diff --git a/pkg/statistics/store_test.go b/pkg/statistics/store_test.go index ccf85caaa72..741fdc54fd3 100644 --- a/pkg/statistics/store_test.go +++ b/pkg/statistics/store_test.go @@ -18,9 +18,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/statistics/utils/kind_test.go b/pkg/statistics/utils/kind_test.go index 0a02ffa00c1..d0834e077da 100644 --- a/pkg/statistics/utils/kind_test.go +++ b/pkg/statistics/utils/kind_test.go @@ -17,9 +17,11 @@ package utils import ( "testing" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" ) diff --git a/pkg/storage/endpoint/cluster_id.go b/pkg/storage/endpoint/cluster_id.go index 974b65d6c6c..f9317d44874 100644 --- a/pkg/storage/endpoint/cluster_id.go +++ b/pkg/storage/endpoint/cluster_id.go @@ -19,14 +19,16 @@ import ( "math/rand" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // InitClusterID creates a cluster ID if it hasn't existed. diff --git a/pkg/storage/endpoint/cluster_id_test.go b/pkg/storage/endpoint/cluster_id_test.go index 5ce1600044d..dcd06e15053 100644 --- a/pkg/storage/endpoint/cluster_id_test.go +++ b/pkg/storage/endpoint/cluster_id_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/storage/endpoint/config.go b/pkg/storage/endpoint/config.go index d297562f275..0c96de0a8cc 100644 --- a/pkg/storage/endpoint/config.go +++ b/pkg/storage/endpoint/config.go @@ -18,9 +18,10 @@ import ( "encoding/json" "strings" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" ) // ConfigStorage defines the storage operations on the config. diff --git a/pkg/storage/endpoint/gc_safe_point.go b/pkg/storage/endpoint/gc_safe_point.go index 8a6c5c5f789..15d3b3c47a1 100644 --- a/pkg/storage/endpoint/gc_safe_point.go +++ b/pkg/storage/endpoint/gc_safe_point.go @@ -20,11 +20,13 @@ import ( "strconv" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" ) // ServiceSafePoint is the safepoint for a specific service diff --git a/pkg/storage/endpoint/keyspace.go b/pkg/storage/endpoint/keyspace.go index 77240541951..e1c7ae4c846 100644 --- a/pkg/storage/endpoint/keyspace.go +++ b/pkg/storage/endpoint/keyspace.go @@ -19,11 +19,13 @@ import ( "strconv" "github.com/gogo/protobuf/proto" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" ) const ( diff --git a/pkg/storage/endpoint/meta.go b/pkg/storage/endpoint/meta.go index 176188be3f3..73b7c397ff4 100644 --- a/pkg/storage/endpoint/meta.go +++ b/pkg/storage/endpoint/meta.go @@ -21,8 +21,10 @@ import ( "time" "github.com/gogo/protobuf/proto" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/storage/endpoint/resource_group.go b/pkg/storage/endpoint/resource_group.go index 733e5ba2c9a..431c869ac70 100644 --- a/pkg/storage/endpoint/resource_group.go +++ b/pkg/storage/endpoint/resource_group.go @@ -16,6 +16,7 @@ package endpoint import ( "github.com/gogo/protobuf/proto" + "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/storage/endpoint/safepoint_v2.go b/pkg/storage/endpoint/safepoint_v2.go index f16855e86d6..12659847510 100644 --- a/pkg/storage/endpoint/safepoint_v2.go +++ b/pkg/storage/endpoint/safepoint_v2.go @@ -19,12 +19,14 @@ import ( "math" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // GCSafePointV2 represents the overall safe point for a specific keyspace. diff --git a/pkg/storage/endpoint/service_middleware.go b/pkg/storage/endpoint/service_middleware.go index 3859dab4d62..35f0606f9d0 100644 --- a/pkg/storage/endpoint/service_middleware.go +++ b/pkg/storage/endpoint/service_middleware.go @@ -29,7 +29,7 @@ type ServiceMiddlewareStorage interface { var _ ServiceMiddlewareStorage = (*StorageEndpoint)(nil) -// LoadServiceMiddlewareConfig loads service middleware config from keypath.KeyspaceGroupLocalTSPath then unmarshal it to cfg. +// LoadServiceMiddlewareConfig loads service middleware config from ServiceMiddlewarePath then unmarshal it to cfg. func (se *StorageEndpoint) LoadServiceMiddlewareConfig(cfg any) (bool, error) { value, err := se.Load(keypath.ServiceMiddlewarePath) if err != nil || value == "" { @@ -42,7 +42,7 @@ func (se *StorageEndpoint) LoadServiceMiddlewareConfig(cfg any) (bool, error) { return true, nil } -// SaveServiceMiddlewareConfig stores marshallable cfg to the keypath.KeyspaceGroupLocalTSPath. +// SaveServiceMiddlewareConfig stores marshallable cfg to the ServiceMiddlewarePath. func (se *StorageEndpoint) SaveServiceMiddlewareConfig(cfg any) error { return se.saveJSON(keypath.ServiceMiddlewarePath, cfg) } diff --git a/pkg/storage/endpoint/tso.go b/pkg/storage/endpoint/tso.go index a656f6d2945..697001dfe7c 100644 --- a/pkg/storage/endpoint/tso.go +++ b/pkg/storage/endpoint/tso.go @@ -19,13 +19,15 @@ import ( "strings" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // TSOStorage is the interface for timestamp storage. @@ -37,9 +39,9 @@ type TSOStorage interface { var _ TSOStorage = (*StorageEndpoint)(nil) -// LoadTimestamp will get all time windows of Local/Global TSOs from etcd and return the biggest one. -// For the Global TSO, loadTimestamp will get all Local and Global TSO time windows persisted in etcd and choose the biggest one. -// For the Local TSO, loadTimestamp will only get its own dc-location time window persisted before. +// LoadTimestamp will get all time windows of Global TSOs from etcd and return the biggest one. +// TODO: Due to local TSO is deprecated, maybe we do not need to load timestamp +// by prefix, we can just load the timestamp by the key. func (se *StorageEndpoint) LoadTimestamp(prefix string) (time.Time, error) { prefixEnd := clientv3.GetPrefixRangeEnd(prefix) keys, values, err := se.LoadRange(prefix, prefixEnd, 0) diff --git a/pkg/storage/endpoint/tso_keyspace_group.go b/pkg/storage/endpoint/tso_keyspace_group.go index b45d1f1da37..ef9a23308a6 100644 --- a/pkg/storage/endpoint/tso_keyspace_group.go +++ b/pkg/storage/endpoint/tso_keyspace_group.go @@ -18,11 +18,12 @@ import ( "context" "encoding/json" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" ) // UserKind represents the user kind. diff --git a/pkg/storage/endpoint/util.go b/pkg/storage/endpoint/util.go index 39aa6240f5a..e8f17a3922f 100644 --- a/pkg/storage/endpoint/util.go +++ b/pkg/storage/endpoint/util.go @@ -20,10 +20,11 @@ import ( "strings" "github.com/gogo/protobuf/proto" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/etcdutil" - clientv3 "go.etcd.io/etcd/client/v3" ) func (se *StorageEndpoint) loadProto(key string, msg proto.Message) (bool, error) { diff --git a/pkg/storage/etcd_backend.go b/pkg/storage/etcd_backend.go index e9af5fc67f6..b967d99b37b 100644 --- a/pkg/storage/etcd_backend.go +++ b/pkg/storage/etcd_backend.go @@ -15,9 +15,10 @@ package storage import ( + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" - clientv3 "go.etcd.io/etcd/client/v3" ) // etcdBackend is a storage backend that stores data in etcd, diff --git a/pkg/storage/hot_region_storage.go b/pkg/storage/hot_region_storage.go index d323b40d435..b5ec8dda6ba 100644 --- a/pkg/storage/hot_region_storage.go +++ b/pkg/storage/hot_region_storage.go @@ -24,12 +24,15 @@ import ( "sync" "time" - "github.com/pingcap/kvproto/pkg/encryptionpb" - "github.com/pingcap/kvproto/pkg/metapb" - "github.com/pingcap/log" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/iterator" "github.com/syndtr/goleveldb/leveldb/util" + "go.uber.org/zap" + + "github.com/pingcap/kvproto/pkg/encryptionpb" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" @@ -37,7 +40,6 @@ import ( "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) // HotRegionStorage is used to store the hot region info. diff --git a/pkg/storage/hot_region_storage_test.go b/pkg/storage/hot_region_storage_test.go index aeda8e450e7..cd713685eb0 100644 --- a/pkg/storage/hot_region_storage_test.go +++ b/pkg/storage/hot_region_storage_test.go @@ -26,6 +26,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/statistics/utils" ) diff --git a/pkg/storage/keyspace_test.go b/pkg/storage/keyspace_test.go index a6ce94e4711..7841f5da22d 100644 --- a/pkg/storage/keyspace_test.go +++ b/pkg/storage/keyspace_test.go @@ -19,8 +19,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/storage/kv/etcd_kv.go b/pkg/storage/kv/etcd_kv.go index 5945990c51b..c25f4d66060 100644 --- a/pkg/storage/kv/etcd_kv.go +++ b/pkg/storage/kv/etcd_kv.go @@ -20,13 +20,15 @@ import ( "strings" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/etcdutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( diff --git a/pkg/storage/kv/kv_test.go b/pkg/storage/kv/kv_test.go index f57c8145bd0..f05561b0c0b 100644 --- a/pkg/storage/kv/kv_test.go +++ b/pkg/storage/kv/kv_test.go @@ -22,8 +22,9 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/etcdutil" clientv3 "go.etcd.io/etcd/client/v3" + + "github.com/tikv/pd/pkg/utils/etcdutil" ) func TestEtcd(t *testing.T) { diff --git a/pkg/storage/kv/levedb_kv.go b/pkg/storage/kv/levedb_kv.go index 6f93cd0237f..5a74c1928e8 100644 --- a/pkg/storage/kv/levedb_kv.go +++ b/pkg/storage/kv/levedb_kv.go @@ -17,9 +17,11 @@ package kv import ( "context" - "github.com/pingcap/errors" "github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb/util" + + "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/syncutil" ) diff --git a/pkg/storage/kv/mem_kv.go b/pkg/storage/kv/mem_kv.go index dc24ab3e0f6..cc5dca29851 100644 --- a/pkg/storage/kv/mem_kv.go +++ b/pkg/storage/kv/mem_kv.go @@ -18,8 +18,10 @@ import ( "context" "github.com/google/btree" + "github.com/pingcap/errors" "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/utils/syncutil" ) diff --git a/pkg/storage/leveldb_backend.go b/pkg/storage/leveldb_backend.go index 8fb1db196c1..096a762db65 100644 --- a/pkg/storage/leveldb_backend.go +++ b/pkg/storage/leveldb_backend.go @@ -18,9 +18,11 @@ import ( "context" "time" + "github.com/syndtr/goleveldb/leveldb" + "github.com/pingcap/failpoint" "github.com/pingcap/log" - "github.com/syndtr/goleveldb/leveldb" + "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/endpoint" diff --git a/pkg/storage/leveldb_backend_test.go b/pkg/storage/leveldb_backend_test.go index c6e0fcef607..0bf626834cd 100644 --- a/pkg/storage/leveldb_backend_test.go +++ b/pkg/storage/leveldb_backend_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/testutil" ) diff --git a/pkg/storage/region_storage.go b/pkg/storage/region_storage.go index 5a581ec5155..8e6a4d87429 100644 --- a/pkg/storage/region_storage.go +++ b/pkg/storage/region_storage.go @@ -18,7 +18,9 @@ import ( "context" "github.com/gogo/protobuf/proto" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" diff --git a/pkg/storage/region_storage_test.go b/pkg/storage/region_storage_test.go index f6670f8c82e..c0ae04c8ded 100644 --- a/pkg/storage/region_storage_test.go +++ b/pkg/storage/region_storage_test.go @@ -18,8 +18,10 @@ import ( "context" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/storage/endpoint" ) diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go index dce2f1712b8..f83beecd0a1 100644 --- a/pkg/storage/storage.go +++ b/pkg/storage/storage.go @@ -18,13 +18,16 @@ import ( "context" "sync/atomic" + clientv3 "go.etcd.io/etcd/client/v3" + + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/syncutil" - clientv3 "go.etcd.io/etcd/client/v3" ) // Storage is the interface for the backend storage of the PD. @@ -73,13 +76,21 @@ func NewRegionStorageWithLevelDBBackend( // TODO: support other KV storage backends like BadgerDB in the future. +type regionSource int + +const ( + unloaded regionSource = iota + fromEtcd + fromLeveldb +) + type coreStorage struct { Storage regionStorage endpoint.RegionStorage - useRegionStorage int32 - regionLoaded bool - mu syncutil.Mutex + useRegionStorage atomic.Bool + regionLoaded regionSource + mu syncutil.RWMutex } // NewCoreStorage creates a new core storage with the given default and region storage. @@ -90,6 +101,7 @@ func NewCoreStorage(defaultStorage Storage, regionStorage endpoint.RegionStorage return &coreStorage{ Storage: defaultStorage, regionStorage: regionStorage, + regionLoaded: unloaded, } } @@ -116,12 +128,12 @@ func TrySwitchRegionStorage(s Storage, useLocalRegionStorage bool) endpoint.Regi if useLocalRegionStorage { // Switch the region storage to regionStorage, all region info will be read/saved by the internal // regionStorage, and in most cases it's LevelDB-backend. - atomic.StoreInt32(&ps.useRegionStorage, 1) + ps.useRegionStorage.Store(true) return ps.regionStorage } // Switch the region storage to defaultStorage, all region info will be read/saved by the internal // defaultStorage, and in most cases it's etcd-backend. - atomic.StoreInt32(&ps.useRegionStorage, 0) + ps.useRegionStorage.Store(false) return ps.Storage } @@ -133,24 +145,29 @@ func TryLoadRegionsOnce(ctx context.Context, s Storage, f func(region *core.Regi return s.LoadRegions(ctx, f) } - if atomic.LoadInt32(&ps.useRegionStorage) == 0 { - return ps.Storage.LoadRegions(ctx, f) - } - ps.mu.Lock() defer ps.mu.Unlock() - if !ps.regionLoaded { + + if !ps.useRegionStorage.Load() { + err := ps.Storage.LoadRegions(ctx, f) + if err == nil { + ps.regionLoaded = fromEtcd + } + return err + } + + if ps.regionLoaded == unloaded { if err := ps.regionStorage.LoadRegions(ctx, f); err != nil { return err } - ps.regionLoaded = true + ps.regionLoaded = fromLeveldb } return nil } // LoadRegion loads one region from storage. func (ps *coreStorage) LoadRegion(regionID uint64, region *metapb.Region) (ok bool, err error) { - if atomic.LoadInt32(&ps.useRegionStorage) > 0 { + if ps.useRegionStorage.Load() { return ps.regionStorage.LoadRegion(regionID, region) } return ps.Storage.LoadRegion(regionID, region) @@ -158,7 +175,7 @@ func (ps *coreStorage) LoadRegion(regionID uint64, region *metapb.Region) (ok bo // LoadRegions loads all regions from storage to RegionsInfo. func (ps *coreStorage) LoadRegions(ctx context.Context, f func(region *core.RegionInfo) []*core.RegionInfo) error { - if atomic.LoadInt32(&ps.useRegionStorage) > 0 { + if ps.useRegionStorage.Load() { return ps.regionStorage.LoadRegions(ctx, f) } return ps.Storage.LoadRegions(ctx, f) @@ -166,7 +183,7 @@ func (ps *coreStorage) LoadRegions(ctx context.Context, f func(region *core.Regi // SaveRegion saves one region to storage. func (ps *coreStorage) SaveRegion(region *metapb.Region) error { - if atomic.LoadInt32(&ps.useRegionStorage) > 0 { + if ps.useRegionStorage.Load() { return ps.regionStorage.SaveRegion(region) } return ps.Storage.SaveRegion(region) @@ -174,7 +191,7 @@ func (ps *coreStorage) SaveRegion(region *metapb.Region) error { // DeleteRegion deletes one region from storage. func (ps *coreStorage) DeleteRegion(region *metapb.Region) error { - if atomic.LoadInt32(&ps.useRegionStorage) > 0 { + if ps.useRegionStorage.Load() { return ps.regionStorage.DeleteRegion(region) } return ps.Storage.DeleteRegion(region) @@ -197,3 +214,17 @@ func (ps *coreStorage) Close() error { } return nil } + +// AreRegionsLoaded returns whether the regions are loaded. +func AreRegionsLoaded(s Storage) bool { + ps := s.(*coreStorage) + ps.mu.RLock() + defer ps.mu.RUnlock() + failpoint.Inject("loadRegionSlow", func() { + failpoint.Return(false) + }) + if ps.useRegionStorage.Load() { + return ps.regionLoaded == fromLeveldb + } + return ps.regionLoaded == fromEtcd +} diff --git a/pkg/storage/storage_gc_test.go b/pkg/storage/storage_gc_test.go index b18fcc12afc..ffffab620b3 100644 --- a/pkg/storage/storage_gc_test.go +++ b/pkg/storage/storage_gc_test.go @@ -19,8 +19,10 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go index ca1c8e275eb..e6c12f37cbb 100644 --- a/pkg/storage/storage_test.go +++ b/pkg/storage/storage_test.go @@ -25,13 +25,15 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/keypath" - clientv3 "go.etcd.io/etcd/client/v3" ) func TestBasic(t *testing.T) { diff --git a/pkg/storage/storage_tso_test.go b/pkg/storage/storage_tso_test.go index 07ea79df47c..e8b49106a09 100644 --- a/pkg/storage/storage_tso_test.go +++ b/pkg/storage/storage_tso_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/syncer/client.go b/pkg/syncer/client.go index 3d7f36d9114..81652045cbf 100644 --- a/pkg/syncer/client.go +++ b/pkg/syncer/client.go @@ -19,11 +19,19 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/backoff" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/keepalive" + "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/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/ratelimit" @@ -31,12 +39,6 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/backoff" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/keepalive" - "google.golang.org/grpc/status" ) const ( diff --git a/pkg/syncer/client_test.go b/pkg/syncer/client_test.go index 926be3421ab..03f18fd2b76 100644 --- a/pkg/syncer/client_test.go +++ b/pkg/syncer/client_test.go @@ -19,15 +19,17 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/metapb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockserver" "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/utils/grpcutil" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) // For issue https://github.com/tikv/pd/issues/3936 diff --git a/pkg/syncer/history_buffer.go b/pkg/syncer/history_buffer.go index 7ff6f202ad3..cb30eb56ee3 100644 --- a/pkg/syncer/history_buffer.go +++ b/pkg/syncer/history_buffer.go @@ -17,12 +17,14 @@ package syncer import ( "strconv" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/syncer/history_buffer_test.go b/pkg/syncer/history_buffer_test.go index 6bcd58b1689..368cecf5a3b 100644 --- a/pkg/syncer/history_buffer_test.go +++ b/pkg/syncer/history_buffer_test.go @@ -17,8 +17,10 @@ package syncer import ( "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/storage/kv" ) diff --git a/pkg/syncer/server.go b/pkg/syncer/server.go index 6009bba1d7d..89af3f79ccc 100644 --- a/pkg/syncer/server.go +++ b/pkg/syncer/server.go @@ -22,11 +22,16 @@ import ( "time" "github.com/docker/go-units" + "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/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/ratelimit" @@ -35,9 +40,6 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/syncutil" - "go.uber.org/zap" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) const ( diff --git a/pkg/systimemon/systimemon.go b/pkg/systimemon/systimemon.go index 75fc5e68d8b..e3aa67d8d7c 100644 --- a/pkg/systimemon/systimemon.go +++ b/pkg/systimemon/systimemon.go @@ -18,10 +18,12 @@ import ( "context" "time" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // StartMonitor calls systimeErrHandler if system time jump backward. diff --git a/pkg/tso/admin.go b/pkg/tso/admin.go index bc9fd1f853d..f74abb29fcb 100644 --- a/pkg/tso/admin.go +++ b/pkg/tso/admin.go @@ -19,9 +19,10 @@ import ( "net/http" "strconv" + "github.com/unrolled/render" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/apiutil" - "github.com/unrolled/render" ) // Handler defines the common behaviors of a basic tso handler. diff --git a/pkg/tso/allocator_manager.go b/pkg/tso/allocator_manager.go index 8d5589143aa..fda5c6088ab 100644 --- a/pkg/tso/allocator_manager.go +++ b/pkg/tso/allocator_manager.go @@ -16,16 +16,18 @@ package tso import ( "context" - "math" - "path" "runtime/trace" "strconv" "sync" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/member" @@ -33,8 +35,6 @@ import ( "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( @@ -43,8 +43,6 @@ const ( checkStep = time.Minute patrolStep = time.Second defaultAllocatorLeaderLease = 3 - localTSOAllocatorEtcdPrefix = "lta" - localTSOSuffixEtcdPrefix = "lts" ) var ( @@ -217,17 +215,6 @@ func (am *AllocatorManager) getGroupIDStr() string { return strconv.FormatUint(uint64(am.kgID), 10) } -// GetTimestampPath returns the timestamp path in etcd. -func (am *AllocatorManager) GetTimestampPath() string { - if am == nil { - return "" - } - - am.mu.RLock() - defer am.mu.RUnlock() - return path.Join(am.rootPath, am.mu.allocatorGroup.allocator.GetTimestampPath()) -} - // tsoAllocatorLoop is used to run the TSO Allocator updating daemon. func (am *AllocatorManager) tsoAllocatorLoop() { defer logutil.LogPanic() @@ -254,21 +241,6 @@ func (am *AllocatorManager) GetMember() ElectionMember { return am.member } -// GetSuffixBits calculates the bits of suffix sign -// by the max number of suffix so far, -// which will be used in the TSO logical part. -func (am *AllocatorManager) GetSuffixBits() int { - am.mu.RLock() - defer am.mu.RUnlock() - return CalSuffixBits(am.mu.maxSuffix) -} - -// CalSuffixBits calculates the bits of suffix by the max suffix sign. -func CalSuffixBits(maxSuffix int32) int { - // maxSuffix + 1 because we have the Global TSO holds 0 as the suffix sign - return int(math.Ceil(math.Log2(float64(maxSuffix + 1)))) -} - // AllocatorDaemon is used to update every allocator's TSO and check whether we have // any new local allocator that needs to be set up. func (am *AllocatorManager) AllocatorDaemon(ctx context.Context) { diff --git a/pkg/tso/global_allocator.go b/pkg/tso/global_allocator.go index 740317c676a..d6bf27878a7 100644 --- a/pkg/tso/global_allocator.go +++ b/pkg/tso/global_allocator.go @@ -24,9 +24,12 @@ import ( "sync/atomic" "time" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" mcsutils "github.com/tikv/pd/pkg/mcs/utils" @@ -34,7 +37,6 @@ import ( "github.com/tikv/pd/pkg/member" "github.com/tikv/pd/pkg/utils/keypath" "github.com/tikv/pd/pkg/utils/logutil" - "go.uber.org/zap" ) // Allocator is a Timestamp Oracle allocator. @@ -47,14 +49,6 @@ type Allocator interface { IsInitialize() bool // UpdateTSO is used to update the TSO in memory and the time window in etcd. UpdateTSO() error - // GetTimestampPath returns the timestamp path in etcd, which is: - // 1. for the default keyspace group: - // a. timestamp in /pd/{cluster_id}/timestamp - // b. lta/{dc-location}/timestamp in /pd/{cluster_id}/lta/{dc-location}/timestamp - // 1. for the non-default keyspace groups: - // a. {group}/gts/timestamp in /ms/{cluster_id}/tso/{group}/gta/timestamp - // b. {group}/lts/{dc-location}/timestamp in /ms/{cluster_id}/tso/{group}/lta/{dc-location}/timestamp - GetTimestampPath() string // SetTSO sets the physical part with given TSO. It's mainly used for BR restore. // Cannot set the TSO smaller than now in any case. // if ignoreSmaller=true, if input ts is smaller than current, ignore silently, else return error @@ -68,6 +62,8 @@ type Allocator interface { } // GlobalTSOAllocator is the global single point TSO allocator. +// TODO: Local TSO allocator is deprecated now, we can update the name to +// TSOAllocator and remove the `Global` concept. type GlobalTSOAllocator struct { ctx context.Context cancel context.CancelFunc @@ -132,19 +128,9 @@ func (gta *GlobalTSOAllocator) getGroupID() uint32 { return gta.am.getGroupID() } -// GetTimestampPath returns the timestamp path in etcd. -func (gta *GlobalTSOAllocator) GetTimestampPath() string { - if gta == nil || gta.timestampOracle == nil { - return "" - } - return gta.timestampOracle.GetTimestampPath() -} - // Initialize will initialize the created global TSO allocator. func (gta *GlobalTSOAllocator) Initialize(int) error { gta.tsoAllocatorRoleGauge.Set(1) - // The suffix of a Global TSO should always be 0. - gta.timestampOracle.suffix = 0 return gta.timestampOracle.SyncTimestamp() } @@ -175,7 +161,7 @@ func (gta *GlobalTSOAllocator) GenerateTSO(ctx context.Context, count uint32) (p return pdpb.Timestamp{}, errs.ErrGenerateTimestamp.FastGenByArgs(fmt.Sprintf("requested pd %s of cluster", errs.NotLeaderErr)) } - return gta.timestampOracle.getTS(ctx, gta.member.GetLeadership(), count, 0) + return gta.timestampOracle.getTS(ctx, gta.member.GetLeadership(), count) } // Reset is used to reset the TSO allocator. diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index 86b43d0de45..d22d284e1be 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -25,11 +25,16 @@ import ( "sync" "time" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + perrors "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/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" @@ -47,9 +52,6 @@ import ( "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( @@ -66,7 +68,7 @@ const ( type state struct { syncutil.RWMutex // ams stores the allocator managers of the keyspace groups. Each keyspace group is - // assigned with an allocator manager managing its global/local tso allocators. + // assigned with an allocator manager managing its global tso allocators. // Use a fixed size array to maximize the efficiency of concurrent access to // different keyspace groups for tso service. ams [constant.MaxKeyspaceGroupCountInUse]*AllocatorManager @@ -790,8 +792,7 @@ func (kgm *KeyspaceGroupManager) updateKeyspaceGroup(group *endpoint.KeyspaceGro am := NewAllocatorManager(kgm.ctx, group.ID, participant, tsRootPath, storage, kgm.cfg) am.startGlobalAllocatorLoop() log.Info("created allocator manager", - zap.Uint32("keyspace-group-id", group.ID), - zap.String("timestamp-path", am.GetTimestampPath())) + zap.Uint32("keyspace-group-id", group.ID)) kgm.Lock() group.KeyspaceLookupTable = make(map[uint32]struct{}) for _, kid := range group.Keyspaces { @@ -1517,7 +1518,6 @@ func (kgm *KeyspaceGroupManager) deletedGroupCleaner() { log.Info("delete the keyspace group tso key", zap.Uint32("keyspace-group-id", groupID)) // Clean up the remaining TSO keys. - // TODO: support the Local TSO Allocator clean up. err := kgm.tsoSvcStorage.DeleteTimestamp( keypath.TimestampPath( keypath.KeyspaceGroupGlobalTSPath(groupID), diff --git a/pkg/tso/keyspace_group_manager_test.go b/pkg/tso/keyspace_group_manager_test.go index dea0b00f4f0..b4393a23471 100644 --- a/pkg/tso/keyspace_group_manager_test.go +++ b/pkg/tso/keyspace_group_manager_test.go @@ -28,9 +28,14 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "go.etcd.io/etcd/api/v3/mvccpb" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/goleak" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/mcs/discovery" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/storage/endpoint" @@ -41,9 +46,6 @@ import ( "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.etcd.io/etcd/api/v3/mvccpb" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/goleak" ) func TestMain(m *testing.M) { @@ -87,7 +89,6 @@ func (suite *keyspaceGroupManagerTestSuite) createConfig() *TestServiceConfig { ListenAddr: addr, AdvertiseListenAddr: addr, LeaderLease: constant.DefaultLeaderLease, - LocalTSOEnabled: false, TSOUpdatePhysicalInterval: 50 * time.Millisecond, TSOSaveInterval: time.Duration(constant.DefaultLeaderLease) * time.Second, MaxResetTSGap: time.Hour * 24, diff --git a/pkg/tso/testutil.go b/pkg/tso/testutil.go index e3d04f55813..336d1414d98 100644 --- a/pkg/tso/testutil.go +++ b/pkg/tso/testutil.go @@ -29,7 +29,6 @@ type TestServiceConfig struct { ListenAddr string // Address the service listens on. AdvertiseListenAddr string // Address the service advertises to the clients. LeaderLease int64 // Leader lease. - LocalTSOEnabled bool // Whether local TSO is enabled. TSOUpdatePhysicalInterval time.Duration // Interval to update TSO in physical storage. TSOSaveInterval time.Duration // Interval to save TSO to physical storage. MaxResetTSGap time.Duration // Maximum gap to reset TSO. diff --git a/pkg/tso/tso.go b/pkg/tso/tso.go index 38a4c989093..5293780b22f 100644 --- a/pkg/tso/tso.go +++ b/pkg/tso/tso.go @@ -21,9 +21,13 @@ import ( "sync/atomic" "time" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/storage/endpoint" @@ -32,8 +36,6 @@ import ( "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/tsoutil" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const ( @@ -43,8 +45,6 @@ const ( // When a TSO's logical time reaches this limit, // the physical time will be forced to increase. maxLogical = int64(1 << 18) - // MaxSuffixBits indicates the max number of suffix bits. - MaxSuffixBits = 4 // jetLagWarningThreshold is the warning threshold of jetLag in `timestampOracle.UpdateTimestamp`. // In case of small `updatePhysicalInterval`, the `3 * updatePhysicalInterval` would also is small, // and trigger unnecessary warnings about clock offset. @@ -55,9 +55,8 @@ const ( // tsoObject is used to store the current TSO in memory with a RWMutex lock. type tsoObject struct { syncutil.RWMutex - physical time.Time - logical int64 - updateTime time.Time + physical time.Time + logical int64 } // timestampOracle is used to maintain the logic of TSO. @@ -75,7 +74,6 @@ type timestampOracle struct { tsoMux *tsoObject // last timestamp window stored in etcd lastSavedTime atomic.Value // stored as time.Time - suffix int // pre-initialized metrics metrics *tsoMetrics @@ -92,7 +90,6 @@ func (t *timestampOracle) setTSOPhysical(next time.Time, force bool) { if typeutil.SubTSOPhysicalByWallClock(next, t.tsoMux.physical) > 0 { t.tsoMux.physical = next t.tsoMux.logical = 0 - t.tsoMux.updateTime = time.Now() } } @@ -106,23 +103,17 @@ func (t *timestampOracle) getTSO() (time.Time, int64) { } // generateTSO will add the TSO's logical part with the given count and returns the new TSO result. -func (t *timestampOracle) generateTSO(ctx context.Context, count int64, suffixBits int) (physical int64, logical int64, lastUpdateTime time.Time) { +func (t *timestampOracle) generateTSO(ctx context.Context, count int64) (physical int64, logical int64) { defer trace.StartRegion(ctx, "timestampOracle.generateTSO").End() t.tsoMux.Lock() defer t.tsoMux.Unlock() if t.tsoMux.physical == typeutil.ZeroTime { - return 0, 0, typeutil.ZeroTime + return 0, 0 } physical = t.tsoMux.physical.UnixNano() / int64(time.Millisecond) t.tsoMux.logical += count logical = t.tsoMux.logical - if suffixBits > 0 && t.suffix >= 0 { - logical = t.calibrateLogical(logical, suffixBits) - } - // Return the last update time - lastUpdateTime = t.tsoMux.updateTime - t.tsoMux.updateTime = time.Now() - return physical, logical, lastUpdateTime + return physical, logical } func (t *timestampOracle) getLastSavedTime() time.Time { @@ -133,28 +124,6 @@ func (t *timestampOracle) getLastSavedTime() time.Time { return last.(time.Time) } -// Because the Local TSO in each Local TSO Allocator is independent, so they are possible -// to be the same at sometimes, to avoid this case, we need to use the logical part of the -// Local TSO to do some differentiating work. -// For example, we have three DCs: dc-1, dc-2 and dc-3. The bits of suffix is defined by -// the const suffixBits. Then, for dc-2, the suffix may be 1 because it's persisted -// in etcd with the value of 1. -// Once we get a normal TSO like this (18 bits): xxxxxxxxxxxxxxxxxx. We will make the TSO's -// low bits of logical part from each DC looks like: -// -// global: xxxxxxxxxx00000000 -// dc-1: xxxxxxxxxx00000001 -// dc-2: xxxxxxxxxx00000010 -// dc-3: xxxxxxxxxx00000011 -func (t *timestampOracle) calibrateLogical(rawLogical int64, suffixBits int) int64 { - return rawLogical< 0)) @@ -209,7 +178,7 @@ func (t *timestampOracle) SyncTimestamp() error { }) save := next.Add(t.saveInterval) start := time.Now() - if err = t.storage.SaveTimestamp(t.GetTimestampPath(), save); err != nil { + if err = t.storage.SaveTimestamp(keypath.TimestampPath(t.tsPath), save); err != nil { t.metrics.errSaveSyncTSEvent.Inc() return err } @@ -277,7 +246,7 @@ func (t *timestampOracle) resetUserTimestamp(leadership *election.Leadership, ts if typeutil.SubRealTimeByWallClock(t.getLastSavedTime(), nextPhysical) <= UpdateTimestampGuard { save := nextPhysical.Add(t.saveInterval) start := time.Now() - if err := t.storage.SaveTimestamp(t.GetTimestampPath(), save); err != nil { + if err := t.storage.SaveTimestamp(keypath.TimestampPath(t.tsPath), save); err != nil { t.metrics.errSaveResetTSEvent.Inc() return err } @@ -287,7 +256,6 @@ func (t *timestampOracle) resetUserTimestamp(leadership *election.Leadership, ts // save into memory only if nextPhysical or nextLogical is greater. t.tsoMux.physical = nextPhysical t.tsoMux.logical = int64(nextLogical) - t.tsoMux.updateTime = time.Now() t.metrics.resetTSOOKEvent.Inc() return nil } @@ -361,10 +329,10 @@ func (t *timestampOracle) UpdateTimestamp() error { if typeutil.SubRealTimeByWallClock(t.getLastSavedTime(), next) <= UpdateTimestampGuard { save := next.Add(t.saveInterval) start := time.Now() - if err := t.storage.SaveTimestamp(t.GetTimestampPath(), save); err != nil { + if err := t.storage.SaveTimestamp(keypath.TimestampPath(t.tsPath), save); err != nil { log.Warn("save timestamp failed", logutil.CondUint32("keyspace-group-id", t.keyspaceGroupID, t.keyspaceGroupID > 0), - zap.String("timestamp-path", t.GetTimestampPath()), + zap.String("timestamp-path", keypath.TimestampPath(t.tsPath)), zap.Error(err)) t.metrics.errSaveUpdateTSEvent.Inc() return err @@ -381,7 +349,7 @@ func (t *timestampOracle) UpdateTimestamp() error { var maxRetryCount = 10 // getTS is used to get a timestamp. -func (t *timestampOracle) getTS(ctx context.Context, leadership *election.Leadership, count uint32, suffixBits int) (pdpb.Timestamp, error) { +func (t *timestampOracle) getTS(ctx context.Context, leadership *election.Leadership, count uint32) (pdpb.Timestamp, error) { defer trace.StartRegion(ctx, "timestampOracle.getTS").End() var resp pdpb.Timestamp if count == 0 { @@ -399,7 +367,7 @@ func (t *timestampOracle) getTS(ctx context.Context, leadership *election.Leader return pdpb.Timestamp{}, errs.ErrGenerateTimestamp.FastGenByArgs("timestamp in memory isn't initialized") } // Get a new TSO result with the given count - resp.Physical, resp.Logical, _ = t.generateTSO(ctx, int64(count), suffixBits) + resp.Physical, resp.Logical = t.generateTSO(ctx, int64(count)) if resp.GetPhysical() == 0 { return pdpb.Timestamp{}, errs.ErrGenerateTimestamp.FastGenByArgs("timestamp in memory has been reset") } @@ -416,7 +384,6 @@ func (t *timestampOracle) getTS(ctx context.Context, leadership *election.Leader if !leadership.Check() { return pdpb.Timestamp{}, errs.ErrGenerateTimestamp.FastGenByArgs(fmt.Sprintf("requested %s anymore", errs.NotLeaderErr)) } - resp.SuffixBits = uint32(suffixBits) return resp, nil } t.metrics.exceededMaxRetryEvent.Inc() @@ -430,6 +397,5 @@ func (t *timestampOracle) ResetTimestamp() { log.Info("reset the timestamp in memory", logutil.CondUint32("keyspace-group-id", t.keyspaceGroupID, t.keyspaceGroupID > 0)) t.tsoMux.physical = typeutil.ZeroTime t.tsoMux.logical = 0 - t.tsoMux.updateTime = typeutil.ZeroTime t.lastSavedTime.Store(typeutil.ZeroTime) } diff --git a/pkg/tso/util_test.go b/pkg/tso/util_test.go index f31f8781ded..c2922d49b7f 100644 --- a/pkg/tso/util_test.go +++ b/pkg/tso/util_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/keypath" ) diff --git a/pkg/unsaferecovery/unsafe_recovery_controller.go b/pkg/unsaferecovery/unsafe_recovery_controller.go index aa3cf192270..dce2069e316 100644 --- a/pkg/unsaferecovery/unsafe_recovery_controller.go +++ b/pkg/unsaferecovery/unsafe_recovery_controller.go @@ -23,10 +23,13 @@ import ( "strings" "time" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/btree" "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" @@ -35,7 +38,6 @@ import ( "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/pkg/utils/typeutil" - "go.uber.org/zap" ) // stage is the stage of unsafe recovery. diff --git a/pkg/unsaferecovery/unsafe_recovery_controller_test.go b/pkg/unsaferecovery/unsafe_recovery_controller_test.go index feaf5ba7430..0dab6aeca1d 100644 --- a/pkg/unsaferecovery/unsafe_recovery_controller_test.go +++ b/pkg/unsaferecovery/unsafe_recovery_controller_test.go @@ -21,11 +21,13 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/eraftpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/kvproto/pkg/raft_serverpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/mock/mockcluster" diff --git a/pkg/utils/apiutil/apiutil.go b/pkg/utils/apiutil/apiutil.go index 20465d8376c..a743c543468 100644 --- a/pkg/utils/apiutil/apiutil.go +++ b/pkg/utils/apiutil/apiutil.go @@ -33,13 +33,15 @@ import ( "github.com/gin-gonic/gin" "github.com/gorilla/mux" "github.com/joho/godotenv" + "github.com/unrolled/render" + "go.uber.org/zap" + "github.com/pingcap/errcode" "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/slice" - "github.com/unrolled/render" - "go.uber.org/zap" ) const ( diff --git a/pkg/utils/apiutil/multiservicesapi/middleware.go b/pkg/utils/apiutil/multiservicesapi/middleware.go index 4343adcc981..5362475f9ad 100644 --- a/pkg/utils/apiutil/multiservicesapi/middleware.go +++ b/pkg/utils/apiutil/multiservicesapi/middleware.go @@ -19,11 +19,13 @@ import ( "net/url" "github.com/gin-gonic/gin" + "go.uber.org/zap" + "github.com/pingcap/log" + bs "github.com/tikv/pd/pkg/basicserver" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/apiutil" - "go.uber.org/zap" ) const ( diff --git a/pkg/utils/apiutil/serverapi/middleware.go b/pkg/utils/apiutil/serverapi/middleware.go index d6fc98082d6..85b958a5554 100644 --- a/pkg/utils/apiutil/serverapi/middleware.go +++ b/pkg/utils/apiutil/serverapi/middleware.go @@ -20,15 +20,17 @@ import ( "strings" "time" + "github.com/urfave/negroni" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/server" - "github.com/urfave/negroni" - "go.uber.org/zap" ) type runtimeServiceValidator struct { diff --git a/pkg/utils/configutil/configutil.go b/pkg/utils/configutil/configutil.go index 48be7ff8c02..fe680879f73 100644 --- a/pkg/utils/configutil/configutil.go +++ b/pkg/utils/configutil/configutil.go @@ -21,8 +21,10 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/pingcap/errors" "github.com/spf13/pflag" + + "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" diff --git a/pkg/utils/etcdutil/etcdutil.go b/pkg/utils/etcdutil/etcdutil.go index 70beae943f8..3e9eaa765ab 100644 --- a/pkg/utils/etcdutil/etcdutil.go +++ b/pkg/utils/etcdutil/etcdutil.go @@ -24,13 +24,6 @@ import ( "time" "github.com/gogo/protobuf/proto" - "github.com/pingcap/errors" - "github.com/pingcap/failpoint" - "github.com/pingcap/log" - "github.com/tikv/pd/pkg/errs" - "github.com/tikv/pd/pkg/utils/grpcutil" - "github.com/tikv/pd/pkg/utils/logutil" - "github.com/tikv/pd/pkg/utils/syncutil" "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/mvccpb" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" @@ -39,6 +32,15 @@ import ( "go.etcd.io/etcd/server/v3/etcdserver" "go.uber.org/zap" "google.golang.org/grpc/codes" + + "github.com/pingcap/errors" + "github.com/pingcap/failpoint" + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" + "github.com/tikv/pd/pkg/utils/grpcutil" + "github.com/tikv/pd/pkg/utils/logutil" + "github.com/tikv/pd/pkg/utils/syncutil" ) const ( diff --git a/pkg/utils/etcdutil/etcdutil_test.go b/pkg/utils/etcdutil/etcdutil_test.go index 92ec8967d03..43c25539207 100644 --- a/pkg/utils/etcdutil/etcdutil_test.go +++ b/pkg/utils/etcdutil/etcdutil_test.go @@ -28,18 +28,20 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "github.com/tikv/pd/pkg/utils/syncutil" - "github.com/tikv/pd/pkg/utils/tempurl" - "github.com/tikv/pd/pkg/utils/testutil" "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/mvccpb" etcdtypes "go.etcd.io/etcd/client/pkg/v3/types" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/embed" "go.uber.org/goleak" + + "github.com/pingcap/failpoint" + + "github.com/tikv/pd/pkg/utils/syncutil" + "github.com/tikv/pd/pkg/utils/tempurl" + "github.com/tikv/pd/pkg/utils/testutil" ) func TestMain(m *testing.M) { diff --git a/pkg/utils/etcdutil/health_checker.go b/pkg/utils/etcdutil/health_checker.go index d75814ec380..eafb6293238 100644 --- a/pkg/utils/etcdutil/health_checker.go +++ b/pkg/utils/etcdutil/health_checker.go @@ -21,13 +21,15 @@ import ( "sync" "time" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/typeutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) const pickedCountThreshold = 3 diff --git a/pkg/utils/etcdutil/testutil.go b/pkg/utils/etcdutil/testutil.go index 7cb718664d9..daca4254467 100644 --- a/pkg/utils/etcdutil/testutil.go +++ b/pkg/utils/etcdutil/testutil.go @@ -22,11 +22,12 @@ import ( "time" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/utils/tempurl" - "github.com/tikv/pd/pkg/utils/testutil" "go.etcd.io/etcd/api/v3/etcdserverpb" clientv3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/server/v3/embed" + + "github.com/tikv/pd/pkg/utils/tempurl" + "github.com/tikv/pd/pkg/utils/testutil" ) // NewTestSingleConfig is used to create a etcd config for the unit test purpose. diff --git a/pkg/utils/grpcutil/grpcutil.go b/pkg/utils/grpcutil/grpcutil.go index 1d1e6478036..aea65dd32dd 100644 --- a/pkg/utils/grpcutil/grpcutil.go +++ b/pkg/utils/grpcutil/grpcutil.go @@ -23,10 +23,6 @@ import ( "strings" "time" - "github.com/pingcap/errors" - "github.com/pingcap/log" - "github.com/tikv/pd/pkg/errs" - "github.com/tikv/pd/pkg/utils/logutil" "go.etcd.io/etcd/client/pkg/v3/transport" "go.uber.org/zap" "google.golang.org/grpc" @@ -35,6 +31,12 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" + + "github.com/pingcap/errors" + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" + "github.com/tikv/pd/pkg/utils/logutil" ) const ( diff --git a/pkg/utils/grpcutil/grpcutil_test.go b/pkg/utils/grpcutil/grpcutil_test.go index fbcfe59f02c..db77a2e4002 100644 --- a/pkg/utils/grpcutil/grpcutil_test.go +++ b/pkg/utils/grpcutil/grpcutil_test.go @@ -7,10 +7,12 @@ import ( "path/filepath" "testing" - "github.com/pingcap/errors" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/errs" "google.golang.org/grpc/metadata" + + "github.com/pingcap/errors" + + "github.com/tikv/pd/pkg/errs" ) var ( diff --git a/pkg/utils/keypath/key_path.go b/pkg/utils/keypath/key_path.go index 4d59fafe16f..1a56ad3330a 100644 --- a/pkg/utils/keypath/key_path.go +++ b/pkg/utils/keypath/key_path.go @@ -370,20 +370,6 @@ func TimestampPath(tsPath string) string { return path.Join(tsPath, TimestampKey) } -// FullTimestampPath returns the full timestamp path. -// 1. for the default keyspace group: -// /pd/{cluster_id}/timestamp -// 2. for the non-default keyspace groups: -// /ms/{cluster_id}/tso/{group}/gta/timestamp -func FullTimestampPath(groupID uint32) string { - rootPath := TSOSvcRootPath() - tsPath := TimestampPath(KeyspaceGroupGlobalTSPath(groupID)) - if groupID == constant.DefaultKeyspaceGroupID { - rootPath = LegacyRootPath() - } - return path.Join(rootPath, tsPath) -} - const ( registryKey = "registry" ) diff --git a/pkg/utils/logutil/log.go b/pkg/utils/logutil/log.go index 4854fd7ac40..1620f9e3b70 100644 --- a/pkg/utils/logutil/log.go +++ b/pkg/utils/logutil/log.go @@ -21,10 +21,12 @@ import ( "strings" "sync/atomic" - "github.com/pingcap/log" - "github.com/tikv/pd/pkg/errs" "go.uber.org/zap" "go.uber.org/zap/zapcore" + + "github.com/pingcap/log" + + "github.com/tikv/pd/pkg/errs" ) // FileLogConfig serializes file log related config in toml/json. diff --git a/pkg/utils/metricutil/metricutil.go b/pkg/utils/metricutil/metricutil.go index 0d73c7678a8..32583248d5b 100644 --- a/pkg/utils/metricutil/metricutil.go +++ b/pkg/utils/metricutil/metricutil.go @@ -19,9 +19,11 @@ import ( "time" "unicode" - "github.com/pingcap/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/push" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/pkg/utils/metricutil/metricutil_test.go b/pkg/utils/metricutil/metricutil_test.go index a5c183abc20..33f322d516b 100644 --- a/pkg/utils/metricutil/metricutil_test.go +++ b/pkg/utils/metricutil/metricutil_test.go @@ -19,6 +19,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/typeutil" ) diff --git a/pkg/utils/operatorutil/operator_check.go b/pkg/utils/operatorutil/operator_check.go index 78b9e9d9bab..4e0d4332a45 100644 --- a/pkg/utils/operatorutil/operator_check.go +++ b/pkg/utils/operatorutil/operator_check.go @@ -16,6 +16,7 @@ package operatorutil import ( "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/schedule/operator" ) diff --git a/pkg/utils/tempurl/check_env_linux.go b/pkg/utils/tempurl/check_env_linux.go index 58f902f4bb7..7e3dffc105b 100644 --- a/pkg/utils/tempurl/check_env_linux.go +++ b/pkg/utils/tempurl/check_env_linux.go @@ -18,7 +18,9 @@ package tempurl import ( "github.com/cakturk/go-netstat/netstat" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" ) diff --git a/pkg/utils/tempurl/tempurl.go b/pkg/utils/tempurl/tempurl.go index fae6f90af91..4984bb57b23 100644 --- a/pkg/utils/tempurl/tempurl.go +++ b/pkg/utils/tempurl/tempurl.go @@ -23,6 +23,7 @@ import ( "time" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/utils/syncutil" ) diff --git a/pkg/utils/testutil/api_check.go b/pkg/utils/testutil/api_check.go index 0b714204500..3c5ffbdbe1e 100644 --- a/pkg/utils/testutil/api_check.go +++ b/pkg/utils/testutil/api_check.go @@ -20,6 +20,7 @@ import ( "net/http" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/utils/apiutil" ) diff --git a/pkg/utils/testutil/testutil.go b/pkg/utils/testutil/testutil.go index 363b3f14aef..89e706b6b63 100644 --- a/pkg/utils/testutil/testutil.go +++ b/pkg/utils/testutil/testutil.go @@ -21,11 +21,12 @@ import ( "sync" "time" - "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/pingcap/log" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" + + "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/pingcap/log" ) const ( diff --git a/pkg/utils/tsoutil/tso_dispatcher.go b/pkg/utils/tsoutil/tso_dispatcher.go index c4aa96274e1..be7d4fa6d83 100644 --- a/pkg/utils/tsoutil/tso_dispatcher.go +++ b/pkg/utils/tsoutil/tso_dispatcher.go @@ -20,15 +20,17 @@ import ( "sync" "time" + "github.com/prometheus/client_golang/prometheus" + "go.uber.org/zap" + "google.golang.org/grpc" + "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus" + "github.com/tikv/pd/pkg/errs" "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" ) const ( @@ -171,23 +173,23 @@ func (s *TSODispatcher) processRequests(forwardStream stream, requests []Request s.tsoProxyBatchSize.Observe(float64(count)) // Split the response ts := resp.GetTimestamp() - physical, logical, suffixBits := ts.GetPhysical(), ts.GetLogical(), ts.GetSuffixBits() + physical, logical := ts.GetPhysical(), ts.GetLogical() // `logical` is the largest ts's logical part here, we need to do the subtracting before we finish each TSO request. // This is different from the logic of client batch, for example, if we have a largest ts whose logical part is 10, // count is 5, then the splitting results should be 5 and 10. - firstLogical := addLogical(logical, -int64(count), suffixBits) - return s.finishRequest(requests, physical, firstLogical, suffixBits) + firstLogical := addLogical(logical, -int64(count)) + return s.finishRequest(requests, physical, firstLogical) } // Because of the suffix, we need to shift the count before we add it to the logical part. -func addLogical(logical, count int64, suffixBits uint32) int64 { - return logical + count< maxStoreLimit { - cmd.Printf("rate should less than %f for all\n", maxStoreLimit) + cmd.Printf("rate should be less than %.1f for all\n", maxStoreLimit) return } } else { @@ -594,7 +596,7 @@ func storeLimitCommandFunc(cmd *cobra.Command, args []string) { return } if rate > maxStoreLimit { - cmd.Printf("rate should less than %f for all\n", maxStoreLimit) + cmd.Printf("rate should be less than %.1f for all\n", maxStoreLimit) return } postInput["rate"] = rate diff --git a/tools/pd-ctl/pdctl/command/tso_command.go b/tools/pd-ctl/pdctl/command/tso_command.go index 689420854ee..7a4e8ec6d6e 100644 --- a/tools/pd-ctl/pdctl/command/tso_command.go +++ b/tools/pd-ctl/pdctl/command/tso_command.go @@ -18,6 +18,7 @@ import ( "strconv" "github.com/spf13/cobra" + "github.com/tikv/pd/pkg/utils/tsoutil" ) diff --git a/tools/pd-ctl/pdctl/ctl.go b/tools/pd-ctl/pdctl/ctl.go index 77f1601c8f5..e975bbf7a31 100644 --- a/tools/pd-ctl/pdctl/ctl.go +++ b/tools/pd-ctl/pdctl/ctl.go @@ -24,6 +24,7 @@ import ( shellwords "github.com/mattn/go-shellwords" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/tikv/pd/pkg/versioninfo" "github.com/tikv/pd/tools/pd-ctl/pdctl/command" ) diff --git a/tools/pd-ctl/tests/cluster/cluster_test.go b/tools/pd-ctl/tests/cluster/cluster_test.go index 46681da9319..8f087bdb094 100644 --- a/tools/pd-ctl/tests/cluster/cluster_test.go +++ b/tools/pd-ctl/tests/cluster/cluster_test.go @@ -21,8 +21,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + clusterpkg "github.com/tikv/pd/server/cluster" pdTests "github.com/tikv/pd/tests" ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" diff --git a/tools/pd-ctl/tests/completion/completion_test.go b/tools/pd-ctl/tests/completion/completion_test.go index cf4717a26aa..da043d2727d 100644 --- a/tools/pd-ctl/tests/completion/completion_test.go +++ b/tools/pd-ctl/tests/completion/completion_test.go @@ -18,6 +18,7 @@ import ( "testing" "github.com/stretchr/testify/require" + ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" ) diff --git a/tools/pd-ctl/tests/config/config_test.go b/tools/pd-ctl/tests/config/config_test.go index 6dc7e9fb269..cf9e4163457 100644 --- a/tools/pd-ctl/tests/config/config_test.go +++ b/tools/pd-ctl/tests/config/config_test.go @@ -26,10 +26,12 @@ import ( "time" "github.com/coreos/go-semver/semver" - "github.com/pingcap/failpoint" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/ratelimit" sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/schedule/placement" diff --git a/tools/pd-ctl/tests/global_test.go b/tools/pd-ctl/tests/global_test.go index 766e357088e..00987f2a8a1 100644 --- a/tools/pd-ctl/tests/global_test.go +++ b/tools/pd-ctl/tests/global_test.go @@ -21,8 +21,10 @@ import ( "net/http" "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/utils/apiutil" "github.com/tikv/pd/pkg/utils/assertutil" "github.com/tikv/pd/pkg/utils/testutil" diff --git a/tools/pd-ctl/tests/health/health_test.go b/tools/pd-ctl/tests/health/health_test.go index be9d5027988..c3b9e9979a4 100644 --- a/tools/pd-ctl/tests/health/health_test.go +++ b/tools/pd-ctl/tests/health/health_test.go @@ -24,6 +24,8 @@ import ( "testing" "github.com/stretchr/testify/require" + "go.etcd.io/etcd/client/pkg/v3/transport" + "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/server/api" "github.com/tikv/pd/server/cluster" @@ -31,7 +33,6 @@ import ( pdTests "github.com/tikv/pd/tests" ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" - "go.etcd.io/etcd/client/pkg/v3/transport" ) func TestHealth(t *testing.T) { diff --git a/tools/pd-ctl/tests/helper.go b/tools/pd-ctl/tests/helper.go index bdacae48c22..8e5963440ee 100644 --- a/tools/pd-ctl/tests/helper.go +++ b/tools/pd-ctl/tests/helper.go @@ -20,6 +20,7 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/response" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/tools/pd-ctl/tests/hot/hot_test.go b/tools/pd-ctl/tests/hot/hot_test.go index e12b6a39a60..d01f861d861 100644 --- a/tools/pd-ctl/tests/hot/hot_test.go +++ b/tools/pd-ctl/tests/hot/hot_test.go @@ -22,10 +22,12 @@ import ( "time" "github.com/docker/go-units" - "github.com/pingcap/kvproto/pkg/metapb" - "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/handler" "github.com/tikv/pd/pkg/statistics" diff --git a/tools/pd-ctl/tests/keyspace/keyspace_group_test.go b/tools/pd-ctl/tests/keyspace/keyspace_group_test.go index 9c16b0751f6..fca00f2fd3c 100644 --- a/tools/pd-ctl/tests/keyspace/keyspace_group_test.go +++ b/tools/pd-ctl/tests/keyspace/keyspace_group_test.go @@ -22,8 +22,10 @@ import ( "strings" "testing" - "github.com/pingcap/failpoint" "github.com/stretchr/testify/require" + + "github.com/pingcap/failpoint" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/utils/testutil" diff --git a/tools/pd-ctl/tests/keyspace/keyspace_test.go b/tools/pd-ctl/tests/keyspace/keyspace_test.go index 4aa3be1d21c..23a1148cd66 100644 --- a/tools/pd-ctl/tests/keyspace/keyspace_test.go +++ b/tools/pd-ctl/tests/keyspace/keyspace_test.go @@ -22,10 +22,12 @@ import ( "strings" "testing" - "github.com/pingcap/failpoint" - "github.com/pingcap/kvproto/pkg/keyspacepb" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/keyspacepb" + "github.com/tikv/pd/pkg/keyspace" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/testutil" diff --git a/tools/pd-ctl/tests/label/label_test.go b/tools/pd-ctl/tests/label/label_test.go index 057c9d9d9bb..b4fcbfc0e2d 100644 --- a/tools/pd-ctl/tests/label/label_test.go +++ b/tools/pd-ctl/tests/label/label_test.go @@ -21,8 +21,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/response" "github.com/tikv/pd/server/config" pdTests "github.com/tikv/pd/tests" diff --git a/tools/pd-ctl/tests/log/log_test.go b/tools/pd-ctl/tests/log/log_test.go index 274bc4ce7df..300b016f37b 100644 --- a/tools/pd-ctl/tests/log/log_test.go +++ b/tools/pd-ctl/tests/log/log_test.go @@ -19,8 +19,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + pdTests "github.com/tikv/pd/tests" ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" diff --git a/tools/pd-ctl/tests/member/member_test.go b/tools/pd-ctl/tests/member/member_test.go index dd3e465ae38..0f7d574945f 100644 --- a/tools/pd-ctl/tests/member/member_test.go +++ b/tools/pd-ctl/tests/member/member_test.go @@ -20,8 +20,10 @@ import ( "fmt" "testing" - "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/testutil" pdTests "github.com/tikv/pd/tests" diff --git a/tools/pd-ctl/tests/operator/operator_test.go b/tools/pd-ctl/tests/operator/operator_test.go index 91e97c66dbd..9e8c374ea49 100644 --- a/tools/pd-ctl/tests/operator/operator_test.go +++ b/tools/pd-ctl/tests/operator/operator_test.go @@ -22,8 +22,10 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/suite" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server/config" diff --git a/tools/pd-ctl/tests/region/region_test.go b/tools/pd-ctl/tests/region/region_test.go index 03a1c04ef19..06077a6184a 100644 --- a/tools/pd-ctl/tests/region/region_test.go +++ b/tools/pd-ctl/tests/region/region_test.go @@ -20,9 +20,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/response" "github.com/tikv/pd/server/api" diff --git a/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go b/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go index 3da72244215..ceab3b07ab7 100644 --- a/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go +++ b/tools/pd-ctl/tests/resourcemanager/resource_manager_command_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/suite" + "github.com/tikv/pd/pkg/mcs/resourcemanager/server" "github.com/tikv/pd/pkg/utils/typeutil" pdTests "github.com/tikv/pd/tests" diff --git a/tools/pd-ctl/tests/safepoint/safepoint_test.go b/tools/pd-ctl/tests/safepoint/safepoint_test.go index 9a9c54460bd..5a7ba8a2bc8 100644 --- a/tools/pd-ctl/tests/safepoint/safepoint_test.go +++ b/tools/pd-ctl/tests/safepoint/safepoint_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/server/api" pdTests "github.com/tikv/pd/tests" diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 3450e59d178..787bdaa4521 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -22,11 +22,13 @@ import ( "testing" "time" - "github.com/pingcap/failpoint" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/spf13/cobra" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + + "github.com/pingcap/failpoint" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/slice" diff --git a/tools/pd-ctl/tests/store/store_test.go b/tools/pd-ctl/tests/store/store_test.go index 6f704a25e8c..8ff36b79abe 100644 --- a/tools/pd-ctl/tests/store/store_test.go +++ b/tools/pd-ctl/tests/store/store_test.go @@ -24,8 +24,11 @@ import ( "testing" "time" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + "go.etcd.io/etcd/client/pkg/v3/transport" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/core/storelimit" "github.com/tikv/pd/pkg/response" @@ -35,7 +38,6 @@ import ( pdTests "github.com/tikv/pd/tests" ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" - "go.etcd.io/etcd/client/pkg/v3/transport" ) func TestStoreLimitV2(t *testing.T) { @@ -482,13 +484,13 @@ func TestStore(t *testing.T) { args = []string{"-u", pdAddr, "store", "limit", "all", "201"} output, err = tests.ExecuteCommand(cmd, args...) re.NoError(err) - re.Contains(string(output), "rate should less than") + re.Contains(string(output), "rate should be less than") // store limit all 201 is invalid for label args = []string{"-u", pdAddr, "store", "limit", "all", "engine", "key", "201", "add-peer"} output, err = tests.ExecuteCommand(cmd, args...) re.NoError(err) - re.Contains(string(output), "rate should less than") + re.Contains(string(output), "rate should be less than") } // https://github.com/tikv/pd/issues/5024 diff --git a/tools/pd-ctl/tests/tso/tso_test.go b/tools/pd-ctl/tests/tso/tso_test.go index 63816c40e7a..30fdda96438 100644 --- a/tools/pd-ctl/tests/tso/tso_test.go +++ b/tools/pd-ctl/tests/tso/tso_test.go @@ -21,6 +21,7 @@ import ( "time" "github.com/stretchr/testify/require" + ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" ) diff --git a/tools/pd-ctl/tests/unsafe/unsafe_operation_test.go b/tools/pd-ctl/tests/unsafe/unsafe_operation_test.go index da89749c2f2..652645e1570 100644 --- a/tools/pd-ctl/tests/unsafe/unsafe_operation_test.go +++ b/tools/pd-ctl/tests/unsafe/unsafe_operation_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/require" + pdTests "github.com/tikv/pd/tests" ctl "github.com/tikv/pd/tools/pd-ctl/pdctl" "github.com/tikv/pd/tools/pd-ctl/tests" diff --git a/tools/pd-heartbeat-bench/config/config.go b/tools/pd-heartbeat-bench/config/config.go index dc5a2a6a047..41c14845074 100644 --- a/tools/pd-heartbeat-bench/config/config.go +++ b/tools/pd-heartbeat-bench/config/config.go @@ -4,11 +4,13 @@ import ( "sync/atomic" "github.com/BurntSushi/toml" + flag "github.com/spf13/pflag" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/log" - flag "github.com/spf13/pflag" + "github.com/tikv/pd/pkg/utils/configutil" - "go.uber.org/zap" ) const ( diff --git a/tools/pd-heartbeat-bench/main.go b/tools/pd-heartbeat-bench/main.go index 7150c81537a..60b1db6734d 100644 --- a/tools/pd-heartbeat-bench/main.go +++ b/tools/pd-heartbeat-bench/main.go @@ -34,11 +34,15 @@ import ( "github.com/gin-contrib/gzip" "github.com/gin-contrib/pprof" "github.com/gin-gonic/gin" + "github.com/spf13/pflag" + "go.etcd.io/etcd/pkg/v3/report" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" - "github.com/spf13/pflag" + pdHttp "github.com/tikv/pd/client/http" "github.com/tikv/pd/client/pkg/utils/grpcutil" "github.com/tikv/pd/client/pkg/utils/tlsutil" @@ -48,8 +52,6 @@ import ( "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/tools/pd-heartbeat-bench/config" "github.com/tikv/pd/tools/pd-heartbeat-bench/metrics" - "go.etcd.io/etcd/pkg/v3/report" - "go.uber.org/zap" ) const ( diff --git a/tools/pd-heartbeat-bench/metrics/util.go b/tools/pd-heartbeat-bench/metrics/util.go index 9a61feee420..5e709630e27 100644 --- a/tools/pd-heartbeat-bench/metrics/util.go +++ b/tools/pd-heartbeat-bench/metrics/util.go @@ -22,12 +22,13 @@ import ( "strings" "time" - "github.com/pingcap/log" "github.com/prometheus/client_golang/api" v1 "github.com/prometheus/client_golang/api/prometheus/v1" "github.com/prometheus/common/model" "go.etcd.io/etcd/pkg/v3/report" "go.uber.org/zap" + + "github.com/pingcap/log" ) var ( diff --git a/tools/pd-recover/main.go b/tools/pd-recover/main.go index 3423d06bb9f..bd5ebf76d74 100644 --- a/tools/pd-recover/main.go +++ b/tools/pd-recover/main.go @@ -24,12 +24,14 @@ import ( "strings" "time" + "go.etcd.io/etcd/client/pkg/v3/transport" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/typeutil" "github.com/tikv/pd/pkg/versioninfo" - "go.etcd.io/etcd/client/pkg/v3/transport" - clientv3 "go.etcd.io/etcd/client/v3" ) var ( diff --git a/tools/pd-simulator/main.go b/tools/pd-simulator/main.go index 609ed3b06e0..59a58f0a00b 100644 --- a/tools/pd-simulator/main.go +++ b/tools/pd-simulator/main.go @@ -23,8 +23,11 @@ import ( "time" "github.com/BurntSushi/toml" - "github.com/pingcap/log" flag "github.com/spf13/pflag" + "go.uber.org/zap" + + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/schedule/schedulers" "github.com/tikv/pd/pkg/statistics" "github.com/tikv/pd/pkg/utils/logutil" @@ -37,7 +40,6 @@ import ( "github.com/tikv/pd/tools/pd-simulator/simulator/cases" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) var ( diff --git a/tools/pd-simulator/simulator/cases/balance_leader.go b/tools/pd-simulator/simulator/cases/balance_leader.go index a6790548dc1..f0ed73a4a9c 100644 --- a/tools/pd-simulator/simulator/cases/balance_leader.go +++ b/tools/pd-simulator/simulator/cases/balance_leader.go @@ -16,7 +16,9 @@ package cases import ( "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/balance_region.go b/tools/pd-simulator/simulator/cases/balance_region.go index d4ef7ad986f..8c7bbbe19d8 100644 --- a/tools/pd-simulator/simulator/cases/balance_region.go +++ b/tools/pd-simulator/simulator/cases/balance_region.go @@ -18,6 +18,7 @@ import ( "time" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/cases.go b/tools/pd-simulator/simulator/cases/cases.go index 026e095342b..c1de896074f 100644 --- a/tools/pd-simulator/simulator/cases/cases.go +++ b/tools/pd-simulator/simulator/cases/cases.go @@ -16,6 +16,7 @@ package cases import ( "github.com/pingcap/kvproto/pkg/metapb" + pdHttp "github.com/tikv/pd/client/http" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/typeutil" diff --git a/tools/pd-simulator/simulator/cases/diagnose_label_isolation.go b/tools/pd-simulator/simulator/cases/diagnose_label_isolation.go index 8e65feefea4..06e0582f5f8 100644 --- a/tools/pd-simulator/simulator/cases/diagnose_label_isolation.go +++ b/tools/pd-simulator/simulator/cases/diagnose_label_isolation.go @@ -19,12 +19,14 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) func newLabelNotMatch1(_ *sc.SimConfig) *Case { diff --git a/tools/pd-simulator/simulator/cases/diagnose_rule.go b/tools/pd-simulator/simulator/cases/diagnose_rule.go index 4e7031a3a01..d1a8350dbbc 100644 --- a/tools/pd-simulator/simulator/cases/diagnose_rule.go +++ b/tools/pd-simulator/simulator/cases/diagnose_rule.go @@ -18,14 +18,16 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" + pdHttp "github.com/tikv/pd/client/http" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/schedule/placement" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) func newRule1(_ *sc.SimConfig) *Case { diff --git a/tools/pd-simulator/simulator/cases/hot_read.go b/tools/pd-simulator/simulator/cases/hot_read.go index 22ff70d9312..87637063385 100644 --- a/tools/pd-simulator/simulator/cases/hot_read.go +++ b/tools/pd-simulator/simulator/cases/hot_read.go @@ -18,7 +18,9 @@ import ( "fmt" "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/hot_write.go b/tools/pd-simulator/simulator/cases/hot_write.go index adb6eb0756a..43494324936 100644 --- a/tools/pd-simulator/simulator/cases/hot_write.go +++ b/tools/pd-simulator/simulator/cases/hot_write.go @@ -18,7 +18,9 @@ import ( "fmt" "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/import_data.go b/tools/pd-simulator/simulator/cases/import_data.go index 3d329081f9e..c06e9e7dd44 100644 --- a/tools/pd-simulator/simulator/cases/import_data.go +++ b/tools/pd-simulator/simulator/cases/import_data.go @@ -21,14 +21,16 @@ import ( "github.com/docker/go-units" "github.com/go-echarts/go-echarts/charts" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) func newImportData(config *sc.SimConfig) *Case { diff --git a/tools/pd-simulator/simulator/cases/makeup_down_replica.go b/tools/pd-simulator/simulator/cases/makeup_down_replica.go index ec664e91254..d5a5021b8cf 100644 --- a/tools/pd-simulator/simulator/cases/makeup_down_replica.go +++ b/tools/pd-simulator/simulator/cases/makeup_down_replica.go @@ -16,7 +16,9 @@ package cases import ( "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/region_merge.go b/tools/pd-simulator/simulator/cases/region_merge.go index 9a278c851bd..8f19f375c8e 100644 --- a/tools/pd-simulator/simulator/cases/region_merge.go +++ b/tools/pd-simulator/simulator/cases/region_merge.go @@ -16,7 +16,9 @@ package cases import ( "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/region_split.go b/tools/pd-simulator/simulator/cases/region_split.go index 8c1f3ac7759..8299cbdf136 100644 --- a/tools/pd-simulator/simulator/cases/region_split.go +++ b/tools/pd-simulator/simulator/cases/region_split.go @@ -16,7 +16,9 @@ package cases import ( "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/scale_tikv.go b/tools/pd-simulator/simulator/cases/scale_tikv.go index 9cfe8d9dcad..49dc70e64fb 100644 --- a/tools/pd-simulator/simulator/cases/scale_tikv.go +++ b/tools/pd-simulator/simulator/cases/scale_tikv.go @@ -16,6 +16,7 @@ package cases import ( "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/cases/stable_env.go b/tools/pd-simulator/simulator/cases/stable_env.go index 54a9f84341f..0a0c72698d8 100644 --- a/tools/pd-simulator/simulator/cases/stable_env.go +++ b/tools/pd-simulator/simulator/cases/stable_env.go @@ -16,7 +16,9 @@ package cases import ( "github.com/docker/go-units" + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" diff --git a/tools/pd-simulator/simulator/client.go b/tools/pd-simulator/simulator/client.go index 4de2ea52f88..4c84d308af7 100644 --- a/tools/pd-simulator/simulator/client.go +++ b/tools/pd-simulator/simulator/client.go @@ -23,18 +23,20 @@ import ( "sync/atomic" "time" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + pdHttp "github.com/tikv/pd/client/http" sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/typeutil" sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" ) // Client is a PD (Placement Driver) client. diff --git a/tools/pd-simulator/simulator/config/config.go b/tools/pd-simulator/simulator/config/config.go index ece3b6fd91f..ead9e50e6af 100644 --- a/tools/pd-simulator/simulator/config/config.go +++ b/tools/pd-simulator/simulator/config/config.go @@ -21,6 +21,7 @@ import ( "github.com/BurntSushi/toml" "github.com/docker/go-units" + pdHttp "github.com/tikv/pd/client/http" sc "github.com/tikv/pd/pkg/schedule/config" "github.com/tikv/pd/pkg/utils/configutil" diff --git a/tools/pd-simulator/simulator/conn.go b/tools/pd-simulator/simulator/conn.go index b1000c0f17b..332f46eb573 100644 --- a/tools/pd-simulator/simulator/conn.go +++ b/tools/pd-simulator/simulator/conn.go @@ -16,6 +16,7 @@ package simulator import ( "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/tools/pd-simulator/simulator/cases" "github.com/tikv/pd/tools/pd-simulator/simulator/config" ) diff --git a/tools/pd-simulator/simulator/drive.go b/tools/pd-simulator/simulator/drive.go index c8c325cfca6..0d81a2af1ab 100644 --- a/tools/pd-simulator/simulator/drive.go +++ b/tools/pd-simulator/simulator/drive.go @@ -26,10 +26,14 @@ import ( "sync/atomic" "time" + "github.com/prometheus/client_golang/prometheus/promhttp" + clientv3 "go.etcd.io/etcd/client/v3" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" - "github.com/prometheus/client_golang/prometheus/promhttp" + pdHttp "github.com/tikv/pd/client/http" sd "github.com/tikv/pd/client/servicediscovery" "github.com/tikv/pd/pkg/core" @@ -38,8 +42,6 @@ import ( "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - clientv3 "go.etcd.io/etcd/client/v3" - "go.uber.org/zap" ) // Driver promotes the cluster status change. diff --git a/tools/pd-simulator/simulator/event.go b/tools/pd-simulator/simulator/event.go index d22f35756ef..719e12f5fea 100644 --- a/tools/pd-simulator/simulator/event.go +++ b/tools/pd-simulator/simulator/event.go @@ -22,12 +22,14 @@ import ( "strconv" "sync" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/tools/pd-simulator/simulator/cases" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) // Event affects the status of the cluster. diff --git a/tools/pd-simulator/simulator/node.go b/tools/pd-simulator/simulator/node.go index 59b0d393c47..edacf5c4129 100644 --- a/tools/pd-simulator/simulator/node.go +++ b/tools/pd-simulator/simulator/node.go @@ -22,8 +22,11 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/ratelimit" "github.com/tikv/pd/pkg/utils/syncutil" @@ -32,7 +35,6 @@ import ( sc "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/info" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) const ( diff --git a/tools/pd-simulator/simulator/raft.go b/tools/pd-simulator/simulator/raft.go index 7f3bf78622f..13371cefdb8 100644 --- a/tools/pd-simulator/simulator/raft.go +++ b/tools/pd-simulator/simulator/raft.go @@ -17,14 +17,16 @@ package simulator import ( "context" + "go.uber.org/zap" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/syncutil" "github.com/tikv/pd/tools/pd-simulator/simulator/cases" "github.com/tikv/pd/tools/pd-simulator/simulator/config" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) // RaftEngine records all raft information. diff --git a/tools/pd-simulator/simulator/simutil/key.go b/tools/pd-simulator/simulator/simutil/key.go index a095f9d567b..ba1a19382ed 100644 --- a/tools/pd-simulator/simulator/simutil/key.go +++ b/tools/pd-simulator/simulator/simutil/key.go @@ -18,6 +18,7 @@ import ( "bytes" "github.com/pingcap/errors" + "github.com/tikv/pd/pkg/codec" ) diff --git a/tools/pd-simulator/simulator/simutil/key_test.go b/tools/pd-simulator/simulator/simutil/key_test.go index be07037501f..23cc0720b6b 100644 --- a/tools/pd-simulator/simulator/simutil/key_test.go +++ b/tools/pd-simulator/simulator/simutil/key_test.go @@ -17,8 +17,10 @@ package simutil import ( "testing" - "github.com/pingcap/kvproto/pkg/metapb" "github.com/stretchr/testify/require" + + "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/codec" "github.com/tikv/pd/pkg/core" ) diff --git a/tools/pd-simulator/simulator/simutil/logger.go b/tools/pd-simulator/simulator/simutil/logger.go index e22124f00a5..08bd0e0461f 100644 --- a/tools/pd-simulator/simulator/simutil/logger.go +++ b/tools/pd-simulator/simulator/simutil/logger.go @@ -15,8 +15,9 @@ package simutil import ( - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) // Logger is the global logger used for simulator. diff --git a/tools/pd-simulator/simulator/task.go b/tools/pd-simulator/simulator/task.go index 0921838c70b..187f08fec68 100644 --- a/tools/pd-simulator/simulator/task.go +++ b/tools/pd-simulator/simulator/task.go @@ -21,13 +21,15 @@ import ( "time" "github.com/docker/go-units" + "go.uber.org/zap" + "github.com/pingcap/kvproto/pkg/eraftpb" "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/tools/pd-analysis/analysis" "github.com/tikv/pd/tools/pd-simulator/simulator/simutil" - "go.uber.org/zap" ) const ( diff --git a/tools/pd-tso-bench/main.go b/tools/pd-tso-bench/main.go index ccb68a1c5fb..cd710470db5 100644 --- a/tools/pd-tso-bench/main.go +++ b/tools/pd-tso-bench/main.go @@ -29,15 +29,17 @@ import ( "time" "github.com/influxdata/tdigest" + "github.com/prometheus/client_golang/prometheus/promhttp" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" + "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/prometheus/client_golang/prometheus/promhttp" + pd "github.com/tikv/pd/client" "github.com/tikv/pd/client/opt" "github.com/tikv/pd/client/pkg/caller" - "go.uber.org/zap" - "google.golang.org/grpc" - "google.golang.org/grpc/keepalive" ) const ( diff --git a/tools/pd-ut/alloc/check_env_linux.go b/tools/pd-ut/alloc/check_env_linux.go index 1a51f8075cf..c4d20bf6a65 100644 --- a/tools/pd-ut/alloc/check_env_linux.go +++ b/tools/pd-ut/alloc/check_env_linux.go @@ -18,8 +18,9 @@ package alloc import ( "github.com/cakturk/go-netstat/netstat" - "github.com/pingcap/log" "go.uber.org/zap" + + "github.com/pingcap/log" ) func environmentCheck(addr string) bool { diff --git a/tools/pd-ut/alloc/server.go b/tools/pd-ut/alloc/server.go index ffa3bce0aa5..6e7aeeb6307 100644 --- a/tools/pd-ut/alloc/server.go +++ b/tools/pd-ut/alloc/server.go @@ -23,9 +23,11 @@ import ( "time" "github.com/gin-gonic/gin" + "go.uber.org/zap" + "github.com/pingcap/log" + "github.com/tikv/pd/pkg/utils/tempurl" - "go.uber.org/zap" ) var statusAddress = flag.String("status-addr", "0.0.0.0:0", "status address") diff --git a/tools/pd-ut/alloc/tempurl.go b/tools/pd-ut/alloc/tempurl.go index 2131699133a..c7492064ac2 100644 --- a/tools/pd-ut/alloc/tempurl.go +++ b/tools/pd-ut/alloc/tempurl.go @@ -21,6 +21,7 @@ import ( "time" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/errs" ) diff --git a/tools/pd-ut/ut.go b/tools/pd-ut/ut.go index 7bb0cf17e9f..8efacf5933a 100644 --- a/tools/pd-ut/ut.go +++ b/tools/pd-ut/ut.go @@ -33,9 +33,10 @@ import ( "sync" "time" - "github.com/tikv/pd/tools/pd-ut/alloc" "go.uber.org/zap" + "github.com/tikv/pd/tools/pd-ut/alloc" + // Set the correct value when it runs inside docker. _ "go.uber.org/automaxprocs" ) diff --git a/tools/regions-dump/main.go b/tools/regions-dump/main.go index 5ae4241cdc0..58d19ce72f2 100644 --- a/tools/regions-dump/main.go +++ b/tools/regions-dump/main.go @@ -25,12 +25,14 @@ import ( "strings" "time" + "go.etcd.io/etcd/client/pkg/v3/transport" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/core" "github.com/tikv/pd/pkg/utils/etcdutil" - "go.etcd.io/etcd/client/pkg/v3/transport" - clientv3 "go.etcd.io/etcd/client/v3" ) var ( diff --git a/tools/stores-dump/main.go b/tools/stores-dump/main.go index 0409244772f..0815c6e7113 100644 --- a/tools/stores-dump/main.go +++ b/tools/stores-dump/main.go @@ -25,11 +25,13 @@ import ( "strings" "time" + "go.etcd.io/etcd/client/pkg/v3/transport" + clientv3 "go.etcd.io/etcd/client/v3" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/metapb" + "github.com/tikv/pd/pkg/utils/etcdutil" - "go.etcd.io/etcd/client/pkg/v3/transport" - clientv3 "go.etcd.io/etcd/client/v3" ) var (