Skip to content

Commit

Permalink
binlogctl: Only show offline nodes when explicitly told so
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku committed Oct 17, 2019
1 parent a8cfbfb commit bece556
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
24 changes: 13 additions & 11 deletions binlogctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ const (
type Config struct {
*flag.FlagSet

Command string `toml:"cmd" json:"cmd"`
NodeID string `toml:"node-id" json:"node-id"`
DataDir string `toml:"data-dir" json:"data-dir"`
TimeZone string `toml:"time-zone" json:"time-zone"`
EtcdURLs string `toml:"pd-urls" json:"pd-urls"`
SSLCA string `toml:"ssl-ca" json:"ssl-ca"`
SSLCert string `toml:"ssl-cert" json:"ssl-cert"`
SSLKey string `toml:"ssl-key" json:"ssl-key"`
State string `toml:"state" json:"state"`
tls *tls.Config
printVersion bool
Command string `toml:"cmd" json:"cmd"`
NodeID string `toml:"node-id" json:"node-id"`
DataDir string `toml:"data-dir" json:"data-dir"`
TimeZone string `toml:"time-zone" json:"time-zone"`
EtcdURLs string `toml:"pd-urls" json:"pd-urls"`
SSLCA string `toml:"ssl-ca" json:"ssl-ca"`
SSLCert string `toml:"ssl-cert" json:"ssl-cert"`
SSLKey string `toml:"ssl-key" json:"ssl-key"`
State string `toml:"state" json:"state"`
ShowOfflineNodes bool `toml:"state" json:"show-offline-nodes"`
tls *tls.Config
printVersion bool
}

// NewConfig returns an instance of configuration
Expand All @@ -91,6 +92,7 @@ func NewConfig() *Config {
cfg.FlagSet.StringVar(&cfg.SSLKey, "ssl-key", "", "Path of file that contains X509 key in PEM format for connection with cluster components.")
cfg.FlagSet.StringVar(&cfg.TimeZone, "time-zone", "", "set time zone if you want save time info in savepoint file, for example `Asia/Shanghai` for CST time, `Local` for local time")
cfg.FlagSet.StringVar(&cfg.State, "state", "", "set node's state, can set to online, pausing, paused, closing or offline.")
cfg.FlagSet.BoolVar(&cfg.ShowOfflineNodes, "show-offline-nodes", false, "include offline nodes when querying pumps/drainers")
cfg.FlagSet.BoolVar(&cfg.printVersion, "V", false, "prints version and exit")

return cfg
Expand Down
5 changes: 4 additions & 1 deletion binlogctl/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
)

// QueryNodesByKind returns specified nodes, like pumps/drainers
func QueryNodesByKind(urls string, kind string) error {
func QueryNodesByKind(urls string, kind string, showOffline bool) error {
registry, err := createRegistryFuc(urls)
if err != nil {
return errors.Trace(err)
Expand All @@ -46,6 +46,9 @@ func QueryNodesByKind(urls string, kind string) error {
}

for _, n := range nodes {
if n.State == node.Offline && !showOffline {
continue
}
log.Info("query node", zap.String("type", kind), zap.Stringer("node", n))
}

Expand Down
2 changes: 1 addition & 1 deletion binlogctl/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *testNodesSuite) TestQueryNodesByKind(c *C) {
registerPumpForTest(c, "test", "127.0.0.1:8255")

// TODO: handle log information and add check
err := QueryNodesByKind("127.0.0.1:2379", "pumps")
err := QueryNodesByKind("127.0.0.1:2379", "pumps", false)
c.Assert(err, IsNil)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/binlogctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func main() {
case ctl.GenerateMeta:
err = ctl.GenerateMetaInfo(cfg)
case ctl.QueryPumps:
err = ctl.QueryNodesByKind(cfg.EtcdURLs, node.PumpNode)
err = ctl.QueryNodesByKind(cfg.EtcdURLs, node.PumpNode, cfg.ShowOfflineNodes)
case ctl.QueryDrainers:
err = ctl.QueryNodesByKind(cfg.EtcdURLs, node.DrainerNode)
err = ctl.QueryNodesByKind(cfg.EtcdURLs, node.DrainerNode, cfg.ShowOfflineNodes)
case ctl.UpdatePump:
err = ctl.UpdateNodeState(cfg.EtcdURLs, node.PumpNode, cfg.NodeID, cfg.State)
case ctl.UpdateDrainer:
Expand Down
2 changes: 1 addition & 1 deletion tests/_utils/check_status
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ max_commit_ts_new=0

for i in {1..15}
do
binlogctl -pd-urls 127.0.0.1:2379 -cmd $NODE_KIND > $STATUS_LOG 2>&1
binlogctl -pd-urls 127.0.0.1:2379 -cmd $NODE_KIND -show-offline-nodes > $STATUS_LOG 2>&1
cat $STATUS_LOG

if [ $NODE_KIND == "pumps" ]; then
Expand Down

0 comments on commit bece556

Please sign in to comment.