From d7a5908c912d814c3dc0cc6ad4dbf48174193bb8 Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Thu, 18 Jul 2019 16:16:21 +0800 Subject: [PATCH 1/4] add node-id cmd for drainer to specify drainer's node-id and update drainer README --- cmd/drainer/README.md | 2 ++ drainer/config.go | 2 ++ drainer/server.go | 12 +++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/drainer/README.md b/cmd/drainer/README.md index ab70faea9..226ddc859 100644 --- a/cmd/drainer/README.md +++ b/cmd/drainer/README.md @@ -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 -pd-urls string a comma separated list of PD endpoints (default "http://127.0.0.1:2379") -safe-mode diff --git a/drainer/config.go b/drainer/config.go index 42e4a212f..38d67fd4d 100644 --- a/drainer/config.go +++ b/drainer/config.go @@ -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"` @@ -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") 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)") diff --git a/drainer/server.go b/drainer/server.go index 0a6f79c5a..5f551b1eb 100644 --- a/drainer/server.go +++ b/drainer/server.go @@ -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 + 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 { From b20b06411c2d6fa8a93d6c94bed6beeff2ca2044 Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Mon, 22 Jul 2019 15:30:29 +0800 Subject: [PATCH 2/4] fix syntax error in drainer & pump's README --- cmd/drainer/README.md | 2 +- cmd/pump/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/drainer/README.md b/cmd/drainer/README.md index 226ddc859..0921b9a76 100644 --- a/cmd/drainer/README.md +++ b/cmd/drainer/README.md @@ -42,7 +42,7 @@ Usage of drainer: -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 + the ID of drainer node; if not specified, we will generate one from hostname and the listening port -pd-urls string a comma separated list of PD endpoints (default "http://127.0.0.1:2379") -safe-mode diff --git a/cmd/pump/README.md b/cmd/pump/README.md index 44228b4f7..bde9bd4f4 100644 --- a/cmd/pump/README.md +++ b/cmd/pump/README.md @@ -34,7 +34,7 @@ pump is a daemon that receives realtime binlog from tidb-server and writes in se -metrics-interval int prometheus client push interval in second, set "0" to disable prometheus push (default 15) -node-id string - the ID of pump node; if not specify, we will generate one from hostname and the listening port + the ID of pump node; if not specified, we will generate one from hostname and the listening port -pd-urls string a comma separated list of the PD endpoints (default "http://127.0.0.1:2379") -zookeeper-addrs string From 9905feafbae734622cb6a6800799d7f69877d703 Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Mon, 22 Jul 2019 18:36:15 +0800 Subject: [PATCH 3/4] fix syntax error in drainer & pump's config.go --- drainer/config.go | 2 +- pump/config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drainer/config.go b/drainer/config.go index 38d67fd4d..f9f90bfa0 100644 --- a/drainer/config.go +++ b/drainer/config.go @@ -110,7 +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") + fs.StringVar(&cfg.NodeID, "node-id", "", "the ID of drainer node; if not specified, we will generate one from hostname and the listening port") 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)") diff --git a/pump/config.go b/pump/config.go index b3a4932bb..987c7aec9 100644 --- a/pump/config.go +++ b/pump/config.go @@ -93,7 +93,7 @@ func NewConfig() *Config { fs.PrintDefaults() } - fs.StringVar(&cfg.NodeID, "node-id", "", "the ID of pump node; if not specify, we will generate one from hostname and the listening port") + fs.StringVar(&cfg.NodeID, "node-id", "", "the ID of pump node; if not specified, we will generate one from hostname and the listening port") fs.StringVar(&cfg.ListenAddr, "addr", util.DefaultListenAddr(8250), "addr(i.e. 'host:port') to listen on for client traffic") fs.StringVar(&cfg.AdvertiseAddr, "advertise-addr", "", "addr(i.e. 'host:port') to advertise to the public") fs.StringVar(&cfg.Socket, "socket", "", "unix socket addr to listen on for client traffic") From 62cb8e9b75bfc18eee52e890d780486a903da7df Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Mon, 22 Jul 2019 18:51:03 +0800 Subject: [PATCH 4/4] simplify drainer/server.go by removing variable ID --- drainer/server.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drainer/server.go b/drainer/server.go index 5f551b1eb..df00b2cd6 100644 --- a/drainer/server.go +++ b/drainer/server.go @@ -86,12 +86,9 @@ func init() { // NewServer return a instance of binlog-server func NewServer(cfg *Config) (*Server, error) { - var ID string - if cfg.NodeID != "" { - ID = cfg.NodeID - } else { + if cfg.NodeID == "" { var err error - ID, err = genDrainerID(cfg.ListenAddr) + cfg.NodeID, err = genDrainerID(cfg.ListenAddr) if err != nil { return nil, errors.Trace(err) } @@ -154,10 +151,10 @@ func NewServer(cfg *Config) (*Server, error) { return nil, errors.Annotatef(err, "invalid configuration of advertise addr(%s)", cfg.AdvertiseAddr) } - status := node.NewStatus(ID, advURL.Host, node.Online, 0, syncer.GetLatestCommitTS(), util.GetApproachTS(latestTS, latestTime)) + status := node.NewStatus(cfg.NodeID, advURL.Host, node.Online, 0, syncer.GetLatestCommitTS(), util.GetApproachTS(latestTS, latestTime)) return &Server{ - ID: ID, + ID: cfg.NodeID, host: advURL.Host, cfg: cfg, collector: c,