Skip to content

Commit

Permalink
planner, executor: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
caohe committed Feb 26, 2019
1 parent 4b300b1 commit 4b29ef9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
32 changes: 7 additions & 25 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (e *ShowExec) fetchAll() error {
case ast.ShowDatabases:
return e.fetchShowDatabases()
case ast.ShowDrainerStatus:
return e.fetchShowDrainerStatus()
return e.fetchShowPumpOrDrainerStatus(node.DrainerNode)
case ast.ShowEngines:
return e.fetchShowEngines()
case ast.ShowGrants:
Expand All @@ -132,7 +132,7 @@ func (e *ShowExec) fetchAll() error {
case ast.ShowProcedureStatus:
return e.fetchShowProcedureStatus()
case ast.ShowPumpStatus:
return e.fetchShowPumpStatus()
return e.fetchShowPumpOrDrainerStatus(node.PumpNode)
case ast.ShowStatus:
return e.fetchShowStatus()
case ast.ShowTables:
Expand Down Expand Up @@ -1006,39 +1006,21 @@ func (e *ShowExec) fetchShowWarnings(errOnly bool) error {
return nil
}

// fetchShowPumpStatus gets status of all pumps and fill them into e.rows.
func (e *ShowExec) fetchShowPumpStatus() error {
// fetchShowPumpOrDrainerStatus gets status of all pumps or drainers and fill them into e.rows.
func (e *ShowExec) fetchShowPumpOrDrainerStatus(kind string) error {
registry, err := createRegistry(config.GetGlobalConfig().Path)
if err != nil {
return errors.Trace(err)
}
defer registry.Close()

nodes, _, err := registry.Nodes(context.Background(), node.NodePrefix[node.PumpNode])
nodes, _, err := registry.Nodes(context.Background(), node.NodePrefix[kind])
if err != nil {
return errors.Trace(err)
}

for _, n := range nodes {
e.appendRow([]interface{}{n.NodeID, n.Addr, n.State, n.MaxCommitTS, utils.TSOToRoughTime(n.UpdateTS)})
}

return nil
}

// fetchShowDrainerStatus gets status of all drainers and fill them into e.rows.
func (e *ShowExec) fetchShowDrainerStatus() error {
registry, err := createRegistry(config.GetGlobalConfig().Path)
if err != nil {
return errors.Trace(err)
}

nodes, _, err := registry.Nodes(context.Background(), node.NodePrefix[node.DrainerNode])
if err != nil {
return errors.Trace(err)
}

for _, n := range nodes {
e.appendRow([]interface{}{n.NodeID, n.Addr, n.State, n.MaxCommitTS, utils.TSOToRoughTime(n.UpdateTS)})
e.appendRow([]interface{}{n.NodeID, n.Addr, n.State, n.MaxCommitTS, utils.TSOToRoughTime(n.UpdateTS).Format("2006-01-02 15:04:05")})
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ func buildShowSchema(s *ast.ShowStmt, isView bool) (schema *expression.Schema) {
names = []string{"Database", "Create Database"}
case ast.ShowDrainerStatus:
names = []string{"NodeID", "Address", "State", "Max_Commit_Ts", "Update_Time"}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeDatetime}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeVarchar}
case ast.ShowGrants:
if s.User != nil {
names = []string{fmt.Sprintf("Grants for %s", s.User)}
Expand All @@ -1783,7 +1783,7 @@ func buildShowSchema(s *ast.ShowStmt, isView bool) (schema *expression.Schema) {
mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeVarchar, mysql.TypeString}
case ast.ShowPumpStatus:
names = []string{"NodeID", "Address", "State", "Max_Commit_Ts", "Update_Time"}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeDatetime}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLonglong, mysql.TypeVarchar}
case ast.ShowStatsMeta:
names = []string{"Db_name", "Table_name", "Partition_name", "Update_time", "Modify_count", "Row_count"}
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeDatetime, mysql.TypeLonglong, mysql.TypeLonglong}
Expand Down

0 comments on commit 4b29ef9

Please sign in to comment.