Skip to content

Commit

Permalink
add config-check flag for pd-server (tikv#1695)
Browse files Browse the repository at this point in the history
Signed-off-by: cwen0 <cwenyin0@gmail.com>
  • Loading branch information
cwen0 committed Aug 28, 2019
1 parent afba07a commit e89d334
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func main() {
default:
log.Fatal("parse cmd flags error", zap.Error(err))
}

if cfg.ConfigCheck {
server.PrintConfigCheckMsg(cfg)
exit(0)
}

// New zap logger
err = cfg.SetupLogger()
if err == nil {
Expand Down
3 changes: 3 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Config struct {

Version bool `json:"-"`

ConfigCheck bool `json:"-"`

ClientUrls string `toml:"client-urls" json:"client-urls"`
PeerUrls string `toml:"peer-urls" json:"peer-urls"`
AdvertiseClientUrls string `toml:"advertise-client-urls" json:"advertise-client-urls"`
Expand Down Expand Up @@ -145,6 +147,7 @@ func NewConfig() *Config {
fs.BoolVar(&cfg.Version, "V", false, "print version information and exit")
fs.BoolVar(&cfg.Version, "version", false, "print version information and exit")
fs.StringVar(&cfg.configFile, "config", "", "Config file")
fs.BoolVar(&cfg.ConfigCheck, "config-check", false, "check config file validity and exit")

fs.StringVar(&cfg.Name, "name", "", "human-readable name for this pd member")

Expand Down
12 changes: 12 additions & 0 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ func PrintPDInfo() {
fmt.Println("UTC Build Time: ", PDBuildTS)
}

// PrintConfigCheckMsg prints the message about configuration checks.
func PrintConfigCheckMsg(cfg *config.Config) {
if len(cfg.WarningMsgs) == 0 {
fmt.Println("config check successful")
return
}

for _, msg := range cfg.WarningMsgs {
fmt.Println(msg)
}
}

// CheckPDVersion checks if PD needs to be upgraded.
func CheckPDVersion(opt *scheduleOption) {
pdVersion := MinSupportedVersion(Base)
Expand Down

0 comments on commit e89d334

Please sign in to comment.