Skip to content

Commit

Permalink
*: Auto refresh PD addrs for PDPlacementManager, PDLabelManager, …
Browse files Browse the repository at this point in the history
…`TiFlashPDPlacementManager` (#33909) (#33913)

close #33908
  • Loading branch information
ti-srebot authored Jun 17, 2022
1 parent 0ec9c36 commit 7bb3edf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
12 changes: 4 additions & 8 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ func GlobalInfoSyncerInit(ctx context.Context, id string, serverIDGetter func()
if err != nil {
return nil, err
}
if etcdCli != nil {
is.labelRuleManager = initLabelRuleManager(etcdCli.Endpoints())
} else {
is.labelRuleManager = initLabelRuleManager([]string{})
}
is.labelRuleManager = initLabelRuleManager(etcdCli)
setGlobalInfoSyncer(is)
return is, nil
}
Expand All @@ -208,11 +204,11 @@ func (is *InfoSyncer) GetSessionManager() util2.SessionManager {
return is.manager
}

func initLabelRuleManager(addrs []string) LabelRuleManager {
if len(addrs) == 0 {
func initLabelRuleManager(etcdCli *clientv3.Client) LabelRuleManager {
if etcdCli == nil {
return &mockLabelManager{labelRules: map[string][]byte{}}
}
return &PDLabelManager{addrs: addrs}
return &PDLabelManager{etcdCli: etcdCli}
}

// GetServerInfo gets self server static information.
Expand Down
11 changes: 6 additions & 5 deletions domain/infosync/label_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/pingcap/tidb/ddl/label"
"github.com/pingcap/tidb/util/pdapi"
"go.etcd.io/etcd/clientv3"
)

// LabelRuleManager manages label rules
Expand All @@ -35,7 +36,7 @@ type LabelRuleManager interface {

// PDLabelManager manages rules with pd
type PDLabelManager struct {
addrs []string
etcdCli *clientv3.Client
}

// PutLabelRule implements PutLabelRule
Expand All @@ -44,7 +45,7 @@ func (lm *PDLabelManager) PutLabelRule(ctx context.Context, rule *label.Rule) er
if err != nil {
return err
}
_, err = doRequest(ctx, lm.addrs, path.Join(pdapi.Config, "region-label", "rule"), "POST", bytes.NewReader(r))
_, err = doRequest(ctx, lm.etcdCli.Endpoints(), path.Join(pdapi.Config, "region-label", "rule"), "POST", bytes.NewReader(r))
return err
}

Expand All @@ -55,14 +56,14 @@ func (lm *PDLabelManager) UpdateLabelRules(ctx context.Context, patch *label.Rul
return err
}

_, err = doRequest(ctx, lm.addrs, path.Join(pdapi.Config, "region-label", "rules"), "PATCH", bytes.NewReader(r))
_, err = doRequest(ctx, lm.etcdCli.Endpoints(), path.Join(pdapi.Config, "region-label", "rules"), "PATCH", bytes.NewReader(r))
return err
}

// GetAllLabelRules implements GetAllLabelRules
func (lm *PDLabelManager) GetAllLabelRules(ctx context.Context) ([]*label.Rule, error) {
var rules []*label.Rule
res, err := doRequest(ctx, lm.addrs, path.Join(pdapi.Config, "region-label", "rules"), "GET", nil)
res, err := doRequest(ctx, lm.etcdCli.Endpoints(), path.Join(pdapi.Config, "region-label", "rules"), "GET", nil)

if err == nil && res != nil {
err = json.Unmarshal(res, &rules)
Expand All @@ -78,7 +79,7 @@ func (lm *PDLabelManager) GetLabelRules(ctx context.Context, ruleIDs []string) (
}

rules := []*label.Rule{}
res, err := doRequest(ctx, lm.addrs, path.Join(pdapi.Config, "region-label", "rules", "ids"), "GET", bytes.NewReader(ids))
res, err := doRequest(ctx, lm.etcdCli.Endpoints(), path.Join(pdapi.Config, "region-label", "rules", "ids"), "GET", bytes.NewReader(ids))

if err == nil && res != nil {
err = json.Unmarshal(res, &rules)
Expand Down

0 comments on commit 7bb3edf

Please sign in to comment.