From 29b83fb9a92340f3302808f9009d7ef0fc8208a7 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 6 Aug 2024 15:56:09 +0800 Subject: [PATCH] *: unify the etcd naming (#8496) ref tikv/pd#4399 Signed-off-by: Ryan Leung --- pkg/mcs/server/server.go | 4 ++-- pkg/mcs/utils/util.go | 4 ++-- server/gc_service.go | 4 ++-- tools/pd-api-bench/cases/cases.go | 28 +++++++++++++------------- tools/pd-api-bench/cases/controller.go | 20 +++++++++--------- tools/pd-api-bench/config/config.go | 6 +++--- tools/pd-api-bench/main.go | 8 ++++---- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/pkg/mcs/server/server.go b/pkg/mcs/server/server.go index 6aec799278c..d30d3337a46 100644 --- a/pkg/mcs/server/server.go +++ b/pkg/mcs/server/server.go @@ -95,8 +95,8 @@ func (bs *BaseServer) GetHTTPClient() *http.Client { return bs.httpClient } -// SetETCDClient sets the etcd client. -func (bs *BaseServer) SetETCDClient(etcdClient *clientv3.Client) { +// SetEtcdClient sets the etcd client. +func (bs *BaseServer) SetEtcdClient(etcdClient *clientv3.Client) { bs.etcdClient = etcdClient } diff --git a/pkg/mcs/utils/util.go b/pkg/mcs/utils/util.go index 844cf17fde4..55e6c54e9b9 100644 --- a/pkg/mcs/utils/util.go +++ b/pkg/mcs/utils/util.go @@ -107,7 +107,7 @@ type server interface { GetGRPCServer() *grpc.Server SetGRPCServer(*grpc.Server) SetHTTPServer(*http.Server) - SetETCDClient(*clientv3.Client) + SetEtcdClient(*clientv3.Client) SetHTTPClient(*http.Client) IsSecure() bool RegisterGRPCService(*grpc.Server) @@ -183,7 +183,7 @@ func InitClient(s server) error { if err != nil { return err } - s.SetETCDClient(etcdClient) + s.SetEtcdClient(etcdClient) s.SetHTTPClient(etcdutil.CreateHTTPClient(tlsConfig)) return nil } diff --git a/server/gc_service.go b/server/gc_service.go index db3879a74fb..8c967d542ee 100644 --- a/server/gc_service.go +++ b/server/gc_service.go @@ -205,7 +205,7 @@ func (s *GrpcServer) GetAllGCSafePointV2(ctx context.Context, request *pdpb.GetA startkey := endpoint.GCSafePointV2Prefix() endkey := clientv3.GetPrefixRangeEnd(startkey) - _, values, revision, err := s.loadRangeFromETCD(startkey, endkey) + _, values, revision, err := s.loadRangeFromEtcd(startkey, endkey) gcSafePoints := make([]*pdpb.GCSafePointV2, 0, len(values)) for _, value := range values { @@ -236,7 +236,7 @@ func (s *GrpcServer) GetAllGCSafePointV2(ctx context.Context, request *pdpb.GetA }, nil } -func (s *GrpcServer) loadRangeFromETCD(startKey, endKey string) ([]string, []string, int64, error) { +func (s *GrpcServer) loadRangeFromEtcd(startKey, endKey string) ([]string, []string, int64, error) { startKey = strings.Join([]string{s.rootPath, startKey}, "/") var opOption []clientv3.OpOption if endKey == "\x00" { diff --git a/tools/pd-api-bench/cases/cases.go b/tools/pd-api-bench/cases/cases.go index 18d5c8732e6..6ffa429fdb7 100644 --- a/tools/pd-api-bench/cases/cases.go +++ b/tools/pd-api-bench/cases/cases.go @@ -117,18 +117,18 @@ func (c *baseCase) GetConfig() *Config { return c.cfg.Clone() } -// ETCDCase is the interface for all etcd api cases. -type ETCDCase interface { +// EtcdCase is the interface for all etcd api cases. +type EtcdCase interface { Case Init(context.Context, *clientv3.Client) error Unary(context.Context, *clientv3.Client) error } -// ETCDCreateFn is function type to create ETCDCase. -type ETCDCreateFn func() ETCDCase +// EtcdCreateFn is function type to create EtcdCase. +type EtcdCreateFn func() EtcdCase -// ETCDCaseFnMap is the map for all ETCD case creation function. -var ETCDCaseFnMap = map[string]ETCDCreateFn{ +// EtcdCaseFnMap is the map for all etcd case creation function. +var EtcdCaseFnMap = map[string]EtcdCreateFn{ "Get": newGetKV(), "Put": newPutKV(), "Delete": newDeleteKV(), @@ -440,8 +440,8 @@ type getKV struct { *baseCase } -func newGetKV() func() ETCDCase { - return func() ETCDCase { +func newGetKV() func() EtcdCase { + return func() EtcdCase { return &getKV{ baseCase: &baseCase{ name: "Get", @@ -470,8 +470,8 @@ type putKV struct { *baseCase } -func newPutKV() func() ETCDCase { - return func() ETCDCase { +func newPutKV() func() EtcdCase { + return func() EtcdCase { return &putKV{ baseCase: &baseCase{ name: "Put", @@ -492,8 +492,8 @@ type deleteKV struct { *baseCase } -func newDeleteKV() func() ETCDCase { - return func() ETCDCase { +func newDeleteKV() func() EtcdCase { + return func() EtcdCase { return &deleteKV{ baseCase: &baseCase{ name: "Put", @@ -514,8 +514,8 @@ type txnKV struct { *baseCase } -func newTxnKV() func() ETCDCase { - return func() ETCDCase { +func newTxnKV() func() EtcdCase { + return func() EtcdCase { return &txnKV{ baseCase: &baseCase{ name: "Put", diff --git a/tools/pd-api-bench/cases/controller.go b/tools/pd-api-bench/cases/controller.go index 42eeafe4597..dc48b5280cf 100644 --- a/tools/pd-api-bench/cases/controller.go +++ b/tools/pd-api-bench/cases/controller.go @@ -77,8 +77,8 @@ func (c *Coordinator) GetGRPCCase(name string) (*Config, error) { return nil, errors.Errorf("case %v does not exist", name) } -// GetETCDCase returns the etcd case config. -func (c *Coordinator) GetETCDCase(name string) (*Config, error) { +// GetEtcdCase returns the etcd case config. +func (c *Coordinator) GetEtcdCase(name string) (*Config, error) { c.mu.RLock() defer c.mu.RUnlock() if controller, ok := c.etcd[name]; ok { @@ -109,8 +109,8 @@ func (c *Coordinator) GetAllGRPCCases() map[string]*Config { return ret } -// GetAllETCDCases returns the all etcd case configs. -func (c *Coordinator) GetAllETCDCases() map[string]*Config { +// GetAllEtcdCases returns the all etcd case configs. +func (c *Coordinator) GetAllEtcdCases() map[string]*Config { c.mu.RLock() defer c.mu.RUnlock() ret := make(map[string]*Config) @@ -164,11 +164,11 @@ func (c *Coordinator) SetGRPCCase(name string, cfg *Config) error { return nil } -// SetETCDCase sets the config for the specific case. -func (c *Coordinator) SetETCDCase(name string, cfg *Config) error { +// SetEtcdCase sets the config for the specific case. +func (c *Coordinator) SetEtcdCase(name string, cfg *Config) error { c.mu.Lock() defer c.mu.Unlock() - if fn, ok := ETCDCaseFnMap[name]; ok { + if fn, ok := EtcdCaseFnMap[name]; ok { var controller *etcdController if controller, ok = c.etcd[name]; !ok { controller = newEtcdController(c.ctx, c.etcdClients, fn) @@ -324,7 +324,7 @@ func (c *gRPCController) stop() { } type etcdController struct { - ETCDCase + EtcdCase clients []*clientv3.Client pctx context.Context @@ -334,11 +334,11 @@ type etcdController struct { wg sync.WaitGroup } -func newEtcdController(ctx context.Context, clis []*clientv3.Client, fn ETCDCreateFn) *etcdController { +func newEtcdController(ctx context.Context, clis []*clientv3.Client, fn EtcdCreateFn) *etcdController { c := &etcdController{ pctx: ctx, clients: clis, - ETCDCase: fn(), + EtcdCase: fn(), } return c } diff --git a/tools/pd-api-bench/config/config.go b/tools/pd-api-bench/config/config.go index 35377c12f33..0320665c29b 100644 --- a/tools/pd-api-bench/config/config.go +++ b/tools/pd-api-bench/config/config.go @@ -44,7 +44,7 @@ type Config struct { // only for init HTTP map[string]cases.Config `toml:"http" json:"http"` GRPC map[string]cases.Config `toml:"grpc" json:"grpc"` - ETCD map[string]cases.Config `toml:"etcd" json:"etcd"` + Etcd map[string]cases.Config `toml:"etcd" json:"etcd"` } // NewConfig return a set of settings. @@ -109,9 +109,9 @@ func (c *Config) InitCoordinator(co *cases.Coordinator) { log.Error("create gRPC case failed", zap.Error(err)) } } - for name, cfg := range c.ETCD { + for name, cfg := range c.Etcd { cfg := cfg - err := co.SetETCDCase(name, &cfg) + err := co.SetEtcdCase(name, &cfg) if err != nil { log.Error("create etcd case failed", zap.Error(err)) } diff --git a/tools/pd-api-bench/main.go b/tools/pd-api-bench/main.go index 747fbaa10c1..78bec1e1d01 100644 --- a/tools/pd-api-bench/main.go +++ b/tools/pd-api-bench/main.go @@ -292,14 +292,14 @@ func runHTTPServer(cfg *config.Config, co *cases.Coordinator) { } for name, cfg := range input { cfg := cfg - co.SetETCDCase(name, &cfg) + co.SetEtcdCase(name, &cfg) } c.String(http.StatusOK, "") }) engine.POST("config/etcd/:name", func(c *gin.Context) { name := c.Param("name") cfg := getCfg(c) - co.SetETCDCase(name, cfg) + co.SetEtcdCase(name, cfg) c.String(http.StatusOK, "") }) @@ -330,12 +330,12 @@ func runHTTPServer(cfg *config.Config, co *cases.Coordinator) { c.IndentedJSON(http.StatusOK, cfg) }) engine.GET("config/etcd/all", func(c *gin.Context) { - all := co.GetAllETCDCases() + all := co.GetAllEtcdCases() c.IndentedJSON(http.StatusOK, all) }) engine.GET("config/etcd/:name", func(c *gin.Context) { name := c.Param("name") - cfg, err := co.GetETCDCase(name) + cfg, err := co.GetEtcdCase(name) if err != nil { c.String(http.StatusBadRequest, err.Error()) return