Skip to content

Commit

Permalink
support show pump/drainer status && change pump/drainer's status (#259)
Browse files Browse the repository at this point in the history
* parser: add support for show pump/drainer status  (#217)

* Support update pump or drainer status (#243)
  • Loading branch information
WangXiangUSTC authored Mar 26, 2019
1 parent 6c89706 commit 750ee1d
Show file tree
Hide file tree
Showing 6 changed files with 5,851 additions and 5,692 deletions.
2 changes: 2 additions & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,8 @@ const (
ShowMasterStatus
ShowPrivileges
ShowErrors
ShowPumpStatus
ShowDrainerStatus
)

// ShowStmt is a statement to provide information about databases, tables, columns and so on.
Expand Down
25 changes: 25 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
// Valid formats for explain statement.
ExplainFormatROW = "row"
ExplainFormatDOT = "dot"
PumpType = "PUMP"
DrainerType = "DRAINER"
)

var (
Expand Down Expand Up @@ -469,6 +471,29 @@ func (n *SetPwdStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

type ChangeStmt struct {
stmtNode

NodeType string
State string
NodeID string
}

// SecureText implements SensitiveStatement interface.
func (n *ChangeStmt) SecureText() string {
return fmt.Sprintf("change %s to node_state='%s' for node_id '%s'", strings.ToLower(n.NodeType), n.State, n.NodeID)
}

// Accept implements Node Accept interface.
func (n *ChangeStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}
n = newNode.(*ChangeStmt)
return v.Leave(n)
}

// UserSpec is used for parsing create user statement.
type UserSpec struct {
User *auth.UserIdentity
Expand Down
14 changes: 14 additions & 0 deletions ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by
}
}

// test Change Pump or drainer status sql parser
func (ts *testMiscSuite) TestChangeStmt(c *C) {
sql := `change pump to node_state='paused' for node_id '127.0.0.1:8249';
change drainer to node_state='paused' for node_id '127.0.0.1:8249';`

p := parser.New()
stmts, _, err := p.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
stmt.Accept(visitor1{})
}
}

func (ts *testMiscSuite) TestSensitiveStatement(c *C) {
positive := []StmtNode{
&SetPwdStmt{},
Expand Down
4 changes: 4 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ var tokenMap = map[string]int{
"DIV": div,
"DO": do,
"DOUBLE": doubleType,
"DRAINER": drainer,
"DROP": drop,
"DUAL": dual,
"DUPLICATE": duplicate,
Expand Down Expand Up @@ -361,6 +362,8 @@ var tokenMap = map[string]int{
"NEXT_ROW_ID": next_row_id,
"NO": no,
"NO_WRITE_TO_BINLOG": noWriteToBinLog,
"NODE_ID": node_id,
"NODE_STATE": node_state,
"NONE": none,
"NOT": not,
"NOW": now,
Expand Down Expand Up @@ -390,6 +393,7 @@ var tokenMap = map[string]int{
"PROCESS": process,
"PROCESSLIST": processlist,
"PROFILES": profiles,
"PUMP": pump,
"QUARTER": quarter,
"QUERY": query,
"QUERIES": queries,
Expand Down
Loading

0 comments on commit 750ee1d

Please sign in to comment.