Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

*: export advertise-addr as the command arg; use master-addr #484

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 16 additions & 8 deletions dm/master/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func NewConfig() *Config {
fs.BoolVar(&cfg.printSampleConfig, "print-sample-config", false, "print sample config file of dm-worker")
fs.StringVar(&cfg.ConfigFile, "config", "", "path to config file")
fs.StringVar(&cfg.MasterAddr, "master-addr", "", "master API server and status addr")
fs.StringVar(&cfg.AdvertiseAddr, "advertise-addr", "", `advertise address for client traffic (default "${master-addr}")`)
fs.StringVar(&cfg.LogLevel, "L", "info", "log level: debug, info, warn, error, fatal")
fs.StringVar(&cfg.LogFile, "log-file", "", "log file path")
//fs.StringVar(&cfg.LogRotate, "log-rotate", "day", "log file rotate type, hour/day")
Expand Down Expand Up @@ -202,18 +203,25 @@ func (c *Config) configFromFile(path string) error {
// adjust adjusts configs
func (c *Config) adjust() error {
// MasterAddr's format may be "host:port" or ":port"
_, _, err := net.SplitHostPort(c.MasterAddr)
host, _, err := net.SplitHostPort(c.MasterAddr)
if err != nil {
return terror.ErrMasterHostPortNotValid.Delegate(err, c.MasterAddr)
}

// AdvertiseAddr's format must be "host:port"
host, port, err := net.SplitHostPort(c.AdvertiseAddr)
if err != nil {
return terror.ErrMasterAdvertiseAddrNotValid.Delegate(err, c.AdvertiseAddr)
}
if len(host) == 0 || len(port) == 0 {
return terror.ErrMasterAdvertiseAddrNotValid.Generate(c.AdvertiseAddr)
if c.AdvertiseAddr == "" {
if host == "" || host == "0.0.0.0" {
lichunzhu marked this conversation as resolved.
Show resolved Hide resolved
return terror.ErrMasterHostPortNotValid.Generatef("master-addr (%s) must include the 'host' part (should not be '0.0.0.0') when advertise-addr is not set", c.MasterAddr)
}
c.AdvertiseAddr = c.MasterAddr
} else {
// AdvertiseAddr's format must be "host:port"
host, port, err2 := net.SplitHostPort(c.AdvertiseAddr)
if err2 != nil {
return terror.ErrMasterAdvertiseAddrNotValid.Delegate(err2, c.AdvertiseAddr)
}
if len(host) == 0 || host == "0.0.0.0" || len(port) == 0 {
return terror.ErrMasterAdvertiseAddrNotValid.Generate(c.AdvertiseAddr)
}
}

c.DeployMap = make(map[string]string)
Expand Down
9 changes: 6 additions & 3 deletions dm/worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ func (c *Config) adjust() error {
}
c.AdvertiseAddr = c.WorkerAddr
} else {
host, _, err = net.SplitHostPort(c.AdvertiseAddr)
if err != nil || host == "" || host == "0.0.0.0" {
return terror.ErrWorkerHostPortNotValid.AnnotateDelegate(err, "advertise-addr (%s) must include the 'host' part and should not be '0.0.0.0'", c.AdvertiseAddr)
host, port, err2 := net.SplitHostPort(c.AdvertiseAddr)
if err2 != nil {
return terror.ErrWorkerHostPortNotValid.Delegate(err2, c.AdvertiseAddr)
}
if host == "" || host == "0.0.0.0" || len(port) == 0 {
return terror.ErrWorkerHostPortNotValid.Generate("advertise-addr (%s) must include the 'host' part and should not be '0.0.0.0'", c.AdvertiseAddr)
}
}

Expand Down