Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

*: unify the etcd naming #8496

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

Filter by extension

Filter by extension

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

Expand Down
4 changes: 2 additions & 2 deletions pkg/mcs/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions server/gc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@

startkey := endpoint.GCSafePointV2Prefix()
endkey := clientv3.GetPrefixRangeEnd(startkey)
_, values, revision, err := s.loadRangeFromETCD(startkey, endkey)
_, values, revision, err := s.loadRangeFromEtcd(startkey, endkey)

Check warning on line 208 in server/gc_service.go

View check run for this annotation

Codecov / codecov/patch

server/gc_service.go#L208

Added line #L208 was not covered by tests

gcSafePoints := make([]*pdpb.GCSafePointV2, 0, len(values))
for _, value := range values {
Expand Down Expand Up @@ -236,7 +236,7 @@
}, nil
}

func (s *GrpcServer) loadRangeFromETCD(startKey, endKey string) ([]string, []string, int64, error) {
func (s *GrpcServer) loadRangeFromEtcd(startKey, endKey string) ([]string, []string, int64, error) {

Check warning on line 239 in server/gc_service.go

View check run for this annotation

Codecov / codecov/patch

server/gc_service.go#L239

Added line #L239 was not covered by tests
startKey = strings.Join([]string{s.rootPath, startKey}, "/")
var opOption []clientv3.OpOption
if endKey == "\x00" {
Expand Down
28 changes: 14 additions & 14 deletions tools/pd-api-bench/cases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions tools/pd-api-bench/cases/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -324,7 +324,7 @@ func (c *gRPCController) stop() {
}

type etcdController struct {
ETCDCase
EtcdCase
clients []*clientv3.Client
pctx context.Context

Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions tools/pd-api-bench/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
Expand Down
8 changes: 4 additions & 4 deletions tools/pd-api-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
})

Expand Down Expand Up @@ -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
Expand Down