diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 516a466c91e..ab8d9ff9915 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -1,6 +1,6 @@ # Sort the member alphabetically. aliases: sig-critical-approvers-config: - - easonn7 - - kevin-xianliu + - BenMeadowcroft - niubell + - yudongusa diff --git a/client/resource_group/controller/controller.go b/client/resource_group/controller/controller.go index e5ad1f81fa5..6cb7995a42e 100644 --- a/client/resource_group/controller/controller.go +++ b/client/resource_group/controller/controller.go @@ -249,16 +249,13 @@ func (c *ResourceGroupsController) Start(ctx context.Context) { defer emergencyTokenAcquisitionTicker.Stop() failpoint.Inject("fastCleanup", func() { - cleanupTicker.Stop() - cleanupTicker = time.NewTicker(100 * time.Millisecond) + cleanupTicker.Reset(100 * time.Millisecond) // because of checking `gc.run.consumption` in cleanupTicker, // so should also change the stateUpdateTicker. - stateUpdateTicker.Stop() - stateUpdateTicker = time.NewTicker(200 * time.Millisecond) + stateUpdateTicker.Reset(200 * time.Millisecond) }) failpoint.Inject("acceleratedReportingPeriod", func() { - stateUpdateTicker.Stop() - stateUpdateTicker = time.NewTicker(time.Millisecond * 100) + stateUpdateTicker.Reset(time.Millisecond * 100) }) _, metaRevision, err := c.provider.LoadResourceGroups(ctx) diff --git a/client/tlsutil/tlsconfig.go b/client/tlsutil/tlsconfig.go index 5bf03dc4afc..88d797d3b3a 100644 --- a/client/tlsutil/tlsconfig.go +++ b/client/tlsutil/tlsconfig.go @@ -43,20 +43,20 @@ import ( "github.com/tikv/pd/client/errs" ) -// TLSInfo stores tls configuration to connect to etcd. -type TLSInfo struct { - CertFile string - KeyFile string - TrustedCAFile string - InsecureSkipVerify bool +// tlsInfo stores tls configuration to connect to etcd. +type tlsInfo struct { + certFile string + keyFile string + trustedCAFile string + insecureSkipVerify bool - // ServerName ensures the cert matches the given host in case of discovery / virtual hosting - ServerName string + // serverName ensures the cert matches the given host in case of discovery / virtual hosting + serverName string - // CipherSuites is a list of supported cipher suites. + // cipherSuites is a list of supported cipher suites. // If empty, Go auto-populates it by default. // Note that cipher suites are prioritized in the given order. - CipherSuites []uint16 + cipherSuites []uint16 selfCert bool @@ -64,24 +64,24 @@ type TLSInfo struct { // should be left nil. In that case, tls.X509KeyPair will be used. parseFunc func([]byte, []byte) (tls.Certificate, error) - // AllowedCN is a CN which must be provided by a client. - AllowedCN string + // allowedCNs is a list of CNs which must be provided by a client. + allowedCNs []string } -// ClientConfig generates a tls.Config object for use by an HTTP client. -func (info TLSInfo) ClientConfig() (*tls.Config, error) { +// clientConfig generates a tls.Config object for use by an HTTP client. +func (info tlsInfo) clientConfig() (*tls.Config, error) { var cfg *tls.Config var err error - if !info.Empty() { + if !info.empty() { cfg, err = info.baseConfig() if err != nil { return nil, err } } else { - cfg = &tls.Config{ServerName: info.ServerName} + cfg = &tls.Config{ServerName: info.serverName} } - cfg.InsecureSkipVerify = info.InsecureSkipVerify + cfg.InsecureSkipVerify = info.insecureSkipVerify CAFiles := info.cafiles() if len(CAFiles) > 0 { @@ -97,36 +97,38 @@ func (info TLSInfo) ClientConfig() (*tls.Config, error) { return cfg, nil } -// Empty returns if the TLSInfo is unset. -func (info TLSInfo) Empty() bool { - return info.CertFile == "" && info.KeyFile == "" +// empty returns if the TLSInfo is unset. +func (info tlsInfo) empty() bool { + return info.certFile == "" && info.keyFile == "" } -func (info TLSInfo) baseConfig() (*tls.Config, error) { - if info.KeyFile == "" || info.CertFile == "" { - return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.KeyFile, info.CertFile) +func (info tlsInfo) baseConfig() (*tls.Config, error) { + if info.keyFile == "" || info.certFile == "" { + return nil, fmt.Errorf("KeyFile and CertFile must both be present[key: %v, cert: %v]", info.keyFile, info.certFile) } - _, err := NewCert(info.CertFile, info.KeyFile, info.parseFunc) + _, err := NewCert(info.certFile, info.keyFile, info.parseFunc) if err != nil { return nil, err } cfg := &tls.Config{ MinVersion: tls.VersionTLS12, - ServerName: info.ServerName, + ServerName: info.serverName, } - if len(info.CipherSuites) > 0 { - cfg.CipherSuites = info.CipherSuites + if len(info.cipherSuites) > 0 { + cfg.CipherSuites = info.cipherSuites } - if info.AllowedCN != "" { + if len(info.allowedCNs) > 0 { cfg.VerifyPeerCertificate = func(_ [][]byte, verifiedChains [][]*x509.Certificate) error { for _, chains := range verifiedChains { if len(chains) != 0 { - if info.AllowedCN == chains[0].Subject.CommonName { - return nil + for _, allowedCN := range info.allowedCNs { + if allowedCN == chains[0].Subject.CommonName { + return nil + } } } } @@ -137,19 +139,19 @@ func (info TLSInfo) baseConfig() (*tls.Config, error) { // this only reloads certs when there's a client request // TODO: support server-side refresh (e.g. inotify, SIGHUP), caching cfg.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) { - return NewCert(info.CertFile, info.KeyFile, info.parseFunc) + return NewCert(info.certFile, info.keyFile, info.parseFunc) } cfg.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) { - return NewCert(info.CertFile, info.KeyFile, info.parseFunc) + return NewCert(info.certFile, info.keyFile, info.parseFunc) } return cfg, nil } // cafiles returns a list of CA file paths. -func (info TLSInfo) cafiles() []string { +func (info tlsInfo) cafiles() []string { cs := make([]string, 0) - if info.TrustedCAFile != "" { - cs = append(cs, info.TrustedCAFile) + if info.trustedCAFile != "" { + cs = append(cs, info.trustedCAFile) } return cs } @@ -162,8 +164,8 @@ type TLSConfig struct { CertPath string `toml:"cert-path" json:"cert-path"` // KeyPath is the path of file that contains X509 key in PEM format. KeyPath string `toml:"key-path" json:"key-path"` - // CertAllowedCN is a CN which must be provided by a client - CertAllowedCN []string `toml:"cert-allowed-cn" json:"cert-allowed-cn"` + // CertAllowedCNs is the list of CN which must be provided by a client + CertAllowedCNs []string `toml:"cert-allowed-cn" json:"cert-allowed-cn"` SSLCABytes []byte SSLCertBytes []byte @@ -194,33 +196,17 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) { if len(s.CertPath) == 0 && len(s.KeyPath) == 0 { return nil, nil } - allowedCN, err := s.GetOneAllowedCN() - if err != nil { - return nil, err - } - tlsInfo := TLSInfo{ - CertFile: s.CertPath, - KeyFile: s.KeyPath, - TrustedCAFile: s.CAPath, - AllowedCN: allowedCN, + tlsInfo := tlsInfo{ + certFile: s.CertPath, + keyFile: s.KeyPath, + trustedCAFile: s.CAPath, + allowedCNs: s.CertAllowedCNs, } - tlsConfig, err := tlsInfo.ClientConfig() + tlsConfig, err := tlsInfo.clientConfig() if err != nil { return nil, errs.ErrEtcdTLSConfig.Wrap(err).GenWithStackByCause() } return tlsConfig, nil } - -// GetOneAllowedCN only gets the first one CN. -func (s TLSConfig) GetOneAllowedCN() (string, error) { - switch len(s.CertAllowedCN) { - case 1: - return s.CertAllowedCN[0], nil - case 0: - return "", nil - default: - return "", errs.ErrSecurityConfig.FastGenByArgs("only supports one CN") - } -} diff --git a/conf/config.toml b/conf/config.toml index f2feacf30f7..a4adc9c7d66 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -204,6 +204,9 @@ ## When enabled, usage data will be sent to PingCAP for improving user experience. # enable-telemetry = false +## When enabled, configuring a custom prometheus address through Dashboard will not be allowed. +# disable-custom-prom-addr = false + [keyspace] ## pre-alloc is used to pre-allocate keyspaces during pd bootstrap. ## Its value should be a list of strings, denoting the name of the keyspaces. diff --git a/go.mod b/go.mod index 79db4f3940c..aa01f33c46b 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/coreos/go-semver v0.3.1 github.com/docker/go-units v0.4.0 github.com/elliotchance/pie/v2 v2.1.0 - github.com/gin-contrib/cors v1.4.0 + github.com/gin-contrib/cors v1.6.0 github.com/gin-contrib/gzip v0.0.1 github.com/gin-contrib/pprof v1.4.0 github.com/gin-gonic/gin v1.9.1 @@ -37,7 +37,7 @@ require ( github.com/pingcap/kvproto v0.0.0-20240716095229-5f7ffec83ea7 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-20240815045040-4d89bc193a0c + github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c github.com/prometheus/client_golang v1.19.0 github.com/prometheus/common v0.51.1 github.com/sasha-s/go-deadlock v0.2.0 @@ -85,10 +85,11 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bitly/go-simplejson v0.5.0 // indirect github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -97,7 +98,7 @@ require ( github.com/fatih/color v1.10.0 // indirect github.com/fogleman/gg v1.3.0 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-logr/logr v1.3.0 // indirect @@ -109,7 +110,7 @@ require ( github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/goccy/go-graphviz v0.1.3 // indirect @@ -135,18 +136,18 @@ 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/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // 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 github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect 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/oleiade/reflections v1.0.1 // indirect github.com/onsi/gomega v1.20.1 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e // indirect github.com/pkg/errors v0.9.1 // indirect @@ -168,7 +169,7 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect github.com/urfave/cli/v2 v2.3.0 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect @@ -190,7 +191,7 @@ require ( go.uber.org/dig v1.9.0 // indirect go.uber.org/fx v1.12.0 // indirect go.uber.org/multierr v1.11.0 - golang.org/x/arch v0.3.0 // indirect + golang.org/x/arch v0.7.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/image v0.18.0 // indirect golang.org/x/mod v0.17.0 // indirect diff --git a/go.sum b/go.sum index e57fdcbce9c..3dbb14b53b1 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,9 @@ github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTo github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8= github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= 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/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= @@ -78,8 +79,12 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA 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/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= +github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= 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= @@ -125,12 +130,12 @@ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzP github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= -github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= +github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg= +github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro= github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= @@ -175,8 +180,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= +github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -305,8 +310,9 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV 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/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +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= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -319,8 +325,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 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.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= @@ -333,8 +339,8 @@ github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE= @@ -369,8 +375,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9 github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -394,8 +400,8 @@ github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8 github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 h1:QV6jqlfOkh8hqvEAgwBZa+4bSgO0EeKC7s5c6Luam2I= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21/go.mod h1:QYnjfA95ZaMefyl1NO8oPtKeb8pYUdnDVhQgf+qdpjM= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c h1:iiVpATdlLLr0NEgKZu+ZnBuYR4J8IgjNE1hNMjMOkYY= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c h1:+0Tl9izTX2X5cy4wO4cbvjjsg8LqKpHdH5bEMv7pTb4= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e h1:FBaTXU8C3xgt/drM58VHxojHo/QoG1oPsgWTGvaSpO4= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -474,7 +480,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM= @@ -510,8 +515,8 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6 github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/unrolled/render v1.0.1 h1:VDDnQQVfBMsOsp3VaCJszSO0nkBIVEYoPWeRThk9spY= github.com/unrolled/render v1.0.1/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= @@ -593,8 +598,8 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= +golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -689,10 +694,10 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc 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-20220704084225-05e143d24a9e/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= @@ -822,6 +827,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= moul.io/zapgorm2 v1.1.0 h1:qwAlMBYf+qJkJ7PAzJl4oCe6eS6QGiKAXUPeis0+RBE= moul.io/zapgorm2 v1.1.0/go.mod h1:emRfKjNqSzVj5lcgasBdovIXY1jSOwFz2GQZn1Rddks= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/pkg/dashboard/adapter/config.go b/pkg/dashboard/adapter/config.go index 348b146c854..cf79690e73b 100644 --- a/pkg/dashboard/adapter/config.go +++ b/pkg/dashboard/adapter/config.go @@ -35,6 +35,7 @@ func GenDashboardConfig(srv *server.Server) (*config.Config, error) { dashboardCfg.PublicPathPrefix = cfg.Dashboard.PublicPathPrefix dashboardCfg.EnableTelemetry = cfg.Dashboard.EnableTelemetry dashboardCfg.EnableExperimental = cfg.Dashboard.EnableExperimental + dashboardCfg.DisableCustomPromAddr = cfg.Dashboard.DisableCustomPromAddr if dashboardCfg.ClusterTLSConfig, err = cfg.Security.ToTLSConfig(); err != nil { return nil, err } diff --git a/pkg/keyspace/tso_keyspace_group.go b/pkg/keyspace/tso_keyspace_group.go index 5d7137ac3c2..f1ed6002a8c 100644 --- a/pkg/keyspace/tso_keyspace_group.go +++ b/pkg/keyspace/tso_keyspace_group.go @@ -162,8 +162,7 @@ func (m *GroupManager) allocNodesToAllKeyspaceGroups(ctx context.Context) { defer m.wg.Done() ticker := time.NewTicker(allocNodesToKeyspaceGroupsInterval) failpoint.Inject("acceleratedAllocNodes", func() { - ticker.Stop() - ticker = time.NewTicker(time.Millisecond * 100) + ticker.Reset(time.Millisecond * 100) }) defer ticker.Stop() log.Info("start to alloc nodes to all keyspace groups") diff --git a/pkg/mcs/metastorage/server/grpc_service.go b/pkg/mcs/metastorage/server/grpc_service.go index 4f43114ea29..c0037353437 100644 --- a/pkg/mcs/metastorage/server/grpc_service.go +++ b/pkg/mcs/metastorage/server/grpc_service.go @@ -71,9 +71,9 @@ func (s *Service) RegisterGRPCService(g *grpc.Server) { } // RegisterRESTHandler registers the service to REST server. -func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) error { - handler, group := SetUpRestHandler(s) - return apiutil.RegisterUserDefinedHandlers(userDefineHandlers, &group, handler) +func (*Service) RegisterRESTHandler(_ map[string]http.Handler) error { + // restful API is not implemented yet. + return nil } func (s *Service) checkServing() error { diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 58b8b5426a4..dd7151a8b05 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -324,8 +324,7 @@ func (m *Manager) GetResourceGroupList(withStats bool) []*ResourceGroup { func (m *Manager) persistLoop(ctx context.Context) { ticker := time.NewTicker(time.Minute) failpoint.Inject("fastPersist", func() { - ticker.Stop() - ticker = time.NewTicker(100 * time.Millisecond) + ticker.Reset(100 * time.Millisecond) }) defer ticker.Stop() for { @@ -477,9 +476,9 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) { ru = 0 } availableRUCounter.WithLabelValues(group.Name, group.Name).Set(ru) - resourceGroupConfigGauge.WithLabelValues(group.Name, priorityLabel).Set(float64(group.Priority)) - resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSecLabel).Set(float64(group.RUSettings.RU.Settings.FillRate)) - resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacityLabel).Set(float64(group.RUSettings.RU.Settings.BurstLimit)) + resourceGroupConfigGauge.WithLabelValues(group.Name, priorityLabel).Set(group.getPriority()) + resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSecLabel).Set(group.getFillRate()) + resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacityLabel).Set(group.getBurstLimit()) } case <-recordMaxTicker.C: // Record the sum of RRU and WRU every second. diff --git a/pkg/mcs/resourcemanager/server/resource_group.go b/pkg/mcs/resourcemanager/server/resource_group.go index cb76a98327a..6a5d06da6f7 100644 --- a/pkg/mcs/resourcemanager/server/resource_group.go +++ b/pkg/mcs/resourcemanager/server/resource_group.go @@ -108,6 +108,24 @@ func (rg *ResourceGroup) getRUToken() float64 { return rg.RUSettings.RU.Tokens } +func (rg *ResourceGroup) getPriority() float64 { + rg.RLock() + defer rg.RUnlock() + return float64(rg.Priority) +} + +func (rg *ResourceGroup) getFillRate() float64 { + rg.RLock() + defer rg.RUnlock() + return float64(rg.RUSettings.RU.Settings.FillRate) +} + +func (rg *ResourceGroup) getBurstLimit() float64 { + rg.RLock() + defer rg.RUnlock() + return float64(rg.RUSettings.RU.Settings.BurstLimit) +} + // PatchSettings patches the resource group settings. // Only used to patch the resource group when updating. // Note: the tokens is the delta value to patch. diff --git a/pkg/mcs/scheduling/server/apis/v1/api.go b/pkg/mcs/scheduling/server/apis/v1/api.go index 8b9427a8896..c374456a6eb 100644 --- a/pkg/mcs/scheduling/server/apis/v1/api.go +++ b/pkg/mcs/scheduling/server/apis/v1/api.go @@ -1508,7 +1508,7 @@ func transferPrimary(c *gin.Context) { } if err := mcsutils.TransferPrimary(svr.GetClient(), svr.GetParticipant().GetExpectedPrimaryLease(), - constant.SchedulingServiceName, svr.Name(), newPrimary, 0); err != nil { + constant.SchedulingServiceName, svr.Name(), newPrimary, 0, nil); err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) return } diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 9ea369aae9e..e3a6d9bd648 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -178,8 +178,7 @@ func (s *Server) updateAPIServerMemberLoop() { defer cancel() ticker := time.NewTicker(memberUpdateInterval) failpoint.Inject("fastUpdateMember", func() { - ticker.Stop() - ticker = time.NewTicker(100 * time.Millisecond) + ticker.Reset(100 * time.Millisecond) }) defer ticker.Stop() var curLeader uint64 diff --git a/pkg/mcs/tso/server/apis/v1/api.go b/pkg/mcs/tso/server/apis/v1/api.go index 19b3a1be612..68a654c7315 100644 --- a/pkg/mcs/tso/server/apis/v1/api.go +++ b/pkg/mcs/tso/server/apis/v1/api.go @@ -307,9 +307,15 @@ func transferPrimary(c *gin.Context) { c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) return } + // only members of specific group are valid primary candidates. + group := svr.GetKeyspaceGroupManager().GetKeyspaceGroups()[keyspaceGroupID] + memberMap := make(map[string]bool, len(group.Members)) + for _, member := range group.Members { + memberMap[member.Address] = true + } if err := utils.TransferPrimary(svr.GetClient(), globalAllocator.(*tso.GlobalTSOAllocator).GetExpectedPrimaryLease(), - constant.TSOServiceName, svr.Name(), newPrimary, keyspaceGroupID); err != nil { + constant.TSOServiceName, svr.Name(), newPrimary, keyspaceGroupID, memberMap); err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) return } diff --git a/pkg/mcs/utils/expected_primary.go b/pkg/mcs/utils/expected_primary.go index c65d0a1cc5e..102bb8d785c 100644 --- a/pkg/mcs/utils/expected_primary.go +++ b/pkg/mcs/utils/expected_primary.go @@ -122,7 +122,7 @@ func watchExpectedPrimary(ctx context.Context, // TransferPrimary transfers the primary of the specified service. // keyspaceGroupID is optional, only used for TSO service. func TransferPrimary(client *clientv3.Client, lease *election.Lease, serviceName, - oldPrimary, newPrimary string, keyspaceGroupID uint32) error { + oldPrimary, newPrimary string, keyspaceGroupID uint32, tsoMembersMap map[string]bool) error { if lease == nil { return errors.New("current lease is nil, please check leadership") } @@ -139,6 +139,10 @@ func TransferPrimary(client *clientv3.Client, lease *election.Lease, serviceName var primaryIDs []string for _, member := range entries { + // only members of specific group are valid primary candidates for TSO service. + if tsoMembersMap != nil && !tsoMembersMap[member.ServiceAddr] { + continue + } if (newPrimary == "" && member.Name != oldPrimary) || (newPrimary != "" && member.Name == newPrimary) { primaryIDs = append(primaryIDs, member.ServiceAddr) } diff --git a/pkg/schedule/coordinator.go b/pkg/schedule/coordinator.go index 2a31045129e..2736c687fdb 100644 --- a/pkg/schedule/coordinator.go +++ b/pkg/schedule/coordinator.go @@ -217,7 +217,7 @@ func (c *Coordinator) RunUntilStop(collectWaitTime ...time.Duration) { func (c *Coordinator) Run(collectWaitTime ...time.Duration) { ticker := time.NewTicker(runSchedulerCheckInterval) failpoint.Inject("changeCoordinatorTicker", func() { - ticker = time.NewTicker(100 * time.Millisecond) + ticker.Reset(100 * time.Millisecond) }) defer ticker.Stop() log.Info("coordinator starts to collect cluster information") diff --git a/pkg/schedule/schedulers/evict_leader_test.go b/pkg/schedule/schedulers/evict_leader_test.go index b2c84ec68b7..ecd80813c0f 100644 --- a/pkg/schedule/schedulers/evict_leader_test.go +++ b/pkg/schedule/schedulers/evict_leader_test.go @@ -26,6 +26,7 @@ import ( "github.com/tikv/pd/pkg/schedule/types" "github.com/tikv/pd/pkg/storage" "github.com/tikv/pd/pkg/utils/operatorutil" + "github.com/tikv/pd/pkg/utils/testutil" ) func TestEvictLeader(t *testing.T) { @@ -115,7 +116,7 @@ func TestBatchEvict(t *testing.T) { tc.AddLeaderStore(2, 0) tc.AddLeaderStore(3, 0) // the random might be the same, so we add 1000 regions to make sure the batch is full - for i := 1; i <= 1000; i++ { + for i := 1; i <= 10000; i++ { tc.AddLeaderRegion(uint64(i), 1, 2, 3) } tc.AddLeaderRegion(6, 2, 1, 3) @@ -124,9 +125,13 @@ func TestBatchEvict(t *testing.T) { sl, err := CreateScheduler(types.EvictLeaderScheduler, oc, storage.NewStorageWithMemoryBackend(), ConfigSliceDecoder(types.EvictLeaderScheduler, []string{"1"}), func(string) error { return nil }) re.NoError(err) re.True(sl.IsScheduleAllowed(tc)) - ops, _ := sl.Schedule(tc, false) - re.Len(ops, 3) + testutil.Eventually(re, func() bool { + ops, _ := sl.Schedule(tc, false) + return len(ops) == 3 + }) sl.(*evictLeaderScheduler).conf.Batch = 5 - ops, _ = sl.Schedule(tc, false) - re.Len(ops, 5) + testutil.Eventually(re, func() bool { + ops, _ := sl.Schedule(tc, false) + return len(ops) == 5 + }) } diff --git a/pkg/tso/allocator_manager.go b/pkg/tso/allocator_manager.go index 1f5bce04583..56ee8313d57 100644 --- a/pkg/tso/allocator_manager.go +++ b/pkg/tso/allocator_manager.go @@ -715,8 +715,7 @@ func (am *AllocatorManager) AllocatorDaemon(ctx context.Context) { } tsTicker := time.NewTicker(am.updatePhysicalInterval) failpoint.Inject("fastUpdatePhysicalInterval", func() { - tsTicker.Stop() - tsTicker = time.NewTicker(time.Millisecond) + tsTicker.Reset(time.Millisecond) }) defer tsTicker.Stop() checkerTicker := time.NewTicker(PriorityCheck) diff --git a/pkg/tso/keyspace_group_manager.go b/pkg/tso/keyspace_group_manager.go index 0e62fc0346c..3a574ea8333 100644 --- a/pkg/tso/keyspace_group_manager.go +++ b/pkg/tso/keyspace_group_manager.go @@ -33,6 +33,7 @@ import ( "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/mcs/discovery" + "github.com/tikv/pd/pkg/mcs/utils" "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/member" "github.com/tikv/pd/pkg/slice" @@ -634,11 +635,11 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() { } // If there is a alive member with higher priority, reset the leader. resetLeader := false - for _, member := range kg.Members { - if member.Priority <= localPriority { + for _, m := range kg.Members { + if m.Priority <= localPriority { continue } - if _, ok := aliveTSONodes[typeutil.TrimScheme(member.Address)]; ok { + if _, ok := aliveTSONodes[typeutil.TrimScheme(m.Address)]; ok { resetLeader = true break } @@ -647,11 +648,31 @@ func (kgm *KeyspaceGroupManager) primaryPriorityCheckLoop() { select { case <-ctx.Done(): default: - member.ResetLeader() - log.Info("reset primary", + allocator, err := kgm.GetAllocatorManager(kg.ID) + if err != nil { + log.Error("failed to get allocator manager", zap.Error(err)) + continue + } + globalAllocator, err := allocator.GetAllocator(GlobalDCLocation) + if err != nil { + log.Error("failed to get global allocator", zap.Error(err)) + continue + } + // only members of specific group are valid primary candidates. + group := kgm.GetKeyspaceGroups()[kg.ID] + memberMap := make(map[string]bool, len(group.Members)) + for _, m := range group.Members { + memberMap[m.Address] = true + } + log.Info("tso priority checker moves primary", zap.String("local-address", kgm.tsoServiceID.ServiceAddr), zap.Uint32("keyspace-group-id", kg.ID), zap.Int("local-priority", localPriority)) + if err := utils.TransferPrimary(kgm.etcdClient, globalAllocator.(*GlobalTSOAllocator).GetExpectedPrimaryLease(), + constant.TSOServiceName, kgm.GetServiceConfig().GetName(), "", kg.ID, memberMap); err != nil { + log.Error("failed to transfer primary", zap.Error(err)) + continue + } } } else { log.Warn("no need to reset primary as the replicas with higher priority are offline", diff --git a/pkg/tso/keyspace_group_manager_test.go b/pkg/tso/keyspace_group_manager_test.go index fb4ac92a59c..95462e3b3d3 100644 --- a/pkg/tso/keyspace_group_manager_test.go +++ b/pkg/tso/keyspace_group_manager_test.go @@ -1044,9 +1044,9 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() { var err error defaultPriority := constant.DefaultKeyspaceGroupReplicaPriority - clusterID := rand.Uint64() + clusterID, err := etcdutil.InitOrGetClusterID(suite.etcdClient, "/pd/cluster_id") + re.NoError(err) clusterIDStr := strconv.FormatUint(clusterID, 10) - rootPath := path.Join("/pd", clusterIDStr) cfg1 := suite.createConfig() cfg2 := suite.createConfig() @@ -1054,6 +1054,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() { svcAddr2 := cfg2.GetAdvertiseListenAddr() // Register TSO server 1 + cfg1.Name = "tso1" err = suite.registerTSOServer(re, clusterIDStr, svcAddr1, cfg1) re.NoError(err) defer func() { @@ -1102,6 +1103,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() { checkTSO(ctx, re, &wg, mgr1, ids) // Create the Second TSO server. + cfg2.Name = "tso2" err = suite.registerTSOServer(re, clusterIDStr, svcAddr2, cfg2) re.NoError(err) mgr2 := suite.newKeyspaceGroupManager(1, clusterID, cfg2) @@ -1150,8 +1152,7 @@ func (suite *keyspaceGroupManagerTestSuite) TestPrimaryPriorityChange() { func (suite *keyspaceGroupManagerTestSuite) registerTSOServer( re *require.Assertions, clusterID, svcAddr string, cfg *TestServiceConfig, ) error { - // Register TSO server 1 - serviceID := &discovery.ServiceRegistryEntry{ServiceAddr: cfg.GetAdvertiseListenAddr()} + serviceID := &discovery.ServiceRegistryEntry{ServiceAddr: cfg.GetAdvertiseListenAddr(), Name: cfg.Name} serializedEntry, err := serviceID.Serialize() re.NoError(err) serviceKey := discovery.RegistryPath(clusterID, constant.TSOServiceName, svcAddr) diff --git a/pkg/utils/grpcutil/grpcutil.go b/pkg/utils/grpcutil/grpcutil.go index 5f852ff7359..1d1e6478036 100644 --- a/pkg/utils/grpcutil/grpcutil.go +++ b/pkg/utils/grpcutil/grpcutil.go @@ -52,8 +52,8 @@ type TLSConfig struct { CertPath string `toml:"cert-path" json:"cert-path"` // KeyPath is the path of file that contains X509 key in PEM format. KeyPath string `toml:"key-path" json:"key-path"` - // CertAllowedCN is a CN which must be provided by a client - CertAllowedCN []string `toml:"cert-allowed-cn" json:"cert-allowed-cn"` + // CertAllowedCNs is the list of CN which must be provided by a client + CertAllowedCNs []string `toml:"cert-allowed-cn" json:"cert-allowed-cn"` SSLCABytes []byte SSLCertBytes []byte @@ -65,16 +65,12 @@ func (s TLSConfig) ToTLSInfo() (*transport.TLSInfo, error) { if len(s.CertPath) == 0 && len(s.KeyPath) == 0 { return nil, nil } - allowedCN, err := s.GetOneAllowedCN() - if err != nil { - return nil, err - } return &transport.TLSInfo{ CertFile: s.CertPath, KeyFile: s.KeyPath, TrustedCAFile: s.CAPath, - AllowedCN: allowedCN, + AllowedCNs: s.CertAllowedCNs, }, nil } @@ -114,18 +110,6 @@ func (s TLSConfig) ToTLSConfig() (*tls.Config, error) { return tlsConfig, nil } -// GetOneAllowedCN only gets the first one CN. -func (s TLSConfig) GetOneAllowedCN() (string, error) { - switch len(s.CertAllowedCN) { - case 1: - return s.CertAllowedCN[0], nil - case 0: - return "", nil - default: - return "", errs.ErrSecurityConfig.FastGenByArgs("only supports one CN") - } -} - // GetClientConn returns a gRPC client connection. // creates a client connection to the given target. By default, it's // a non-blocking dial (the function won't wait for connections to be diff --git a/scripts/dashboard-version b/scripts/dashboard-version index d8d960683ae..1f6c34ca2fd 100644 --- a/scripts/dashboard-version +++ b/scripts/dashboard-version @@ -1,3 +1,3 @@ # This file is updated by running scripts/update-dashboard.sh # Don't edit it manually -8.3.0-e6e78c7c +8.4.0-3d0c3db0 diff --git a/server/api/region_test.go b/server/api/region_test.go index fb32496c16a..482208261e3 100644 --- a/server/api/region_test.go +++ b/server/api/region_test.go @@ -126,9 +126,13 @@ func (suite *regionTestSuite) TestRegionCheck() { url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "down-peer") r2 := &response.RegionsInfo{} - re.NoError(tu.ReadGetJSON(re, testDialClient, url, r2)) - r2.Adjust() - re.Equal(&response.RegionsInfo{Count: 1, Regions: []response.RegionInfo{*response.NewAPIRegionInfo(r)}}, r2) + tu.Eventually(re, func() bool { + if err := tu.ReadGetJSON(re, testDialClient, url, r2); err != nil { + return false + } + r2.Adjust() + return suite.Equal(&response.RegionsInfo{Count: 1, Regions: []response.RegionInfo{*response.NewAPIRegionInfo(r)}}, r2) + }) url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "pending-peer") r3 := &response.RegionsInfo{} @@ -146,25 +150,37 @@ func (suite *regionTestSuite) TestRegionCheck() { mustRegionHeartbeat(re, suite.svr, r) url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "empty-region") r5 := &response.RegionsInfo{} - re.NoError(tu.ReadGetJSON(re, testDialClient, url, r5)) - r5.Adjust() - re.Equal(&response.RegionsInfo{Count: 1, Regions: []response.RegionInfo{*response.NewAPIRegionInfo(r)}}, r5) + tu.Eventually(re, func() bool { + if err := tu.ReadGetJSON(re, testDialClient, url, r5); err != nil { + return false + } + r5.Adjust() + return suite.Equal(&response.RegionsInfo{Count: 1, Regions: []response.RegionInfo{*response.NewAPIRegionInfo(r)}}, r5) + }) r = r.Clone(core.SetApproximateSize(1)) mustRegionHeartbeat(re, suite.svr, r) url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "hist-size") r6 := make([]*histItem, 1) - re.NoError(tu.ReadGetJSON(re, testDialClient, url, &r6)) - histSizes := []*histItem{{Start: 1, End: 1, Count: 1}} - re.Equal(histSizes, r6) + tu.Eventually(re, func() bool { + if err := tu.ReadGetJSON(re, testDialClient, url, &r6); err != nil { + return false + } + histSizes := []*histItem{{Start: 1, End: 1, Count: 1}} + return suite.Equal(histSizes, r6) + }) r = r.Clone(core.SetApproximateKeys(1000)) mustRegionHeartbeat(re, suite.svr, r) url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "hist-keys") r7 := make([]*histItem, 1) - re.NoError(tu.ReadGetJSON(re, testDialClient, url, &r7)) - histKeys := []*histItem{{Start: 1000, End: 1999, Count: 1}} - re.Equal(histKeys, r7) + tu.Eventually(re, func() bool { + if err := tu.ReadGetJSON(re, testDialClient, url, &r7); err != nil { + return false + } + histKeys := []*histItem{{Start: 1000, End: 1999, Count: 1}} + return suite.Equal(histKeys, r7) + }) // ref https://github.com/tikv/pd/issues/3558, we should change size to pass `NeedUpdate` for observing. r = r.Clone(core.SetApproximateKeys(0)) @@ -172,10 +188,13 @@ func (suite *regionTestSuite) TestRegionCheck() { mustRegionHeartbeat(re, suite.svr, r) url = fmt.Sprintf("%s/regions/check/%s", suite.urlPrefix, "offline-peer") r8 := &response.RegionsInfo{} - re.NoError(tu.ReadGetJSON(re, testDialClient, url, r8)) - r4.Adjust() - re.Equal(1, r8.Count) - re.Equal(r.GetID(), r8.Regions[0].ID) + tu.Eventually(re, func() bool { + if err := tu.ReadGetJSON(re, testDialClient, url, r8); err != nil { + return false + } + r4.Adjust() + return suite.Equal(r.GetID(), r8.Regions[0].ID) && r8.Count == 1 + }) } func (suite *regionTestSuite) TestRegions() { diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index fdeffd15e9c..ef6d45203d8 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -396,8 +396,7 @@ func (c *RaftCluster) runServiceCheckJob() { ticker := time.NewTicker(serviceCheckInterval) failpoint.Inject("highFrequencyClusterJobs", func() { - ticker.Stop() - ticker = time.NewTicker(time.Millisecond) + ticker.Reset(time.Millisecond) }) defer ticker.Stop() @@ -675,8 +674,7 @@ func (c *RaftCluster) runMetricsCollectionJob() { ticker := time.NewTicker(metricsCollectionJobInterval) failpoint.Inject("highFrequencyClusterJobs", func() { - ticker.Stop() - ticker = time.NewTicker(time.Millisecond) + ticker.Reset(time.Millisecond) }) defer ticker.Stop() @@ -699,8 +697,7 @@ func (c *RaftCluster) runNodeStateCheckJob() { ticker := time.NewTicker(nodeStateCheckJobInterval) failpoint.Inject("highFrequencyClusterJobs", func() { - ticker.Stop() - ticker = time.NewTicker(2 * time.Second) + ticker.Reset(2 * time.Second) }) defer ticker.Stop() diff --git a/server/cluster/scheduling_controller.go b/server/cluster/scheduling_controller.go index 20a36a6817d..5d617700804 100644 --- a/server/cluster/scheduling_controller.go +++ b/server/cluster/scheduling_controller.go @@ -150,8 +150,7 @@ func (sc *schedulingController) runSchedulingMetricsCollectionJob() { ticker := time.NewTicker(metricsCollectionJobInterval) failpoint.Inject("highFrequencyClusterJobs", func() { - ticker.Stop() - ticker = time.NewTicker(time.Millisecond) + ticker.Reset(time.Millisecond) }) defer ticker.Stop() diff --git a/server/config/config.go b/server/config/config.go index c1791be1fd9..d8bd086225c 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -726,23 +726,20 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) { cfg.QuotaBackendBytes = int64(c.QuotaBackendBytes) cfg.MaxRequestBytes = c.MaxRequestBytes - allowedCN, serr := c.Security.GetOneAllowedCN() - if serr != nil { - return nil, serr - } cfg.ClientTLSInfo.ClientCertAuth = len(c.Security.CAPath) != 0 cfg.ClientTLSInfo.TrustedCAFile = c.Security.CAPath cfg.ClientTLSInfo.CertFile = c.Security.CertPath cfg.ClientTLSInfo.KeyFile = c.Security.KeyPath - // Client no need to set the CN. (cfg.ClientTLSInfo.AllowedCN = allowedCN) + // Keep compatibility with https://github.com/tikv/pd/pull/2305 + // Only check client cert when there are multiple CNs. + if len(c.Security.CertAllowedCNs) > 1 { + cfg.ClientTLSInfo.AllowedCNs = c.Security.CertAllowedCNs + } cfg.PeerTLSInfo.ClientCertAuth = len(c.Security.CAPath) != 0 cfg.PeerTLSInfo.TrustedCAFile = c.Security.CAPath cfg.PeerTLSInfo.CertFile = c.Security.CertPath cfg.PeerTLSInfo.KeyFile = c.Security.KeyPath - // TODO: After https://github.com/etcd-io/etcd/pull/18015, AllowedCN is Deprecated. - // It will be replaced by AllowedCNs in the future to support multi cn. - // nolint:staticcheck - cfg.PeerTLSInfo.AllowedCN = allowedCN + cfg.PeerTLSInfo.AllowedCNs = c.Security.CertAllowedCNs cfg.ForceNewCluster = c.ForceNewCluster cfg.ZapLoggerBuilder = embed.NewZapCoreLoggerBuilder(c.Logger, c.Logger.Core(), c.LogProps.Syncer) cfg.EnableGRPCGateway = c.EnableGRPCGateway @@ -774,13 +771,14 @@ func (c *Config) GenEmbedEtcdConfig() (*embed.Config, error) { // DashboardConfig is the configuration for tidb-dashboard. type DashboardConfig struct { - TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb-cacert-path"` - TiDBCertPath string `toml:"tidb-cert-path" json:"tidb-cert-path"` - TiDBKeyPath string `toml:"tidb-key-path" json:"tidb-key-path"` - PublicPathPrefix string `toml:"public-path-prefix" json:"public-path-prefix"` - InternalProxy bool `toml:"internal-proxy" json:"internal-proxy"` - EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"` - EnableExperimental bool `toml:"enable-experimental" json:"enable-experimental"` + TiDBCAPath string `toml:"tidb-cacert-path" json:"tidb-cacert-path"` + TiDBCertPath string `toml:"tidb-cert-path" json:"tidb-cert-path"` + TiDBKeyPath string `toml:"tidb-key-path" json:"tidb-key-path"` + PublicPathPrefix string `toml:"public-path-prefix" json:"public-path-prefix"` + InternalProxy bool `toml:"internal-proxy" json:"internal-proxy"` + EnableTelemetry bool `toml:"enable-telemetry" json:"enable-telemetry"` + EnableExperimental bool `toml:"enable-experimental" json:"enable-experimental"` + DisableCustomPromAddr bool `toml:"disable-custom-prom-addr" json:"disable-custom-prom-addr"` } // ToTiDBTLSConfig generates tls config for connecting to TiDB, used by tidb-dashboard. diff --git a/server/grpc_service.go b/server/grpc_service.go index d3db45c8364..216611038e5 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -57,7 +57,7 @@ import ( const ( heartbeatSendTimeout = 5 * time.Second - maxRetryTimesRequestTSOServer = 3 + maxRetryTimesRequestTSOServer = 6 retryIntervalRequestTSOServer = 500 * time.Millisecond getMinTSFromTSOServerTimeout = 1 * time.Second defaultGRPCDialTimeout = 3 * time.Second diff --git a/tests/cluster.go b/tests/cluster.go index f9cbb99ce25..5cd90d8e03e 100644 --- a/tests/cluster.go +++ b/tests/cluster.go @@ -611,6 +611,11 @@ func (c *TestCluster) StopAll() error { return nil } +// DeleteServer is used to delete a server. +func (c *TestCluster) DeleteServer(name string) { + delete(c.servers, name) +} + // GetServer returns a server with a given name. func (c *TestCluster) GetServer(name string) *TestServer { return c.servers[name] diff --git a/tests/integrations/client/cert_opt.sh b/tests/integrations/client/cert_opt.sh index 3984e67f3ab..02f72249db7 100755 --- a/tests/integrations/client/cert_opt.sh +++ b/tests/integrations/client/cert_opt.sh @@ -3,7 +3,7 @@ cert_dir="$2" function generate_certs() { if [[ ! -z "$cert_dir" ]]; then - cd "$cert_dir" || exit 255 # Change to the specified directory + cd "$cert_dir" || exit 255 # Change to the specified directory fi if ! [[ "$0" =~ "cert_opt.sh" ]]; then @@ -21,10 +21,10 @@ function generate_certs() { openssl req -new -x509 -key ca-key.pem -out ca.pem -days 1 -subj "/CN=ca" # pd-server openssl genpkey -algorithm RSA -out pd-server-key.pem - openssl req -new -key pd-server-key.pem -out pd-server.csr -subj "/CN=pd-server" + openssl req -new -key pd-server-key.pem -out pd-server.csr -subj "/CN=pd-server" # Add IP address as a SAN - echo "subjectAltName = IP:127.0.0.1" > extfile.cnf + echo "subjectAltName = IP:127.0.0.1" >extfile.cnf openssl x509 -req -in pd-server.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out pd-server.pem -days 1 -extfile extfile.cnf # Clean up the temporary extension file @@ -34,11 +34,16 @@ function generate_certs() { openssl genpkey -algorithm RSA -out client-key.pem openssl req -new -key client-key.pem -out client.csr -subj "/CN=client" openssl x509 -req -in client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out client.pem -days 1 + + # client2 + openssl genpkey -algorithm RSA -out tidb-client-key.pem + openssl req -new -key tidb-client-key.pem -out tidb-client.csr -subj "/CN=tidb" + openssl x509 -req -in tidb-client.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out tidb-client.pem -days 1 } function cleanup_certs() { if [[ ! -z "$cert_dir" ]]; then - cd "$cert_dir" || exit 255 # Change to the specified directory + cd "$cert_dir" || exit 255 # Change to the specified directory fi rm -f ca.pem ca-key.pem ca.srl diff --git a/tests/integrations/client/client_tls_test.go b/tests/integrations/client/client_tls_test.go index b915d77b3b0..75706c3d902 100644 --- a/tests/integrations/client/client_tls_test.go +++ b/tests/integrations/client/client_tls_test.go @@ -36,54 +36,24 @@ import ( "google.golang.org/grpc" ) -var ( - certPath = strings.Join([]string{".", "cert"}, string(filepath.Separator)) - certExpiredPath = strings.Join([]string{".", "cert-expired"}, string(filepath.Separator)) - certScript = strings.Join([]string{".", "cert_opt.sh"}, string(filepath.Separator)) - testTLSInfo = transport.TLSInfo{ - KeyFile: strings.Join([]string{".", "cert", "pd-server-key.pem"}, string(filepath.Separator)), - CertFile: strings.Join([]string{".", "cert", "pd-server.pem"}, string(filepath.Separator)), - TrustedCAFile: strings.Join([]string{".", "cert", "ca.pem"}, string(filepath.Separator)), - } - - testClientTLSInfo = transport.TLSInfo{ - KeyFile: strings.Join([]string{".", "cert", "client-key.pem"}, string(filepath.Separator)), - CertFile: strings.Join([]string{".", "cert", "client.pem"}, string(filepath.Separator)), - TrustedCAFile: strings.Join([]string{".", "cert", "ca.pem"}, string(filepath.Separator)), - } - - testTLSInfoExpired = transport.TLSInfo{ - KeyFile: strings.Join([]string{".", "cert-expired", "pd-server-key.pem"}, string(filepath.Separator)), - CertFile: strings.Join([]string{".", "cert-expired", "pd-server.pem"}, string(filepath.Separator)), - TrustedCAFile: strings.Join([]string{".", "cert-expired", "ca.pem"}, string(filepath.Separator)), - } -) +var certScript = strings.Join([]string{".", "cert_opt.sh"}, string(filepath.Separator)) // TestTLSReloadAtomicReplace ensures server reloads expired/valid certs // when all certs are atomically replaced by directory renaming. // And expects server to reject client requests, and vice versa. func TestTLSReloadAtomicReplace(t *testing.T) { - // generate certs - for _, path := range []string{certPath, certExpiredPath} { - if err := os.Mkdir(path, 0755); err != nil { - t.Fatal(err) - } - if err := exec.Command(certScript, "generate", path).Run(); err != nil { - t.Fatal(err) - } - } - defer func() { - for _, path := range []string{certPath, certExpiredPath} { - if err := exec.Command(certScript, "cleanup", path).Run(); err != nil { - t.Fatal(err) - } - if err := os.RemoveAll(path); err != nil { - t.Fatal(err) - } - } - }() - re := require.New(t) + + certPath := strings.Join([]string{".", "cert"}, string(filepath.Separator)) + certExpiredPath := strings.Join([]string{".", "cert-expired"}, string(filepath.Separator)) + cleanFunc := generateCerts(re, certPath) + defer cleanFunc() + cleanFunc = generateCerts(re, certExpiredPath) + defer cleanFunc() + testTLSInfo := buildTLSInfo(certPath, "pd-server") + testTLSInfoExpired := buildTLSInfo(certExpiredPath, "pd-server") + testClientTLSInfo := buildTLSInfo(certPath, "client") + ctx, cancel := context.WithCancel(context.Background()) defer cancel() tmpDir := t.TempDir() @@ -120,12 +90,35 @@ func TestTLSReloadAtomicReplace(t *testing.T) { err = os.Rename(certsDirExp, certsDir) re.NoError(err) } - testTLSReload(ctx, re, cloneFunc, replaceFunc, revertFunc) + testTLSReload(ctx, re, testClientTLSInfo, cloneFunc, replaceFunc, revertFunc) +} + +func buildTLSInfo(path, name string) transport.TLSInfo { + return transport.TLSInfo{ + KeyFile: strings.Join([]string{path, name + "-key.pem"}, string(filepath.Separator)), + CertFile: strings.Join([]string{path, name + ".pem"}, string(filepath.Separator)), + TrustedCAFile: strings.Join([]string{path, "ca.pem"}, string(filepath.Separator)), + } +} + +func generateCerts(re *require.Assertions, path string) func() { + err := os.Mkdir(path, 0755) + re.NoError(err) + err = exec.Command(certScript, "generate", path).Run() + re.NoError(err) + + return func() { + err := exec.Command(certScript, "cleanup", path).Run() + re.NoError(err) + err = os.RemoveAll(path) + re.NoError(err) + } } func testTLSReload( ctx context.Context, re *require.Assertions, + testClientTLSInfo transport.TLSInfo, cloneFunc func() transport.TLSInfo, replaceFunc func(), revertFunc func()) { @@ -275,3 +268,64 @@ func copyFile(src, dst string) error { } return w.Sync() } + +func TestMultiCN(t *testing.T) { + re := require.New(t) + + certPath := strings.Join([]string{".", "cert-multi-cn"}, string(filepath.Separator)) + cleanFunc := generateCerts(re, certPath) + defer cleanFunc() + testTLSInfo := buildTLSInfo(certPath, "pd-server") + testClientTLSInfo := buildTLSInfo(certPath, "client") + testTiDBClientTLSInfo := buildTLSInfo(certPath, "tidb-client") + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + clus, err := tests.NewTestCluster(ctx, 1, func(conf *config.Config, _ string) { + conf.Security.TLSConfig = grpcutil.TLSConfig{ + KeyPath: testTLSInfo.KeyFile, + CertPath: testTLSInfo.CertFile, + CAPath: testTLSInfo.TrustedCAFile, + CertAllowedCNs: []string{"tidb", "pd-server"}, + } + conf.AdvertiseClientUrls = strings.ReplaceAll(conf.AdvertiseClientUrls, "http", "https") + conf.ClientUrls = strings.ReplaceAll(conf.ClientUrls, "http", "https") + conf.AdvertisePeerUrls = strings.ReplaceAll(conf.AdvertisePeerUrls, "http", "https") + conf.PeerUrls = strings.ReplaceAll(conf.PeerUrls, "http", "https") + conf.InitialCluster = strings.ReplaceAll(conf.InitialCluster, "http", "https") + }) + re.NoError(err) + defer clus.Destroy() + err = clus.RunInitialServers() + re.NoError(err) + clus.WaitLeader() + + testServers := clus.GetServers() + endpoints := make([]string, 0, len(testServers)) + for _, s := range testServers { + endpoints = append(endpoints, s.GetConfig().AdvertiseClientUrls) + } + + // cn TiDB is allowed + re.NoError(testAllowedCN(ctx, endpoints, testTiDBClientTLSInfo)) + + // cn client is not allowed + re.Error(testAllowedCN(ctx, endpoints, testClientTLSInfo)) +} + +func testAllowedCN(ctx context.Context, endpoints []string, tls transport.TLSInfo) error { + ctx1, cancel1 := context.WithTimeout(ctx, 3*time.Second) + defer cancel1() + cli, err := pd.NewClientWithContext(ctx1, endpoints, pd.SecurityOption{ + CAPath: tls.TrustedCAFile, + CertPath: tls.CertFile, + KeyPath: tls.KeyFile, + }, pd.WithGRPCDialOptions(grpc.WithBlock())) + if err != nil { + return err + } + defer cli.Close() + _, err = cli.GetAllMembers(ctx1) + return err +} diff --git a/tests/integrations/go.mod b/tests/integrations/go.mod index d7305379e9f..3db0931351e 100644 --- a/tests/integrations/go.mod +++ b/tests/integrations/go.mod @@ -56,11 +56,12 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bitly/go-simplejson v0.5.0 // indirect github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/cloudfoundry/gosigar v1.3.6 // indirect github.com/coreos/go-semver v0.3.1 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect @@ -68,8 +69,8 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/elliotchance/pie/v2 v2.1.0 // indirect github.com/fogleman/gg v1.3.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/gin-contrib/cors v1.4.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/cors v1.6.0 // indirect github.com/gin-contrib/gzip v0.0.1 // indirect github.com/gin-contrib/pprof v1.4.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect @@ -83,7 +84,7 @@ require ( github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/goccy/go-graphviz v0.1.3 // indirect github.com/goccy/go-json v0.10.2 // indirect @@ -112,11 +113,11 @@ 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/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // 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 github.com/mailru/easyjson v0.7.6 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect github.com/minio/sio v0.3.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -124,12 +125,12 @@ require ( github.com/oleiade/reflections v1.0.1 // indirect github.com/opentracing/basictracer-go v1.1.0 github.com/opentracing/opentracing-go v1.2.0 - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d // indirect github.com/pingcap/errcode v0.3.0 // indirect github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 // indirect - github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c // indirect + github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c // indirect github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -156,7 +157,7 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect github.com/unrolled/render v1.0.1 // indirect github.com/urfave/negroni v0.3.0 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect @@ -181,7 +182,7 @@ require ( go.uber.org/dig v1.9.0 // indirect go.uber.org/fx v1.12.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/arch v0.3.0 // indirect + golang.org/x/arch v0.7.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4 // indirect golang.org/x/image v0.18.0 // indirect diff --git a/tests/integrations/go.sum b/tests/integrations/go.sum index 914ce1ff35c..2b9f24474d1 100644 --- a/tests/integrations/go.sum +++ b/tests/integrations/go.sum @@ -66,8 +66,9 @@ github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTo github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8= github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= 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/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= @@ -76,8 +77,12 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA 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/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= +github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= 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= @@ -120,11 +125,11 @@ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzP github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= -github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= +github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg= +github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro= github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= @@ -169,8 +174,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= +github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -297,8 +302,9 @@ github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQL 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/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +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= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -311,8 +317,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 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.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= @@ -323,8 +329,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE= @@ -366,8 +372,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9 github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -391,8 +397,8 @@ github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8 github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 h1:QV6jqlfOkh8hqvEAgwBZa+4bSgO0EeKC7s5c6Luam2I= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21/go.mod h1:QYnjfA95ZaMefyl1NO8oPtKeb8pYUdnDVhQgf+qdpjM= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c h1:iiVpATdlLLr0NEgKZu+ZnBuYR4J8IgjNE1hNMjMOkYY= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c h1:+0Tl9izTX2X5cy4wO4cbvjjsg8LqKpHdH5bEMv7pTb4= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e h1:FBaTXU8C3xgt/drM58VHxojHo/QoG1oPsgWTGvaSpO4= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -468,7 +474,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM= @@ -502,8 +507,8 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6 github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/unrolled/render v1.0.1 h1:VDDnQQVfBMsOsp3VaCJszSO0nkBIVEYoPWeRThk9spY= github.com/unrolled/render v1.0.1/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= @@ -585,8 +590,8 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= +golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -680,10 +685,10 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc 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-20220704084225-05e143d24a9e/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= @@ -806,6 +811,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= moul.io/zapgorm2 v1.1.0 h1:qwAlMBYf+qJkJ7PAzJl4oCe6eS6QGiKAXUPeis0+RBE= moul.io/zapgorm2 v1.1.0/go.mod h1:emRfKjNqSzVj5lcgasBdovIXY1jSOwFz2GQZn1Rddks= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/tests/integrations/mcs/members/member_test.go b/tests/integrations/mcs/members/member_test.go index dffa6305d0b..4e1e6534416 100644 --- a/tests/integrations/mcs/members/member_test.go +++ b/tests/integrations/mcs/members/member_test.go @@ -19,14 +19,19 @@ import ( "context" "encoding/json" "fmt" + "io" "net/http" "testing" "time" "github.com/pingcap/failpoint" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" pdClient "github.com/tikv/pd/client/http" bs "github.com/tikv/pd/pkg/basicserver" + tso "github.com/tikv/pd/pkg/mcs/tso/server" + "github.com/tikv/pd/pkg/mcs/tso/server/apis/v1" + "github.com/tikv/pd/pkg/mcs/utils/constant" "github.com/tikv/pd/pkg/utils/tempurl" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/tests" @@ -41,6 +46,9 @@ type memberTestSuite struct { backendEndpoints string pdClient pdClient.Client + // We only test `DefaultKeyspaceGroupID` here. + // tsoAvailMembers is used to check the tso members which in the DefaultKeyspaceGroupID. + tsoAvailMembers map[string]bool tsoNodes map[string]bs.Server schedulingNodes map[string]bs.Server } @@ -51,6 +59,7 @@ func TestMemberTestSuite(t *testing.T) { func (suite *memberTestSuite) SetupTest() { re := suite.Require() + re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes", `return(true)`)) ctx, cancel := context.WithCancel(context.Background()) suite.ctx = ctx cluster, err := tests.NewTestAPICluster(suite.ctx, 1) @@ -65,6 +74,7 @@ func (suite *memberTestSuite) SetupTest() { // TSO nodes := make(map[string]bs.Server) + // mock 3 tso nodes, which is more than the default replica count(DefaultKeyspaceGroupReplicaCount). for i := 0; i < 3; i++ { s, cleanup := tests.StartSingleTSOTestServer(suite.ctx, re, suite.backendEndpoints, tempurl.Alloc()) nodes[s.GetAddr()] = s @@ -72,8 +82,16 @@ func (suite *memberTestSuite) SetupTest() { cleanup() }) } - tests.WaitForPrimaryServing(re, nodes) + primary := tests.WaitForPrimaryServing(re, nodes) + members := mustGetKeyspaceGroupMembers(re, nodes[primary].(*tso.Server)) + // Get the tso nodes suite.tsoNodes = nodes + // We only test `DefaultKeyspaceGroupID` here. + // tsoAvailMembers is used to check the tso members which in the DefaultKeyspaceGroupID. + suite.tsoAvailMembers = make(map[string]bool) + for _, member := range members[constant.DefaultKeyspaceGroupID].Group.Members { + suite.tsoAvailMembers[member.Address] = true + } // Scheduling nodes = make(map[string]bs.Server) @@ -100,6 +118,8 @@ func (suite *memberTestSuite) TearDownTest() { suite.pdClient.Close() } suite.cluster.Destroy() + re := suite.Require() + re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/keyspace/acceleratedAllocNodes")) } func (suite *memberTestSuite) TestMembers() { @@ -124,7 +144,7 @@ func (suite *memberTestSuite) TestPrimary() { re.NotEmpty(primary) } -func (suite *memberTestSuite) TestCampaignPrimaryWhileServerClose() { +func (suite *memberTestSuite) TestPrimaryWorkWhileOtherServerClose() { re := suite.Require() primary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, "tso") re.NoError(err) @@ -143,20 +163,18 @@ func (suite *memberTestSuite) TestCampaignPrimaryWhileServerClose() { primary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, service) re.NoError(err) - // Close old and new primary to mock campaign primary + // Close non-primary node. for _, member := range nodes { if member.GetAddr() != primary { nodes[member.Name()].Close() - break } } - nodes[primary].Close() tests.WaitForPrimaryServing(re, nodes) - // primary should be different with before - onlyPrimary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, service) + // primary should be same with before. + curPrimary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, service) re.NoError(err) - re.NotEqual(primary, onlyPrimary) + re.Equal(primary, curPrimary) } } @@ -200,6 +218,9 @@ func (suite *memberTestSuite) TestTransferPrimary() { // Test transfer primary to a specific node var newPrimary string for _, member := range nodes { + if service == "tso" && !suite.tsoAvailMembers[member.GetAddr()] { + continue + } if member.GetAddr() != primary { newPrimary = member.Name() break @@ -251,6 +272,9 @@ func (suite *memberTestSuite) TestCampaignPrimaryAfterTransfer() { // Test transfer primary to a specific node var newPrimary string for _, member := range nodes { + if service == "tso" && !suite.tsoAvailMembers[member.GetAddr()] { + continue + } if member.GetAddr() != primary { newPrimary = member.Name() break @@ -270,15 +294,13 @@ func (suite *memberTestSuite) TestCampaignPrimaryAfterTransfer() { re.NoError(err) re.NotEqual(primary, newPrimary) - // Close old and new primary to mock campaign primary - nodes[primary].Close() + // Close primary to push other nodes campaign primary nodes[newPrimary].Close() tests.WaitForPrimaryServing(re, nodes) // Primary should be different with before - onlyPrimary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, service) + anotherPrimary, err := suite.pdClient.GetMicroServicePrimary(suite.ctx, service) re.NoError(err) - re.NotEqual(primary, onlyPrimary) - re.NotEqual(newPrimary, onlyPrimary) + re.NotEqual(newPrimary, anotherPrimary) } } @@ -304,6 +326,9 @@ func (suite *memberTestSuite) TestTransferPrimaryWhileLeaseExpired() { // Test transfer primary to a specific node var newPrimary string for _, member := range nodes { + if service == "tso" && !suite.tsoAvailMembers[member.GetAddr()] { + continue + } if member.GetAddr() != primary { newPrimary = member.Name() break @@ -356,6 +381,9 @@ func (suite *memberTestSuite) TestTransferPrimaryWhileLeaseExpiredAndServerDown( // Test transfer primary to a specific node var newPrimary string for _, member := range nodes { + if service == "tso" && !suite.tsoAvailMembers[member.GetAddr()] { + continue + } if member.GetAddr() != primary { newPrimary = member.Name() break @@ -390,3 +418,17 @@ func (suite *memberTestSuite) TestTransferPrimaryWhileLeaseExpiredAndServerDown( re.NotEqual(newPrimary, onlyPrimary) } } + +func mustGetKeyspaceGroupMembers(re *require.Assertions, server *tso.Server) map[uint32]*apis.KeyspaceGroupMember { + httpReq, err := http.NewRequest(http.MethodGet, server.GetAddr()+"/tso/api/v1/keyspace-groups/members", nil) + re.NoError(err) + httpResp, err := tests.TestDialClient.Do(httpReq) + re.NoError(err) + defer httpResp.Body.Close() + data, err := io.ReadAll(httpResp.Body) + re.NoError(err) + re.Equal(http.StatusOK, httpResp.StatusCode, string(data)) + var resp map[uint32]*apis.KeyspaceGroupMember + re.NoError(json.Unmarshal(data, &resp)) + return resp +} diff --git a/tests/integrations/mcs/scheduling/api_test.go b/tests/integrations/mcs/scheduling/api_test.go index d2027a616cb..6335d104e3e 100644 --- a/tests/integrations/mcs/scheduling/api_test.go +++ b/tests/integrations/mcs/scheduling/api_test.go @@ -513,6 +513,20 @@ func (suite *apiTestSuite) checkFollowerForward(cluster *tests.TestCluster) { defer cancel() follower, err := cluster.JoinAPIServer(ctx) re.NoError(err) + defer func() { + leader := cluster.GetLeaderServer() + cli := leader.GetEtcdClient() + testutil.Eventually(re, func() bool { + _, err = cli.MemberRemove(context.Background(), follower.GetServer().GetMember().ID()) + return err == nil + }) + testutil.Eventually(re, func() bool { + res, err := cli.MemberList(context.Background()) + return err == nil && len(res.Members) == 1 + }) + cluster.DeleteServer(follower.GetConfig().Name) + follower.Destroy() + }() re.NoError(follower.Run()) re.NotEmpty(cluster.WaitLeader()) diff --git a/tests/server/api/rule_test.go b/tests/server/api/rule_test.go index f4d85d60361..7d00310d557 100644 --- a/tests/server/api/rule_test.go +++ b/tests/server/api/rule_test.go @@ -985,13 +985,7 @@ func (suite *ruleTestSuite) checkLeaderAndVoter(cluster *tests.TestCluster) { tu.StatusOK(re), tu.ExtractJSON(re, &respBundle)) re.NoError(err) re.Len(respBundle, 1) - if bundle[0].Rules[0].Role == placement.Leader { - return respBundle[0].Rules[0].Role == placement.Leader - } - if bundle[0].Rules[0].Role == placement.Voter { - return respBundle[0].Rules[0].Role == placement.Voter - } - return false + return compareBundle(respBundle[0], bundle[0]) }) } } diff --git a/tests/server/member/member_test.go b/tests/server/member/member_test.go index 6cd9eacddf1..2d0c9098153 100644 --- a/tests/server/member/member_test.go +++ b/tests/server/member/member_test.go @@ -161,21 +161,33 @@ func TestLeaderPriority(t *testing.T) { re.NotEmpty(cluster.WaitLeader()) - leader1, err := cluster.GetServer("pd1").GetEtcdLeader() + leader, err := cluster.GetServer("pd1").GetEtcdLeader() re.NoError(err) - server1 := cluster.GetServer(leader1) - addr := server1.GetConfig().ClientUrls + server := cluster.GetServer(leader) + addr := server.GetConfig().ClientUrls // PD leader should sync with etcd leader. testutil.Eventually(re, func() bool { - return cluster.GetLeader() == leader1 + leader, err := cluster.GetServer("pd1").GetEtcdLeader() + if err != nil { + return false + } + return cluster.GetLeader() == leader }) // Bind a lower priority to current leader. - post(t, re, addr+"/pd/api/v1/members/name/"+leader1, `{"leader-priority": -1}`) + post(t, re, addr+"/pd/api/v1/members/name/"+leader, `{"leader-priority": -1}`) + // Wait etcd leader change. - leader2 := waitEtcdLeaderChange(re, server1, leader1) + waitEtcdLeaderChange(re, server, leader) // PD leader should sync with etcd leader again. testutil.Eventually(re, func() bool { - return cluster.GetLeader() == leader2 + etcdLeader, err := server.GetEtcdLeader() + if err != nil { + return false + } + if cluster.GetLeader() == etcdLeader { + return true + } + return false }) } diff --git a/tools/go.mod b/tools/go.mod index b1a3c1e3543..a9bc5446477 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -13,7 +13,7 @@ require ( github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e github.com/coreos/go-semver v0.3.1 github.com/docker/go-units v0.4.0 - github.com/gin-contrib/cors v1.4.0 + github.com/gin-contrib/cors v1.6.0 github.com/gin-contrib/gzip v0.0.1 github.com/gin-contrib/pprof v1.4.0 github.com/gin-gonic/gin v1.9.1 @@ -67,16 +67,17 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bitly/go-simplejson v0.5.0 // indirect github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch // indirect - github.com/bytedance/sonic v1.9.1 // indirect + github.com/bytedance/sonic v1.11.2 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.1 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/elliotchance/pie/v2 v2.1.0 // indirect github.com/fogleman/gg v1.3.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect @@ -87,7 +88,7 @@ require ( github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.19.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/goccy/go-graphviz v0.1.3 // indirect @@ -117,23 +118,23 @@ 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/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // 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 github.com/mailru/easyjson v0.7.6 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-sqlite3 v1.14.15 // indirect 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/oleiade/reflections v1.0.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.1.1 // indirect github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d // indirect github.com/pingcap/errcode v0.3.0 // indirect github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 // indirect - github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c // indirect + github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c // indirect github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -158,7 +159,7 @@ require ( github.com/tklauser/numcpus v0.6.0 // indirect github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect github.com/unrolled/render v1.0.1 // indirect github.com/urfave/negroni v0.3.0 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect @@ -181,7 +182,7 @@ require ( go.uber.org/dig v1.9.0 // indirect go.uber.org/fx v1.12.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/arch v0.3.0 // indirect + golang.org/x/arch v0.7.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20230711005742-c3f37128e5a4 // indirect golang.org/x/image v0.18.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index 0933f7ceda7..3ca1597645f 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -64,8 +64,9 @@ github.com/breeswish/gin-jwt/v2 v2.6.4-jwt-patch/go.mod h1:KjBLriHXe7L6fGceqWzTo github.com/brianvoe/gofakeit/v6 v6.26.3 h1:3ljYrjPwsUNAUFdUIr2jVg5EhKdcke/ZLop7uVg1Er8= github.com/brianvoe/gofakeit/v6 v6.26.3/go.mod h1:Xj58BMSnFqcn/fAQeSK+/PLtC5kSb7FJIq4JyGa8vEs= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= -github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.11.2 h1:ywfwo0a/3j9HR8wsYGWsIWl2mvRsI950HyoxiBERw5A= +github.com/bytedance/sonic v1.11.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= 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/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= @@ -74,8 +75,12 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA 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/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0= +github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= @@ -117,11 +122,11 @@ github.com/envoyproxy/protoc-gen-validate v1.0.4/go.mod h1:qys6tmnRsYrQqIhm2bvKZ github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= -github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= +github.com/gin-contrib/cors v1.6.0 h1:0Z7D/bVhE6ja07lI8CTjTonp6SB07o8bNuFyRbsBUQg= +github.com/gin-contrib/cors v1.6.0/go.mod h1:cI+h6iOAyxKRtUtC6iF/Si1KSFvGm/gK+kshxlCi8ro= github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= @@ -168,8 +173,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= -github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= -github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= +github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= @@ -297,8 +302,9 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV 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/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +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= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -311,8 +317,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 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.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a h1:N9zuLhTvBSRt0gWSiJswwQ2HqDmtX/ZCDJURnKUt1Ik= github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= @@ -323,8 +329,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= @@ -363,8 +369,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9 github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= -github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= -github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= +github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -388,8 +394,8 @@ github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8 github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21 h1:QV6jqlfOkh8hqvEAgwBZa+4bSgO0EeKC7s5c6Luam2I= github.com/pingcap/sysutil v1.0.1-0.20230407040306-fb007c5aff21/go.mod h1:QYnjfA95ZaMefyl1NO8oPtKeb8pYUdnDVhQgf+qdpjM= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c h1:iiVpATdlLLr0NEgKZu+ZnBuYR4J8IgjNE1hNMjMOkYY= -github.com/pingcap/tidb-dashboard v0.0.0-20240815045040-4d89bc193a0c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c h1:+0Tl9izTX2X5cy4wO4cbvjjsg8LqKpHdH5bEMv7pTb4= +github.com/pingcap/tidb-dashboard v0.0.0-20240830080600-3d0c3db0d55c/go.mod h1:AT9vfeojwr/GGCHTURXtA8yZBE9AW8LdIo02/eYdfHU= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e h1:FBaTXU8C3xgt/drM58VHxojHo/QoG1oPsgWTGvaSpO4= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -468,7 +474,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM= @@ -502,8 +507,8 @@ github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6 github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/unrolled/render v1.0.1 h1:VDDnQQVfBMsOsp3VaCJszSO0nkBIVEYoPWeRThk9spY= github.com/unrolled/render v1.0.1/go.mod h1:gN9T0NhL4Bfbwu8ann7Ry/TGHYfosul+J0obPf6NBdM= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= @@ -587,8 +592,8 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= +golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -681,10 +686,10 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc 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-20220704084225-05e143d24a9e/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= @@ -811,6 +816,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= moul.io/zapgorm2 v1.1.0 h1:qwAlMBYf+qJkJ7PAzJl4oCe6eS6QGiKAXUPeis0+RBE= moul.io/zapgorm2 v1.1.0/go.mod h1:emRfKjNqSzVj5lcgasBdovIXY1jSOwFz2GQZn1Rddks= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/tools/pd-api-bench/README.md b/tools/pd-api-bench/README.md index 019dbd5e6a3..76d568b3787 100644 --- a/tools/pd-api-bench/README.md +++ b/tools/pd-api-bench/README.md @@ -66,7 +66,7 @@ The api bench cases we support are as follows: You can run shell as follows. ```shell -go run main.go -http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 -client 1 -debug true +go run main.go --http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 --client 1 --debug true ``` ### TLS @@ -76,7 +76,7 @@ You can use the following command to generate a certificate for testing TLS: ```shell mkdir cert ./cert_opt.sh generate cert -go run main.go -http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 -client 1 -debug true -cacert ./cert/ca.pem -cert ./cert/pd-server.pem -key ./cert/pd-server-key.pem +go run main.go --http-cases GetRegionStatus-1+1,GetMinResolvedTS-1+1 --client 1 --debug true --cacert ./cert/ca.pem --cert ./cert/pd-server.pem --key ./cert/pd-server-key.pem ./cert_opt.sh cleanup cert rm -rf cert ``` diff --git a/tools/pd-api-bench/cases/controller.go b/tools/pd-api-bench/cases/controller.go index a77474db3a7..75c3c25f7ab 100644 --- a/tools/pd-api-bench/cases/controller.go +++ b/tools/pd-api-bench/cases/controller.go @@ -224,7 +224,7 @@ func (c *httpController) run() { for i := int64(0); i < burst; i++ { go func() { defer c.wg.Done() - var ticker = time.NewTicker(tt) + ticker := time.NewTicker(tt) defer ticker.Stop() for { select { @@ -293,7 +293,7 @@ func (c *gRPCController) run() { for i := int64(0); i < burst; i++ { go func() { defer c.wg.Done() - var ticker = time.NewTicker(tt) + ticker := time.NewTicker(tt) defer ticker.Stop() for { select { @@ -367,7 +367,7 @@ func (c *etcdController) run() { for i := int64(0); i < burst; i++ { go func() { defer c.wg.Done() - var ticker = time.NewTicker(tt) + ticker := time.NewTicker(tt) defer ticker.Stop() for { select { diff --git a/tools/pd-ctl/pdctl/command/scheduler.go b/tools/pd-ctl/pdctl/command/scheduler.go index 4c85bb64037..43c6429cd4f 100644 --- a/tools/pd-ctl/pdctl/command/scheduler.go +++ b/tools/pd-ctl/pdctl/command/scheduler.go @@ -641,6 +641,16 @@ func addStoreToSchedulerConfig(cmd *cobra.Command, schedulerName string, args [] cmd.Println(cmd.UsageString()) return } + + exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } + if !exist { + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) + return + } + storeID, err := strconv.ParseUint(args[0], 10, 64) if err != nil { cmd.Println(err) @@ -768,8 +778,17 @@ func deleteStoreFromSchedulerConfig(cmd *cobra.Command, schedulerName string, ar cmd.Println(cmd.Usage()) return } + exist, err := checkSchedulerExist(cmd, schedulerName) + if err != nil { + return + } + if !exist { + cmd.Printf("Unable to update config: scheduler %s does not exist.\n", schedulerName) + return + } + path := path.Join(schedulerConfigPrefix, "/", schedulerName, "delete", args[0]) - _, err := doRequest(cmd, path, http.MethodDelete, http.Header{}) + _, err = doRequest(cmd, path, http.MethodDelete, http.Header{}) if err != nil { cmd.Println(err) return diff --git a/tools/pd-ctl/tests/scheduler/scheduler_test.go b/tools/pd-ctl/tests/scheduler/scheduler_test.go index 3a6e29f3586..8c96f5ee3fa 100644 --- a/tools/pd-ctl/tests/scheduler/scheduler_test.go +++ b/tools/pd-ctl/tests/scheduler/scheduler_test.go @@ -204,6 +204,12 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { for idx := range schedulers { checkStorePause([]uint64{}, schedulers[idx]) + + // will fail because the scheduler is not existed + args = []string{"-u", pdAddr, "scheduler", "config", schedulers[idx], "add-store", "3"} + output := mustExec(re, cmd, args, nil) + re.Contains(output, fmt.Sprintf("Unable to update config: scheduler %s does not exist.", schedulers[idx])) + // scheduler add command args = []string{"-u", pdAddr, "scheduler", "add", schedulers[idx], "2"} expected = map[string]bool{ @@ -315,7 +321,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) { echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil) re.Contains(echo, "Success!") echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil) - re.Contains(echo, "404") + re.Contains(echo, "Unable to update config: scheduler evict-leader-scheduler does not exist.") testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server. echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", "evict-leader-scheduler"}, nil) return strings.Contains(echo, "[404] scheduler not found") diff --git a/tools/pd-heartbeat-bench/main.go b/tools/pd-heartbeat-bench/main.go index cfa0495c31c..e77f0797bef 100644 --- a/tools/pd-heartbeat-bench/main.go +++ b/tools/pd-heartbeat-bench/main.go @@ -167,7 +167,7 @@ func putStores(ctx context.Context, cfg *config.Config, cli pdpb.PDClient, store log.Fatal("failed to put store", zap.Uint64("store-id", i), zap.String("err", resp.GetHeader().GetError().String())) } go func(ctx context.Context, storeID uint64) { - var heartbeatTicker = time.NewTicker(10 * time.Second) + heartbeatTicker := time.NewTicker(10 * time.Second) defer heartbeatTicker.Stop() for { select { @@ -526,9 +526,9 @@ func main() { header := &pdpb.RequestHeader{ ClusterId: clusterID, } - var heartbeatTicker = time.NewTicker(regionReportInterval * time.Second) + heartbeatTicker := time.NewTicker(regionReportInterval * time.Second) defer heartbeatTicker.Stop() - var resolvedTSTicker = time.NewTicker(time.Second) + resolvedTSTicker := time.NewTicker(time.Second) defer resolvedTSTicker.Stop() withMetric := metrics.InitMetric2Collect(cfg.MetricsAddr) for { diff --git a/tools/pd-simulator/simulator/drive.go b/tools/pd-simulator/simulator/drive.go index 947d0664755..22d4175ecc6 100644 --- a/tools/pd-simulator/simulator/drive.go +++ b/tools/pd-simulator/simulator/drive.go @@ -266,7 +266,6 @@ func (d *Driver) RegionsHeartbeat(ctx context.Context) { healthyNodes[n.Store.GetId()] = true } } - report := 0 for _, region := range regions { hibernatePercent := d.simConfig.HibernatePercent // using rand(0,100) to meet hibernatePercent @@ -280,7 +279,6 @@ func (d *Driver) RegionsHeartbeat(ctx context.Context) { continue } nodesChannel[storeID] <- region.Clone() - report++ } }