Skip to content

Commit

Permalink
add node-id cmd to specify drainer's node-id (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
lichunzhu authored and july2993 committed Aug 13, 2019
1 parent 7123aba commit 5d4831a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
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 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
Expand Down
2 changes: 1 addition & 1 deletion cmd/pump/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions drainer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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 @@ -97,6 +98,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 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)")
Expand Down
17 changes: 10 additions & 7 deletions drainer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ngaut/log"
"github.com/pingcap/errors"
"github.com/pingcap/parser/model"
"github.com/pingcap/pd/client"
pd "github.com/pingcap/pd/client"
"github.com/pingcap/tidb-binlog/drainer/checkpoint"
"github.com/pingcap/tidb-binlog/pkg/flags"
"github.com/pingcap/tidb-binlog/pkg/node"
Expand Down Expand Up @@ -72,13 +72,16 @@ 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)
if cfg.NodeID == "" {
var err error
cfg.NodeID, err = genDrainerID(cfg.ListenAddr)
if err != nil {
return nil, errors.Trace(err)
}
}

if err1 := os.MkdirAll(cfg.DataDir, 0700); err1 != nil {
return nil, err
return nil, err1
}

// get pd client and cluster ID
Expand Down Expand Up @@ -133,10 +136,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,
Expand Down
2 changes: 1 addition & 1 deletion pump/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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")
Expand Down

0 comments on commit 5d4831a

Please sign in to comment.