Skip to content

Commit

Permalink
add bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
imtbkcat committed May 9, 2020
1 parent d81fff8 commit 559b974
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ type MySQLPrivilege struct {
DefaultRoles []defaultRoleRecord
RoleGraph map[string]roleGraphEdgesTable
PwdErrorCnt map[string]int
BlackList map[string][]blackListItem
BlackList map[string][]blackListItem
}

// FindAllRole is used to find all roles grant to this user.
Expand Down Expand Up @@ -297,7 +297,7 @@ func (p *MySQLPrivilege) CheckAccountLock(user, host string, sctx sessionctx.Con
for _, r := range recs {
if r.Host == host {
t := r.startTime
if time.Now().Sub(t) > limit * time.Second {
if time.Now().Sub(t) > limit*time.Second {
ctx := context.Background()
sql := fmt.Sprintf("delete from mysql.login_blacklist where user = '%s' and host = '%s'", user, host)
_, err := sctx.(sqlexec.SQLExecutor).Execute(ctx, sql)
Expand Down
16 changes: 16 additions & 0 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ const (
version44 = 44
// version45 introduces CONFIG_PRIV for SET CONFIG statements.
version45 = 45
// version46 introduces mysql.login_blacklist to detect login fail.
version46 = 46
)

var (
Expand Down Expand Up @@ -439,6 +441,7 @@ var (
upgradeToVer43,
upgradeToVer44,
upgradeToVer45,
upgradeToVer46,
}
)

Expand Down Expand Up @@ -1052,6 +1055,19 @@ func upgradeToVer45(s Session, ver int64) {
mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Config_priv='Y' where Super_priv='Y'")
}

func upgradeToVer46(s Session, ver int64) {
if ver >= version46 {
return
}
mustExecute(s, CreateLoginBlackList)
sql := fmt.Sprintf("INSERT IGNORE INTO %s.%s (`VARIABLE_NAME`, `VARIABLE_VALUE`) VALUES ('%s', '%d')",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.MaxLoginAttempts, 10)
mustExecute(s, sql)
sql = fmt.Sprintf("INSERT IGNORE INTO %s.%s (`VARIABLE_NAME`, `VARIABLE_VALUE`) VALUES ('%s', '%d')",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.LoginBlockInterval, 3600)
mustExecute(s, sql)
}

// updateBootstrapVer updates bootstrap version variable in mysql.TiDB table.
func updateBootstrapVer(s Session) {
// Update bootstrap version.
Expand Down

0 comments on commit 559b974

Please sign in to comment.