Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add node-id cmd to specify drainer's node-id #684

Merged
merged 8 commits into from
Jul 23, 2019
2 changes: 2 additions & 0 deletions cmd/drainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Usage of drainer:
prometheus pushgateway address, leaves it empty will disable prometheus push
-metrics-interval int
prometheus client push interval in second, set "0" to disable prometheus push (default 15)
-node-id string
the ID of drainer node; if not specify, we will generate one from hostname and the listening port
suzaku marked this conversation as resolved.
Show resolved Hide resolved
-pd-urls string
a comma separated list of PD endpoints (default "http://127.0.0.1:2379")
-safe-mode
Expand Down
2 changes: 2 additions & 0 deletions drainer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type SyncerConfig struct {
type Config struct {
*flag.FlagSet `json:"-"`
LogLevel string `toml:"log-level" json:"log-level"`
NodeID string `toml:"node-id" json:"node-id"`
ListenAddr string `toml:"addr" json:"addr"`
AdvertiseAddr string `toml:"advertise-addr" json:"advertise-addr"`
DataDir string `toml:"data-dir" json:"data-dir"`
Expand Down Expand Up @@ -109,6 +110,7 @@ func NewConfig() *Config {
fmt.Fprintln(os.Stderr, "Usage of drainer:")
fs.PrintDefaults()
}
fs.StringVar(&cfg.NodeID, "node-id", "", "the ID of drainer node; if not specify, we will generate one from hostname and the listening port")
suzaku marked this conversation as resolved.
Show resolved Hide resolved
fs.StringVar(&cfg.ListenAddr, "addr", util.DefaultListenAddr(8249), "addr (i.e. 'host:port') to listen on for drainer connections")
fs.StringVar(&cfg.AdvertiseAddr, "advertise-addr", "", "addr(i.e. 'host:port') to advertise to the public, default to be the same value as -addr")
fs.StringVar(&cfg.DataDir, "data-dir", defaultDataDir, "drainer data directory path (default data.drainer)")
Expand Down
12 changes: 9 additions & 3 deletions drainer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ func init() {

// NewServer return a instance of binlog-server
func NewServer(cfg *Config) (*Server, error) {
ID, err := genDrainerID(cfg.ListenAddr)
if err != nil {
return nil, errors.Trace(err)
var ID string
lichunzhu marked this conversation as resolved.
Show resolved Hide resolved
if cfg.NodeID != "" {
ID = cfg.NodeID
} else {
var err error
ID, err = genDrainerID(cfg.ListenAddr)
if err != nil {
return nil, errors.Trace(err)
}
}

if err := os.MkdirAll(cfg.DataDir, 0700); err != nil {
Expand Down