Skip to content

Commit

Permalink
Merge pull request #8038 from planetscale/jg_super_onlineddl
Browse files Browse the repository at this point in the history
Handle online DDL user creation if we do not have SUPER privs (e.g. AWS Aurora)
  • Loading branch information
deepthi authored May 5, 2021
2 parents 9a06a61 + 0272d9b commit c098c15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ func (e *Executor) readMySQLVariables(ctx context.Context) (variables *mysqlVari
return variables, nil
}

// createOnlineDDLUser creates a gh-ost user account with all neccessary privileges and with a random password
// createOnlineDDLUser creates a gh-ost or pt-osc user account with all
// neccessary privileges and with a random password
func (e *Executor) createOnlineDDLUser(ctx context.Context) (password string, err error) {
conn, err := dbconnpool.NewDBConnection(ctx, e.env.Config().DB.DbaConnector())
if err != nil {
Expand All @@ -377,6 +378,12 @@ func (e *Executor) createOnlineDDLUser(ctx context.Context) (password string, er
return password, err
}
}
for _, query := range sqlGrantOnlineDDLSuper {
parsed := sqlparser.BuildParsedQuery(query, onlineDDLGrant)
conn.ExecuteFetch(parsed.Query, 0, false)
// We ignore failure, since we might not be able to grant
// SUPER privs (e.g. Aurora)
}
for _, query := range sqlGrantOnlineDDLUser {
parsed := sqlparser.BuildParsedQuery(query, onlineDDLGrant)
if _, err := conn.ExecuteFetch(parsed.Query, 0, false); err != nil {
Expand Down
5 changes: 4 additions & 1 deletion go/vt/vttablet/onlineddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,11 @@ var (
`CREATE USER IF NOT EXISTS %s IDENTIFIED BY '%s'`,
`ALTER USER %s IDENTIFIED BY '%s'`,
}
sqlGrantOnlineDDLSuper = []string{
`GRANT SUPER ON *.* TO %s`,
}
sqlGrantOnlineDDLUser = []string{
`GRANT SUPER, REPLICATION SLAVE ON *.* TO %s`,
`GRANT PROCESS, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO %s`,
`GRANT ALTER, CREATE, DELETE, DROP, INDEX, INSERT, LOCK TABLES, SELECT, TRIGGER, UPDATE ON *.* TO %s`,
}
sqlDropOnlineDDLUser = `DROP USER IF EXISTS %s`
Expand Down

0 comments on commit c098c15

Please sign in to comment.