Skip to content

Commit

Permalink
Don't check labels when user enable placement-rule (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklove authored and AstroProfundis committed May 26, 2021
1 parent 39c3942 commit cead1ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pkg/cluster/api/pdapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,18 +692,18 @@ func (pc *PDClient) GetReplicateConfig() ([]byte, error) {
}

// GetLocationLabels gets the replication.location-labels config from pd server
func (pc *PDClient) GetLocationLabels() ([]string, error) {
func (pc *PDClient) GetLocationLabels() ([]string, bool, error) {
config, err := pc.GetReplicateConfig()
if err != nil {
return nil, err
return nil, false, err
}

rc := PDReplicationConfig{}
if err := json.Unmarshal(config, &rc); err != nil {
return nil, perrs.Annotatef(err, "unmarshal replication config: %s", string(config))
return nil, false, perrs.Annotatef(err, "unmarshal replication config: %s", string(config))
}

return rc.LocationLabels, nil
return rc.LocationLabels, rc.EnablePlacementRules, nil
}

// GetTiKVLabels implements TiKVLabelProvider
Expand Down
9 changes: 6 additions & 3 deletions pkg/cluster/manager/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ func (m *Manager) Display(name string, opt operator.Options) error {
if t, ok := topo.(*spec.Specification); ok {
// Check if TiKV's label set correctly
pdClient := api.NewPDClient(masterActive, 10*time.Second, tlsCfg)
if lbs, err := pdClient.GetLocationLabels(); err != nil {

if lbs, placementRule, err := pdClient.GetLocationLabels(); err != nil {
log.Debugf("get location labels from pd failed: %v", err)
} else if err := spec.CheckTiKVLabels(lbs, pdClient); err != nil {
color.Yellow("\nWARN: there is something wrong with TiKV labels, which may cause data losing:\n%v", err)
} else if !placementRule {
if err := spec.CheckTiKVLabels(lbs, pdClient); err != nil {
color.Yellow("\nWARN: there is something wrong with TiKV labels, which may cause data losing:\n%v", err)
}
}

// Check if there is some instance in tombstone state
Expand Down
8 changes: 5 additions & 3 deletions pkg/cluster/manager/scale_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ func (m *Manager) ScaleOut(
return err
}
pdClient := api.NewPDClient(pdList, 10*time.Second, tlsCfg)
lbs, err := pdClient.GetLocationLabels()
lbs, placementRule, err := pdClient.GetLocationLabels()
if err != nil {
return err
}
if err := spec.CheckTiKVLabels(lbs, mergedTopo.(*spec.Specification)); err != nil {
return perrs.Errorf("check TiKV label failed, please fix that before continue:\n%s", err)
if !placementRule {
if err := spec.CheckTiKVLabels(lbs, mergedTopo.(*spec.Specification)); err != nil {
return perrs.Errorf("check TiKV label failed, please fix that before continue:\n%s", err)
}
}
}

Expand Down

0 comments on commit cead1ea

Please sign in to comment.