Skip to content

Commit

Permalink
parser: add support for SHUTDOWN syntax (#580) (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored Dec 18, 2019
1 parent 701d0da commit 56b91da
Show file tree
Hide file tree
Showing 7 changed files with 6,465 additions and 6,393 deletions.
23 changes: 23 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
_ StmtNode = &KillStmt{}
_ StmtNode = &CreateBindingStmt{}
_ StmtNode = &DropBindingStmt{}
_ StmtNode = &ShutdownStmt{}

_ Node = &PrivElem{}
_ Node = &VariableAssignment{}
Expand Down Expand Up @@ -1991,6 +1992,28 @@ func (n *GrantRoleStmt) SecureText() string {
return text
}

// ShutdownStmt is a statement to stop the TiDB server.
// See https://dev.mysql.com/doc/refman/5.7/en/shutdown.html
type ShutdownStmt struct {
stmtNode
}

// Restore implements Node interface.
func (n *ShutdownStmt) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("SHUTDOWN")
return nil
}

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

// Ident is the table identifier composed of schema name and table name.
type Ident struct {
Schema model.CIStr
Expand Down
4 changes: 3 additions & 1 deletion ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (ts *testMiscSuite) TestMiscVisitorCover(c *C) {
&VariableAssignment{Value: valueExpr},
&KillStmt{},
&DropStatsStmt{Table: &TableName{}},
&ShutdownStmt{},
}

for _, v := range stmts {
Expand Down Expand Up @@ -130,7 +131,8 @@ 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';`
change drainer to node_state='paused' for node_id '127.0.0.1:8249';
shutdown;`

p := parser.New()
stmts, _, err := p.Parse(sql, "", "")
Expand Down
1 change: 1 addition & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ var tokenMap = map[string]int{
"SHARE": share,
"SHARED": shared,
"SHOW": show,
"SHUTDOWN": shutdown,
"SIGNED": signed,
"SIMPLE": simple,
"SLAVE": slave,
Expand Down
9 changes: 8 additions & 1 deletion mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ const (
AlterRoutinePriv
EventPriv

// ShutdownPriv the privilege to shutdown a server.
ShutdownPriv

// AllPriv is the privilege for all actions.
AllPriv
)
Expand Down Expand Up @@ -311,6 +314,7 @@ var Priv2UserCol = map[PrivilegeType]string{
CreateRoutinePriv: "Create_routine_priv",
AlterRoutinePriv: "Alter_routine_priv",
EventPriv: "Event_priv",
ShutdownPriv: "Shutdown_priv",
}

// Col2PrivType is the privilege tables column name to privilege type.
Expand Down Expand Up @@ -340,6 +344,7 @@ var Col2PrivType = map[string]PrivilegeType{
"Create_routine_priv": CreateRoutinePriv,
"Alter_routine_priv": AlterRoutinePriv,
"Event_priv": EventPriv,
"Shutdown_priv": ShutdownPriv,
}

// Command2Str is the command information to command name.
Expand Down Expand Up @@ -405,6 +410,7 @@ var Priv2Str = map[PrivilegeType]string{
CreateRoutinePriv: "CREATE ROUTINE",
AlterRoutinePriv: "ALTER ROUTINE",
EventPriv: "EVENT",
ShutdownPriv: "SHUTDOWN",
}

// Priv2SetStr is the map for privilege to string.
Expand All @@ -423,6 +429,7 @@ var Priv2SetStr = map[PrivilegeType]string{
ShowViewPriv: "Show View",
CreateRolePriv: "Create Role",
DropRolePriv: "Drop Role",
ShutdownPriv: "Shutdown Role",
}

// SetStr2Priv is the map for privilege set string to privilege type.
Expand All @@ -442,7 +449,7 @@ var SetStr2Priv = map[string]PrivilegeType{
}

// AllGlobalPrivs is all the privileges in global scope.
var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv, CreateTMPTablePriv, LockTablesPriv, CreateRoutinePriv, AlterRoutinePriv, EventPriv}
var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv, CreateTMPTablePriv, LockTablesPriv, CreateRoutinePriv, AlterRoutinePriv, EventPriv, ShutdownPriv}

// AllDBPrivs is all the privileges in database scope.
var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, AlterPriv, ExecutePriv, IndexPriv, CreateViewPriv, ShowViewPriv}
Expand Down
Loading

0 comments on commit 56b91da

Please sign in to comment.