Skip to content

Commit

Permalink
add name to pdms (#2420)
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp authored May 30, 2024
1 parent 3352a93 commit 3519319
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
11 changes: 10 additions & 1 deletion components/playground/instance/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ func (inst *PDInstance) InitCluster(pds []*PDInstance) *PDInstance {

// Name return the name of pd.
func (inst *PDInstance) Name() string {
return fmt.Sprintf("pd-%d", inst.ID)
switch inst.Role {
case PDRoleTSO:
return fmt.Sprintf("tso-%d", inst.ID)
case PDRoleScheduling:
return fmt.Sprintf("scheduling-%d", inst.ID)
default:
return fmt.Sprintf("pd-%d", inst.ID)
}
}

// Start calls set inst.cmd and Start
Expand Down Expand Up @@ -137,6 +144,7 @@ func (inst *PDInstance) Start(ctx context.Context, version utils.Version) error
args = []string{
"services",
"tso",
"--name=" + uid,
fmt.Sprintf("--listen-addr=http://%s", utils.JoinHostPort(inst.Host, inst.StatusPort)),
fmt.Sprintf("--advertise-listen-addr=http://%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.StatusPort)),
fmt.Sprintf("--backend-endpoints=%s", strings.Join(endpoints, ",")),
Expand All @@ -148,6 +156,7 @@ func (inst *PDInstance) Start(ctx context.Context, version utils.Version) error
args = []string{
"services",
"scheduling",
"--name=" + uid,
fmt.Sprintf("--listen-addr=http://%s", utils.JoinHostPort(inst.Host, inst.StatusPort)),
fmt.Sprintf("--advertise-listen-addr=http://%s", utils.JoinHostPort(AdvertiseHost(inst.Host), inst.StatusPort)),
fmt.Sprintf("--backend-endpoints=%s", strings.Join(endpoints, ",")),
Expand Down
1 change: 1 addition & 0 deletions embed/templates/scripts/run_scheduling.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=mad
{{- else}}
exec env GODEBUG=madvdontneed=1 bin/pd-server services scheduling \
{{- end}}
--name="{{.Name}}" \
--backend-endpoints="{{.BackendEndpoints}}" \
--listen-addr="{{.ListenURL}}" \
--advertise-listen-addr="{{.AdvertiseListenURL}}" \
Expand Down
1 change: 1 addition & 0 deletions embed/templates/scripts/run_tso.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exec numactl --cpunodebind={{.NumaNode}} --membind={{.NumaNode}} env GODEBUG=mad
{{- else}}
exec env GODEBUG=madvdontneed=1 bin/pd-server services tso \
{{- end}}
--name="{{.Name}}" \
--backend-endpoints="{{.BackendEndpoints}}" \
--listen-addr="{{.ListenURL}}" \
--advertise-listen-addr="{{.AdvertiseListenURL}}" \
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/spec/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

// SchedulingSpec represents the scheduling topology specification in topology.yaml
type SchedulingSpec struct {
// Use Name to get the name with a default value if it's empty.
Name string `yaml:"name"`
Host string `yaml:"host"`
ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
ListenHost string `yaml:"listen_host,omitempty"`
Expand Down Expand Up @@ -169,7 +171,7 @@ func (c *SchedulingComponent) Instances() []Instance {
ins = append(ins, &SchedulingInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Name: s.Name,
Host: s.Host,
ManageHost: s.ManageHost,
ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string),
Expand Down Expand Up @@ -229,6 +231,7 @@ func (i *SchedulingInstance) InitConfig(
pds = append(pds, pdspec.GetAdvertiseClientURL(enableTLS))
}
cfg := &scripts.SchedulingScript{
Name: spec.Name,
ListenURL: fmt.Sprintf("%s://%s", scheme, utils.JoinHostPort(i.GetListenHost(), spec.Port)),
AdvertiseListenURL: spec.GetAdvertiseListenURL(enableTLS),
BackendEndpoints: strings.Join(pds, ","),
Expand Down
5 changes: 4 additions & 1 deletion pkg/cluster/spec/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

// TSOSpec represents the TSO topology specification in topology.yaml
type TSOSpec struct {
// Use Name to get the name with a default value if it's empty.
Name string `yaml:"name"`
Host string `yaml:"host"`
ManageHost string `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
ListenHost string `yaml:"listen_host,omitempty"`
Expand Down Expand Up @@ -169,7 +171,7 @@ func (c *TSOComponent) Instances() []Instance {
ins = append(ins, &TSOInstance{
BaseInstance: BaseInstance{
InstanceSpec: s,
Name: c.Name(),
Name: s.Name,
Host: s.Host,
ManageHost: s.ManageHost,
ListenHost: utils.Ternary(s.ListenHost != "", s.ListenHost, c.Topology.BaseTopo().GlobalOptions.ListenHost).(string),
Expand Down Expand Up @@ -229,6 +231,7 @@ func (i *TSOInstance) InitConfig(
pds = append(pds, pdspec.GetAdvertiseClientURL(enableTLS))
}
cfg := &scripts.TSOScript{
Name: spec.Name,
ListenURL: fmt.Sprintf("%s://%s", scheme, utils.JoinHostPort(i.GetListenHost(), spec.Port)),
AdvertiseListenURL: spec.GetAdvertiseListenURL(enableTLS),
BackendEndpoints: strings.Join(pds, ","),
Expand Down
34 changes: 34 additions & 0 deletions pkg/cluster/spec/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,38 @@ func (s *Specification) validatePDNames() error {
return nil
}

func (s *Specification) validateTSONames() error {
// check tso server name
tsoNames := set.NewStringSet()
for _, tso := range s.TSOServers {
if tso.Name == "" {
continue
}

if tsoNames.Exist(tso.Name) {
return errors.Errorf("component tso_servers.name is not supported duplicated, the name %s is duplicated", tso.Name)
}
tsoNames.Insert(tso.Name)
}
return nil
}

func (s *Specification) validateSchedulingNames() error {
// check scheduling server name
schedulingNames := set.NewStringSet()
for _, scheduling := range s.SchedulingServers {
if scheduling.Name == "" {
continue
}

if schedulingNames.Exist(scheduling.Name) {
return errors.Errorf("component scheduling_servers.name is not supported duplicated, the name %s is duplicated", scheduling.Name)
}
schedulingNames.Insert(scheduling.Name)
}
return nil
}

func (s *Specification) validateTiFlashConfigs() error {
c := FindComponent(s, ComponentTiFlash)
for _, ins := range c.Instances() {
Expand Down Expand Up @@ -1063,6 +1095,8 @@ func (s *Specification) Validate() error {
s.dirConflictsDetect,
s.validateUserGroup,
s.validatePDNames,
s.validateTSONames,
s.validateSchedulingNames,
s.validateTiSparkSpec,
s.validateTiFlashConfigs,
s.validateMonitorAgent,
Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/template/scripts/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"path"
"text/template"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/embed"
"github.com/pingcap/tiup/pkg/utils"
)

// SchedulingScript represent the data to generate scheduling config
type SchedulingScript struct {
Name string
ListenURL string
AdvertiseListenURL string
BackendEndpoints string
Expand All @@ -48,6 +50,10 @@ func (c *SchedulingScript) ConfigToFile(file string) error {
return err
}

if c.Name == "" {
return errors.New("empty name")
}

content := bytes.NewBufferString("")
if err := tmpl.Execute(content, c); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions pkg/cluster/template/scripts/tso.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"path"
"text/template"

"github.com/pingcap/errors"
"github.com/pingcap/tiup/embed"
"github.com/pingcap/tiup/pkg/utils"
)

// TSOScript represent the data to generate tso config
type TSOScript struct {
Name string
ListenURL string
AdvertiseListenURL string
BackendEndpoints string
Expand All @@ -48,6 +50,10 @@ func (c *TSOScript) ConfigToFile(file string) error {
return err
}

if c.Name == "" {
return errors.New("empty name")
}

content := bytes.NewBufferString("")
if err := tmpl.Execute(content, c); err != nil {
return err
Expand Down

0 comments on commit 3519319

Please sign in to comment.